Timer (Emergencie)

  • Hi, i have this project where i control the the time (0-20 s) that a relay is actuated, i have a button to turn the relay and i want another button to turn off the relay in any moment, like a emergencie button. I though about running a parallel program but i dont know if it possible, here is the code.

    int potPin = A0;
    int ledPin = 13;
    const int buttonPin = 2;

    void setup() {
    pinMode(ledPin, OUTPUT);

    pinMode(buttonPin, INPUT);


    void loop()
    int buttonState = digitalRead(buttonPin);

    int val = analogRead(potPin);
    long tempo = (val*19.550342131);

    // read the value from the sensor
    if (buttonState==HIGH) {

    digitalWrite(ledPin, HIGH);
    digitalWrite(ledPin, LOW);
    } else {}; // turn the ledPin off


  • Mod

    Use an if statement instead of delay and use millis to count time passed, when time is up turn off pin.

  • if it is an emergency button should be connected directly to relay (connected by hardware). And not using code,because if arduino it's freezed it will not respond and you cant stop it

Log in to reply

Looks like your connection to MySensors Forum was lost, please wait while we try to reconnect.