The arduino pro-mini board is used for a previous project on how to use the analog input and output of the arduino. The different values appear at the analog input and analog output of the arduino board will be monitored using the serial monitor tool in the arduino IDE version 1.0.3 for windows. The image of the arduino pro-mini board and the arduino IDE are shown below;
Another board which is used as a programmer and usb to serial converter should be used with the arduino pro-mini board since the arduino pro-mini board has no circuitary for interfacing it with the serial port or the USB port of the PC. The image of the FTDI USB to TTL converter board is shown in the following;
It is assumed that the reader has gone through the project Getting started with Arduino and tried out the project on how to use the analog input and output of the arduino. This project also make use of the serial port accessing functions explained in the projects on how to receive and send serial data using arduino and how to do serial communication using arduino.
This function is used in the code to initialize the serial port with the baud rate 9600 which is given as the argument of the function and also with 8 bits of data frame, one start bit, one stop bit and no parity bits using the statement given below;
The Serial.print() function is used in the code to send the value to the serial port that has to be monitored. This function formats the value to ASCII characters so that it can be displayed in the serial monitor window. For example if the variable ‘var’ has a value 10, then it can be displayed on the serial port as 10 using the following statement
In short the Serial.print() function actually ‘prints’ the value which is given as a parameter to it on the serial monitor.
The function Serial.println() is also used in the same manner but to introduce a new line and carriage return after printing the value in the serial monitor. The values printed after the Serial.println() function will appear on the next line in the window.
This function is used to enable the built-in ADC of the arduino’s microcontroller which then converts the analog value appears in a particular pin to its 10 bit digital equivalent and then stores in the variable.
var = analogRead(A0);
The above statement reads the value from the A0 and stores it in the variable ‘var’. The serial printing functions are then used to print the value of this variable in this particular project.
The map() is a built-in function which can be used to map the value from one rage to another range. For example the ADC of the arduino generates 10 bit values but the PWM module of the arduino can produce 8 bit equivalent waveforms. If there is a requirement to directly write the analog input value to the analog output one can make use of the map() function as follows;
var = map(potvalue, 0, 1023, 0, 255);
The above statement will convert the value which is in the range of 0 to 1023 (the output of 10 bit ADC) into the range 0 to 255 (the input range of 8 bit PWM) and stores it in a variable ‘var’. The variable ‘var’ could be of the type integer or character.
This project also monitors the mapped variable’s value before using that variable to generate the analog voltage in an analog output pin.
This function can write an analog value into an analog output pin mentioned in its argument to generate the equivalent voltage on that pin. For example one can make use of the analogWrite() function to generate a voltage equivalent of value 100 on an analog output pin 5 as shown below;
analogWrite (5, 100);
The above statement will actually write the value 100 to an 8 bit PWM module which will generate a corresponding width modulated waveform on the pin number 5 so as to generate the equivalent voltage on the device connected to that pin.
Once the coding is finished one can verify and upload the code to the arduino board as explained in the project how to get started with the arduino. The following section explains how to connect the arduino board with the serial monitor tool.
The serial monitor tool can be selected from the same IDE which has been used for verifying and uploading the code. For any other serial monitor tool the IDE should be closed before connecting the arduino board and hence it is always an advantage to be having the serial monitor tool in the IDE itself. If any error has been noticed one can quickly change the code, upload it and check it again which speeds up the code development process.
As shown in the above image the serial monitor can be selected from the tools->serial monitor and for this particular project the display on the serial monitor appears as shown in the following image.