Can anyone give me the full code of my project because my code is not working?
My aim is that when the Z axis of an accelerometer is below 370 and a pushbutton connected to a pin 2 becomes high, then pin 13 turns high and remains high. When the Z axis is above 370 and pushbutton is high then the pin 13 goes low and remains low.
P.S I am also a noob to Arduino
Here is my code :
const int ledPin = 13;
const int threshold = 370;
const int pull_up_resistor = 12;
const int pull_down_resistor = 11;
const int groundpin = A1;
const int powerpin = A5;
const int xpin = A2;
const int ypin = A3;
const int zpin = A4;
int pushButton = 2;
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
Serial.begin(9600);
pinMode(pushButton, INPUT);
digitalWrite(pushButton, HIGH);
Serial.begin(9600);
pinMode(groundpin, OUTPUT);
pinMode(powerpin, OUTPUT);
digitalWrite(groundpin, LOW);
digitalWrite(powerpin, HIGH);
}
void loop() {
int buttonState = digitalRead(pushButton);
Serial.println(buttonState);
delay(100); // delay in between reads for stability
Serial.print(analogRead(xpin));
Serial.print("\t");
delay(100);
Serial.print(analogRead(ypin));
Serial.print("\t");
delay(100);
Serial.print(analogRead(zpin));
Serial.println();
delay(100);
if (buttonState = 0) {
digitalWrite( ledPin, HIGH);
}
if (buttonState = 1) {
digitalWrite (pushButton, LOW);
}
}
if (buttonState = 1)
. You need a double equals.