Arduino + Accelerometer: Tilt Detection

Thanks for sharing.

Here are some tips that may help you if you add to this sketch

You can simplify the position checks, for example you can do the y position check as follows:

if (y < xy_max) { //backwards
digitalWrite(backPin, HIGH);
Serial.println("The arduino is moving(tilted) backwards");
}
else{
digitalWrite(backPin, LOW);
}

This works because if y is not less than xy_max it must be greater than or equal , so you don't need to do that check

If you just wanted to control the led without the serial message you can simplify further. The following code will set the pin HIGH when x is less than xy_max and low otherwise

digitalWrite(backPin, (x<xy_max) );

the expression (x<xy_max) evaluates to true (the same as HIGH) if x is less than xy_max and false (the same as LOW) otherwise.

Have fun!