Im trying to make a device that will switch on a LED when I twist my hand, Im trying to simulate a smart watch feature wherein when I raised my hand and look to my smart watch the lcd screen will automatically light up, the only difference with my project is that when I twist my hand the device will turn on.
Currently, Im using an adxl345 but the problem is that when I twist my sensor facing down that y-value returns back to 0 which is the same value when I twist my sensor facing Upward, this means that when my sensor is facing Up the led is on then turns off when I twist my hand, then the LED is turned on again when the sensor is facing down. Is their any way wherein I can only turn on my led when the sensor is facing down.
This is the code Im currently using
#include <SparkFun_ADXL345.h> // SparkFun ADXL345 Library
ADXL345 adxl = ADXL345(10); // USE FOR SPI COMMUNICATION, ADXL345(CS_PIN);
void setup() {
pinMode(2,OUTPUT);
Serial.begin(9600); // Start the serial terminal
adxl.powerOn(); // Power on the ADXL345
adxl.setRangeSetting(2); // Give the range settings
// Accepted values are 2g, 4g, 8g or 16g
// Higher Values = Wider Measurement Range
// Lower Values = Greater Sensitivity
adxl.setSpiBit(0); // Configure the device to be in 4 wire SPI mode when set to '0' or 3 wire SPI mode when set to 1
// Default: Set to 1
// SPI pins on the ATMega328: 11, 12 and 13 as reference in SPI Library
}
void loop() {
// Accelerometer Readings
int x,y,z;
adxl.readAccel(&x, &y, &z); // Read the accelerometer values and store them in variables declared above x,y,z
// Output Results to Serial
Serial.println(y);
if(y > 0 && y < 60 ){
digitalWrite(2,1);
}else{
digitalWrite(2,0);
}
}