Please help

I am using 2 pushbuttons, an analog Sensor and a motor.

Conditions:
When pushbutton 1 is pressed if sensor value >500 the motor has to be turned on. If the pushbutton is pressed second time the motor has to go off.

When pushbutton 2 is pressed if sensor value <500 the motor has to be turned on. If the pushbutton is pressed second time the motor has to go off.

Help me to run this. Motor starts itself with my code

int buttonPin = 7;
int waterPump=12;
int enable = 11;

int pumpState = HIGH;
int buttonState;
int lastButtonState = LOW;

unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50;

void setup() {
Serial.begin(9600);
pinMode(buttonPin, INPUT);
pinMode(enable, OUTPUT);
pinMode(waterPump, OUTPUT);

digitalWrite(waterPump, pumpState);

}

void loop() {
int reading = digitalRead(buttonPin);
int SensorValue=analogRead(A0);
Serial.println(SensorValue);
delay(1000);

if (reading != lastButtonState) {

lastDebounceTime = millis();
}

if ((millis() - lastDebounceTime) > debounceDelay) {

if (reading != buttonState) {
buttonState = reading;

if (buttonState == HIGH) {
pumpState = !pumpState;
}
}
}
{
digitalWrite(enable, HIGH);
digitalWrite(waterPump, pumpState);
lastButtonState = reading;
}}

Check your placement of the { and }.

Use CTRL T to format your sketch.

Please use code tags. Use the </> icon in the posting menu. [code] Paste sketch here. [/code]

.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.. :slight_smile: