The microcontroller can read the analog input voltage by sampling it and converting it to their digital values with the help of Analog to Digital Converter (ADC). The microcontroller can also generate an analog voltage on any external device with the help of Pulse Width Modulated (PWM) waves. Most of the microcontrollers have built-in PWM module and ADC modules which helps them in reading analog voltage inputs and generating analog voltage outputs on an external device.In an Arduino board some of the digital pins can be configured as analog output pins and there are also dedicated analog input pins which can be used for voltage sensing applications. In this project the Arduino pro-mini board is used which has a maximum of eight pins which can be used as analog input pins. The pins are marked in the board as A0, A1, A2, … A7. They are actually the input channels to the built-in ADC which can read the analog value and convert them to the digital equivalent.The Arduino pro-mini board has ATMEGA328 microcontroller inside it which has an internal EEPROM memory of 1Kb.
In this project the Arduino pro-mini board is programmed with the help of Arduino IDE version 1.0.3 on windows operating system. The image of the Arduino pro-mini board and the Arduino IDE is shown in the following;
Fig. 2: Typical Arduino Pro-Mini Board
Fig. 3: Arduino IDE Software Window
Another hardware which can perform the USB to TTL conversion is used to upload the program into the arduino board.
Fig. 4: External USB to TTL converter board for programming Arduino and serial communication
It is assumed that the reader has gone through the project how to get started with the arduino and done all the things discussed in it. In this particular project a simple potentiometer is used to provide variable voltage to the analog pin as a sensor does and which can be replaced with an actual sensor in future projects. The variable pin of a potentiometer is connected to the analog pin; in this project the pin A0. The other two pins of the potentiometer is connected to the VCC and GND so that as the variable moves it can divide the entire supply voltage and provide it as the analog input voltage for the Arduino board.
Once a value is read from the sensor it is immediately mapped and written to a pin configured as the analog output and where an LED is connected in the circuit. The brightness of the LED indicates the voltage output from the sensor. The value read is also converted to its voltage equivalent and displayed in an LCD and at the same time stored in an EEPROM. The functions analogRead(),analogWrite() and map() which can be used to read, write and map the values respectively and also the method to convert the value to the actual voltage are already explained in previous projects on how to use analog input and output of an Arduino board, how to display the sensor values using Arduino, and how to make dynamic sensor display using arduino.
The last read value, the present value and the other data are displayed on a 16*2 LCD using the functions provided by the library <LiquidCrystal.h>. Few functions from the library <LiquidCrystal.h> including those which are used in this particular project are already discussed in the previous projects onhow to interface an LCD, how to display sensor value on LCD, how to connect the LCD with the PC and how to make an LCD scrolling display.
The Arduino pro-mini has ATMEGA328 microcontroller which has 1Kb of EEPROM memory. The EEPROM memory is accessed in the code with the help of functions provided by the library <EEPROM.h>. The projects on how to access the EEPROM of the Arduino and how to perform the EEPROM test of the Arduino explains the method of reading and writing the EEPROM memory of the Arduino.
There are basically two functions namely EEPROM.write() and EEPROM.read() which helps in writing data to the EEPROM memory and reading data from the EEPROM memory respectively. The details of the functions are explained in the following section.
The function EEPROM.write() is used to write a data byte into a particular address of the EEPROM memory mentioned by the parameters passed to the function. The function has two parameters where the first one should be provided with the address of the EEPROM location into which the data need to be written into and the second parameter should be provided with actual data byte. For example if the data ‘A’ need to be written into the address mentioned by the variable ‘addr’ the following statement can be used.
The function EEPROM.read() is used to read a particular data byte from the internal EEPROM of the Arduino’s microcontroller. The function has a single parameter which is the address from which the data should be read from. The function has a return value which is the actual data byte which it read from the address mentioned by the parameter passed into it. For example if the data byte is to be read from the location mentioned by the variable ‘addr’ the following statement can be used.
The Arduino board reads the analog value at the analog input channel using the function analogRead() and then maps the value to the range 0 to 255 so that it can be written into the PWM module. The function map() is used to map the value from the range 0 to 1023 to the range 0 to 255. The mapped value is immediately written to the pin which is selected as the analog output pin using the function analogWrite() and hence varying the brightness of an LED indicator connected to that pin.
The mapped value is then converted to the actual voltage value which is then stored in the internal EEPROM with the help of functions from the library <EEPROM.h>. The function EEPROM.write() is used for writing the value into a particular memory location. The value is also displayed in a 16*2 LCD.
Whenever the Arduino is powered up the code first reads the previously stored value from the same memory location and displays it on a 16*2 LCD. The function from the library <EEPROM.h> namely EEPROM.read() is used to read the value from the memory location.
Both the previous value read from the location is and the current value reads from the analog pin are displayed in a 16*2 LCD with the help of functions from the library <LiquidCrystal.h>. Few functions from the library <LiquidCrystal.h> including those which are used in this particular project are already discussed in the previous projects on how to interface an LCD, how to display sensor value on LCD, how to connect the LCD with the PC and how to make an LCD scrolling display.
When 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. First time when the Arduino is powere up the last value displayed will be 0 and from the next time onwards it will display the last value sensed before the Arduino is powered off.