Requirements
- AtMega 16 IC /development board
- 2. 3-axis accelerometer
- 3. 16X2 LCD screen (to display X, Y and Z data)
Description
This project uses three of the eight ADCs present in the AtMega16 IC to display the corresponding digital data from the X, Y and Z outputs of an accelerometer on a 16X2 LCD.
Accelerometer
First let's talk about the Accelerometer IC; here I used the ADXL-335, which is a 3-axis accelerometer module.
Figure 1: Image of the ADXL335 Accelerometer Module
It is very easy to deal with these types of modules, as they only need VCC and GND power to start, the rest is its job to provide us with analog data. These modules work with a simple concept such as the force acting on an object on an inclined plane. It deals with the Mg(sin?) and Mg(cos?) part of the force and determines the angle for further calculations. Now you also notice the change in force from which the acceleration will be calculated.Analog/Digital Converter
There are 8 independent ADCs that share their pins with those of PORTA. These ADCs are 10-bit, which simply means that they can convert a given analog value into its corresponding 10-bit digital data.
Before we proceed, we must first discuss what ADCs are. ADC stands for Analog to Digital Converter. We all know that microcontrollers work with digital values only, but what if we need to interact with analog devices or values. In these situations we need a device that can function as a communicator between the analogue part and the digital part. ADCs (analog to digital converter) play the same game; they convert the analog values to digital by some reference medium (Vref).
On the AtMega16, pin 32 requires a reference voltage (typically supplied +5V) when working with ADCs. There is also one more term that needs to be introduced i.e. Resolution. In simple terms, we can say that it is the precision or accuracy with which an ADC works. For a 10-bit ADC working with Vref of 5V, its resolution is 4.88mV. This further means that for every increase or decrease of 4.88mV in the analog input, the digital output will increase or decrease by one unit, respectively. Since it is a 10-bit ADC, the output data ranges from 0 to 1023 (2^10 = 1024) with 1024 different values. Now coming back to this project, I connected the X, Y and Z pins to ADC0-ADC2. They provide individual and independent analog values. I also displayed the corresponding digital result on the LCD. LCD connections are as follows: • DATA pins are connected to PB4-PB7 as it works in 4-bit mode • RS, RW and ES pins are connected to PB0, 1, 2 respectively. When watching the video portion, you will notice that the values of X, Y, and Z only range between 300-500. This is because my Vref is set to 5V while the accelerometer outputs remain between 1.6-1.9V. In the coding part I used three header files: •Project source code
###
#include
#include
#include
#include
main void
{
internal adc0;
ADCinit;
LCDinit ;
LCDclr ;
LCD Cursor OFF ;
Characters ch(16);
while (1)
{
adc0=ler_adc(0); //reading data from the X axis
sprintf(ch,"X: %d",adc0); // converting int to char
LCDGotoXY (0,0);
LCD screen (CH);
LCDsendChar (' ');
adc0=ler_adc(1); //reading data from the Y axis
sprintf(ch,"Y: %d",adc0);
LCDGotoXY (0.10);
LCD screen (CH);
LCDsendChar (' ');
adc0=ler_adc(2); //reading data from Z axis
sprintf(ch,"Z: %d",adc0);
LCDGotoXY (1.5);
LCD screen (CH);
LCDsendChar (' ');
_delay_ms (500); //a delay of half a second
}
}
###
Circuit diagrams
Circuit Diagram-ADXL335-Accelerometer-Module-Interface-AVR-ATMega16 |