Go Down

Topic: Adding a Action on a button press. (Read 118 times) previous topic - next topic


Mar 25, 2019, 12:25 pm Last Edit: Mar 25, 2019, 12:29 pm by antony1876
I am a returning Novice after 18 years. Now aged 70.. Don't hold that against me.
I have modified someone else's code that came from  Link to original
 Now for the code that I have got so far.. Please see Attachment.
What I would like to do is:-
Press a button and the Lights switch off (IF they are on) and Pump switches On for 1 minute.
Then both Lights and Pump return to their original State.
I have been trying a few methods But with no success so far.

Pointers in the right direction would be well appreciated and welcome.

Regards Antony.


I have been trying a few methods But with no success so far.
You've done something, with some results. You've shared neither. If you want help, you need to be specific as to what the problem is.


Hi Paul.
Yes you are correct.. But I deleted it as it was not working as it should.

I've put it back in and it works BUT I don't know where to or How to do the check code to return the states of the Pump and Light.

Code: [Select]
void loop()
  //    Checks if button on pin 2 is pressed If so Pump starts and Lights go Off until released
  //    Pump_Hold  Light_Hold
  Pump_Hold  = Water_spray_Pump;
  Light_Hold = light;
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH) {
    Serial.println("  Extra spray is ON and Light is OFF ");
    digitalWrite(light, LOW);             // turns light OFF
    digitalWrite(Water_spray_Pump, HIGH);  // Turns Pump ON

  } else {

    Serial.println("  Extra spray is OFF and Light is ON ");
    digitalWrite(light, HIGH);             // turns light ON
    digitalWrite(Water_spray_Pump, LOW);  // Turns Pump OFF

  //Water_spray_Pump  Check

I've used Pump_hold and Light_hold to store the Condition of the Pump and Light.
From here I don't know.. Still exploring this as you read this.

Regards Antony.

Go Up