This Code is only visible to Registered users. Please Login/Register
Developed By:
The EEPROM stands for Electrically Erasable Programmable Read Only Memory. In an EEPROM the data can be written with the help of electrically programming the chip. EEPROM memory is widely used in microcontroller systems where some particular data need to be retained each time the system is turned on and to save particular data before the system is powered off.
The EEPROM memory chips can be interfaced in a microcontroller chip usually with the help of serial communication protocols. In case of small applications where only a few bytes needs to be stored the extra EEPROM chips are not preferred since it add extra complexity in the hardware, coding and increase the cost of the system. Hence most of the microcontrollers are provided with small sized built-in EEPROM chip which can be used to store data in small applications.The Arduino board has an AVR microcontroller in it which also has a built-in EEPROM memory. The memory size varies with the Arduino boards and the microcontroller used in them.
A microcontroller might need to store its data like sensor value, or a particular count or image data for a long period of time uses the EEPROM memory. The EEPROM memory is also used to save the data before the system switches itself off so that the same data can be retained next time when the system is turned on. This particular project demonstrates how to save the last read value from a senor into the built-in EEPROM of Arduino before it is powered off, so that the next time it is powered on the same data can be read.Clik here to view.

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;
Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.
Another hardware which can perform the USB to TTL conversion is used to upload the program into the arduino board.
Image may be NSFW.
Clik here to view.
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.
EEPROM.write()
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.
EEPROM.write(addr, ‘A’);
EEPROM.read()
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.
EEPROM.read(addr);
THE CODE
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.
Image may be NSFW. Clik here to view. ![]()
| LCD
LCD (Liquid Crystal Display) screen is an electronic display module and find a wide range of applications. A 16x2 LCD display is very basic module and is very commonly used in various devices and circuits. These modules are... |
Image may be NSFW. Clik here to view. ![]()
| Arduino Pro Mini The Arduino Pro Mini is an ATmega168 based microcontroller board. The board comes with built-in arduino bootloader. It has 14 digital input/output pins (of which 6 can be used as PWM... |
Image may be NSFW. Clik here to view. ![]()
| LED Light emitting diodes... |
Image may be NSFW. Clik here to view. ![]()
| Resistor Resistor is a passive component used to control current in a circuit. Its resistance is given by the ratio of voltage applied across its terminals to the current passing through it. Thus a particular value of resistor, for fixed voltage, limits the current through it. They are omnipresent in... |