Professional Documents
Culture Documents
What is an accelerometer?
An accelerometer is an electromechanical device that will measure acceleration forces. These
forces may be static, like the constant force of gravity pulling at your feet, or they could be
dynamic - caused by moving or vibrating the accelerometer.
It gives six different values in the corresponding tilts like x+, x-, y+, y-, z+, z-;
If you tilt the accelerometer in x+ then its value will increase upto 1.9v, if you tilt the
accelerometer in x- then its value decreases upto 1.2v. Similarly y-axis and z-axis value also
varies from 1.2v to 1.9v.
Connection details:-
1. Connect 5v supply to the vcc of accelerometer
2. Connect ground to gnd of the accelerometer
3. Connect pin X of the accelerometer to ADC0
4. Connect pin Y to ADC1.
5. Do not connect the ST pin with anyone.
With moving accelerometer in x and y direction, the output of PORTC varies.Program for the
same has been mentioned below.
#include <avr/io.h>
#include <util/delay.h>
unsigned char a,b,c;
void adc_init()
{
ADCSRA=0xE5;
}
void adc_getvalue()
{
ADMUX=0x60;
_delay_ms(1);
a=ADCH;
ADMUX=0x61;
_delay_ms(1);
b=ADCH;
}
void main()
{
DDRC=0XFF;
DDRA=0x00;
adc_init();
while(1)
{
adc_getvalue();
if(a>100)
PORTC=0b00001010;
else if(a<80)
PORTC=0b00000101;
else if(b>100)
PORTC=0b00001001;
else if(b<80)
PORTC=0b00000110;
else
PORTC=0b11111111;
}
}