i am working on a project where i have an adxl 377 accelerometer hooked up to the arduino and i want to use the analog output from the accelerometer to turn on the led. i want a threshold 70g but to start off i just need to know how i should go about writing the code to turn the led on. i tried to write the code but its not working. any help would be appreciated. I have included the code below
// these constants describe the pins. They won't change:
const int xpin = A3; // x-axis of the accelerometer
const int ypin = A2; // y-axis
const int zpin = A1; // z-axis (only on 3-axis models)
int led = 13;
void setup()
{
// initialize the serial communications:
Serial.begin(9600);
pinMode(led, OUTPUT);
}
void loop()
{
int X = analogRead(xpin);
int Y = analogRead(ypin);
int Z = analogRead(zpin);
float Volt_X = X * 0.003222656;
float Volt_Y = Y * 0.003222656;
float Volt_Z = Z * 0.003222656;
float Cal_X = (Volt_X - 1.65)*1000.0;
float Cal_Y = (Volt_Y - 1.65)*1000.0;
float Cal_Z = (Volt_Z - 1.65)*1000.0;
float G_X = (Cal_X/6.5)-1.49;
float G_Y = (Cal_Y/6.5);
float G_Z = (Cal_Z/6.5);
// float Total_Gs = sqrt(sqrt(G_X)+ sqrt(G_Y) + sqrt(G_Z));
Serial.print("X_Value");
Serial.print(G_X);
Serial.print("\t");
Serial.print("Y_Value");
Serial.print(G_Y);
Serial.print("\t");
Serial.print("Z_Value");
Serial.print(G_Z);
Serial.print("\t");
if (G_X == 70)
{
digitalWrite(led,HIGH);
delay(1000);
}
Serial.println ();
delay(100);
}