Accelerometer Values

Hi,

I’m attempting to use an accelerometer for the first time (an AM3X - you probably wont have heard of it unless your from New Zealand) but am having some issues trying to use the values it outputs in Arduino. For example I amp trying to run an if statement that prints less if the yAxis is “less” the 980 and “more” if it more. The problem is it only prints “less” no matter what value the yAxis returns… Does any body have any ideas on what the problem is here?

Here is my code:

int xAxis = A0;
int yAxis = A1;
int zAxis = A2;
int axisValue = 0;

#include <Servo.h>

Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;

void setup() {
Serial.begin(38400);
Serial.println(“Starting up”);

myservo.attach(9); // attaches the servo on pin 9 to the servo object

}

void loop() {

axisValue = analogRead(xAxis);
Serial.print(“X=”);
Serial.print(axisValue);

axisValue = analogRead(yAxis);
Serial.print(",Y=");
Serial.print(axisValue);

axisValue = analogRead(zAxis);
Serial.print(",Z=");
Serial.println(axisValue);

delay(200);

if ( yAxis < 980) {

Serial.println(“less”);

} else if (yAxis == 980) {

Serial.println(“equal”);

} else {

Serial.println(“more”);

}

}

,
Cheers

Adam.

Hi.

axisValue = analogRead(xAxis);
 Serial.print("X=");
 Serial.print(axisValue);
 axisValue = analogRead(yAxis);
 Serial.print(",Y=");
 Serial.print(axisValue);
[color=#222222][/color]
 axisValue = analogRead(zAxis);
 Serial.print(",Z=");
 Serial.println(axisValue);

You keep using axisValue as your input value, change it yo xaxisValue, yaxisValue, zaxisValue.

 if ( yAxis < 980) {
Serial.println("less");
 } else if (yAxis == 980) {
 Serial.println("equal");
 } else {
 Serial.println("more");

Here you are testing yAxis which is a pin allocation.
Test yaxisValue.

Please use code tags… See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

Hope this helps.
By the way I can buy the AX3 here in my city too.

http://http://www.wiltronics.com.au/catalogue/200441/arduino/arduino-compatibles-by-freetronics/freetronics-development-boards-shields-and-sensors/arduino-compatible-sensors-by-freeetronics/accelerometer-am3x-sensor-by-freetronics

Tom… :slight_smile:

Dude, you are awesome - that is the solution I was looking for. I'll post the code correctly next time as well - sorry this is my first time posting on these forums - or any coding forums for that matter.

Cheers,

Adam.

Use map() function to calibrate your values first, and then you will able to determine your min and max limits
I did that for my sensor , it is work 100% now.