Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. My Project
  3. Timer (Emergencie)

Timer (Emergencie)

Scheduled Pinned Locked Moved My Project
3 Posts 3 Posters 923 Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Bruno CunhaB Offline
    Bruno CunhaB Offline
    Bruno Cunha
    wrote on last edited by
    #1

    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);
    }
    "

    1 Reply Last reply
    0
    • gohanG Offline
      gohanG Offline
      gohan
      Mod
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • TmasterT Offline
        TmasterT Offline
        Tmaster
        wrote on last edited by Tmaster
        #3

        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

        i'm a arduino fan .Even sometimes don't undestanding how to use it :P

        1 Reply Last reply
        2
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        21

        Online

        11.7k

        Users

        11.2k

        Topics

        113.1k

        Posts


        Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • MySensors
        • OpenHardware.io
        • Categories
        • Recent
        • Tags
        • Popular