Pages: [1]   Go Down
Author Topic: accelerometer ADXL335  (Read 900 times)
0 Members and 1 Guest are viewing this topic.
India
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have interfaced an ADXL335 3-axis accelerometer with an atmega8 microcontroller.. what i would like to know is how can i use the analog output of the accelerometer to interrupt the microcontroller whenever the outputs deviate from their mean value? any kind of help will be greatly appreciated.... thanks smiley
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 220
Posts: 13846
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

(no electrical guru)

If you want an interrupt you must add some hardware as analog ports cannot generate an IRQ on some threshold value.

Do you have a real time constraint in your application?
Maybe it is a good Idea to post your code so we can have a look at it how it can be done.

Do you use delay() in your code? Code can be more reactive if it is written without delays'...

« Last Edit: February 24, 2012, 10:56:27 am by robtillaart » Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

India
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yea... there is a real time constraint.... basically we are building a window washer.... and using the accelerometer as an anemometer so that whenever the bot which is suspended from the top starts swaying, it needs to be interrupted...
Logged

India
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

here is the code for the accelerometer alone, i have been polling the status of the outputs of accelerometer to get the desired result...

int x, y, z;

void setup()
{
Serial.begin(9600);           // sets the serial port to 9600
}
void loop()
{
x = analogRead(0);       // read analog input pin 0
y = analogRead(1);       // read analog input pin 1
z = analogRead(2);       // read analog input pin 2
Serial.print("accelerations are x, y, z: ");
Serial.print(x, DEC);    // print the acceleration in the X axis
Serial.print(" ");       // prints a space between the numbers
Serial.print(y, DEC);    // print the acceleration in the Y axis
Serial.print(" ");       // prints a space between the numbers
Serial.println(z, DEC);  // print the acceleration in the Z axis
delay(1000);// wait 100ms for next reading
if (x<375||x>390 && y<375||y>390 && z<310||z>325)
{
  digitalWrite(13,HIGH);
}
else
{
  digitalWrite(13,LOW);
}



}
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 220
Posts: 13846
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

PLease use the # button to get code tags , makes at least the look better.

some observations:
- why not use higher baudrate 115200 is 12 times faster
- if code and comments differ the code wins ==> check the delay(1000) in your code

- you need to add extra ()'s in the boolean statement to enforce what you really want (I guess)
  see my change in the code below.
  => google for short circuit boolean evaluation why you should do that. (operator precedence is also a good reader)

Code:
int x, y, z;

void setup()
{
Serial.begin(115200);    <<<<<<<<<<<<<<<<<<<<
}
void loop()
{
x = analogRead(0);       // read analog input pin 0
y = analogRead(1);       // read analog input pin 1
z = analogRead(2);       // read analog input pin 2

Serial.print("accelerations are x, y, z: ");
Serial.print(x, DEC);    // print the acceleration in the X axis
Serial.print(" ");       // prints a space between the numbers
Serial.print(y, DEC);    // print the acceleration in the Y axis
Serial.print(" ");       // prints a space between the numbers
Serial.println(z, DEC);  // print the acceleration in the Z axis

delay(1000);// wait 100ms for next reading <<<<<<<<<<<<<<<<<<


if ((x<375||x>390) && (y<375||y>390) && (z<310||z>325))  <<<<<<<<<<<<<<<<
{
digitalWrite(13,HIGH);
}
else
{
digitalWrite(13,LOW);
}
}
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

India
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

well actually  the code was originally written by a friend... i just tweaked it a little and forgot to change the comments smiley-razz and as far as using the brackets... the code works perfectly fine without using them also
Logged

Pages: [1]   Go Up
Jump to: