Relay on with countdown. Non-blocking / no delay?

Hi there!

My programming skills are almost limited to just upload the file itself to the arduino, so I hope someone can help me on this easy project.

This is what I’m looking for:

  • By the press of a button, a relay turns on for 30 sec and then turns off
  • If the button is pressed again before the 30 sec is finished, then it starts the count down again (from 30 down to 0)

That’s all the function it needs. However, this will not work with the delay function, so from my two-three hours of googling I found out that a non-blocking or no delay function is needed.

if anyone got some minutes to help me, then I would be super super happy :slight_smile:

Thanks : ))

This might help.

You can do what you ask with a single TTL chip.
Take a look at the 74xx122 & xx123 or similar...
Retriggerable one-shot ICs
Or a 555 timer chip can do the same.

Less parts, more reliability, less power, smaller... the list goes on!

The demo Several Things at a Time illustrates the use of millis() to manage timing without blocking. It may help with understanding the technique.

Have a look at Using millis() for timing. A beginners guide if you need more explanation.