February 27, 2012

Reading Accelerometer Data with Microcontroller

Reading Accelerometer with microcontroller can bring your project to life after reading this post you will be able to interface your accelerometer easily with microcontrollers.

After reading a bit about accelerometer  and accelerometer pins you are good to go with accelerometer interfacing with your microcontroller I have interfaced accelerometer with my Atmega 8535 microcontroller (it is easy to use because its having built in ADC).
According to me the easiest way to know any sensor is transmit its data to hyper terminal via COM port and then analyze data in real-time. So as soon as I got accelerometer I wrote a piece of code to transmit the data serially and started analyzing them on my PC.

Here is the code which I wrote in AVR-BASCOM
$regfile = "m8535.dat"                                      ' specify the used micro
$crystal = 16000000                                         ' used crystal frequency
$baud = 9600                                                ' use baud rate

Dim X As Integer , Y As Integer , Z As Integer
Dim Channel As Word

Config Adc = Single, Prescaler = Auto

Ddra.0 = 1
Porta.0 = 1                                                 'pin 1 in output mode high(vcc)
Ddra.1 = 1                                                  'pin 2 in op mode low(gnd)
Porta.1 = 0
Ddra.2 = 0
Porta.2 = 1                                                 'x axis adc ip mode
Ddra.3 = 0
Porta.3 = 1                                                 'y axis adc ip mode
Ddra.4 = 0
Porta.4 = 1                                                 'z axis in ip mode
Ddra.5 = 1
Porta.5 = 0                                                 'g select pin op high
Ddra.6 = 1                                                  'self test pin op low
Porta.6 = 0

X = Getadc(3)                                  'read x axis
Y = Getadc(4)                                   'read y axis
Z = Getadc(5)                                   'read z axis
Waitms 100
Print " X " ; Getadc(3) ; " Y " ; Getadc(4) ; " Z " ; Getadc(5) ;  'display on COM port
 And finally what i got is this 
accelerometer interfacing with microcontroller
Accelerometer interfacing with microcontroller
and then you are ready to see instant data on your hyper terminal.
So you can analyze your movement or just create a look-up table for further references. 

or manually decide what values you want to use for application.

                  Guys keep waiting for further posts  what are about how to utilize this accelerometer data to control any game like NFS Most wanted or Counter strike with just a tilt of hand or to make your own WII like gaming console.


Post a Comment

Related Posts Plugin for WordPress, Blogger...