Arduino Turn OFF the relay with delay

preview_player
Показать описание
turning off the relay after a delay
Рекомендации по теме
Комментарии
Автор

Thank you for this great video!
What will happen if you push the button before the delay runs out?
How can we turn off the fan during the delay time??

oqbamohammad
Автор

its very simple code:
if(button == HIGH){
ddigitalWrite(engine, HIGH);
delay(5000);
digitalWrite(engine, LOW)
and don't forget DIODE in circuit or othervise u will destroy arduino

strssko
Автор

Whats the maximum delay I can put in? For example..I want to use a switch to turn a relay on...if the switch is forgotten and left on, I want the relay to turn off after a few hours of it being on. Do I need an external clock for this or will the Arduino do it provided it is on and programmed for the time?

Consequently, when the switch it turned off, it resets the timer until the switch it turned on again to perform a function... Much like how newer cars will automatically turn off the interior light after X amount of time if you accidentally leave it on.

aquatone
Автор

Can you send us the code please. that would be very helpful.

kentmurillo
Автор

int pinButton = 8;
int Relay = 5;
int stateRelay = LOW;
int stateButton;
int previous = LOW;
long time = 0;
long debounce = 500;
int stayON = 5000; //stay on for 5000 ms

void setup() {
pinMode(pinButton, INPUT);
pinMode(Relay, OUTPUT);
}

void loop() {
stateButton = digitalRead(pinButton);
if(stateButton == HIGH && previous == LOW && millis() - time > debounce) {
if(stateRelay == HIGH){
digitalWrite(Relay, LOW);
} else {
digitalWrite(Relay, HIGH);
delay(stayON);
digitalWrite(Relay, LOW);
}
time = millis();
}
previous == stateButton;
}

jona