Relay off timer

hi I’m new to all of this, but I have a 4 relay particle board and I am using an electron to turn a relay on all it does it turn a 12v led light bar on, the reason I need a timer is the system runs off a solar panel and want a safety as in if I forget to turn the light off it will time out and turn off, thinking of an hour timer

but I still want the ability to turn it off manually before the timer is due,

can anyone help or point me in the right direction for a simple timer?

thanks Karl

You can use Software Timers or check the current time (or millis()) against the time when your action started and trigger the off action once the difference exceeds your timeout.

Here is some sample code that shows how a time variable can be set when you turn the light on, and how loop() can turn it off when current time reaches the set time.

time_t  lightOffTime = 0;
time_t  LIGHT_DELAY = 3600; // 60 seconds x 60 minutes

void setup() {


void loop() {
    if ((lightOffTime > 0) && ( >= lightOffTime)) {

void turnLightOn() {
    lightOffTime = + LIGHT_DELAY;
    // turn relay on

void turnLightOff() {
    lightOffTime = 0;
    // turn relay off

thanks for the reply sorry I have been away working and haven’t had a chance to reply, I will go through the the options but the timer looks like a good option bear, and scruffr

I will let you know how I get on

thanks again