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() {
    Serial.begin(9600);
    pinMode(ledPin, OUTPUT);

    pinMode(buttonPin, INPUT);

    }

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

    int val = analogRead(potPin);
    long tempo = (val*19.550342131);
    Serial.print(val);
    Serial.print("tempo:");

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

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

    delay(500);
    }
    "


  • 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
 

Suggested Topics

55
Online

11.4k
Users

11.1k
Topics

112.7k
Posts