Countdown timer sketch

Can anyone help me with my project. I am building a countdown timer using push button and RTC
. When I push the button it will trigger the relay on, then stop after 6hours

@kingjohn, you just hijacked someone elses thread. That is not allowed. Please start your own separate thread. I strongly suggest you read the forum guidelines.

Split from an unconnected topic

What have you tried so far? Do you have any hardware? Have you written any code? Please provide details.

What do you mean by "help"? We will help with code you have written. We will not write code for you.

@kingjohn13

What you got so far code ? breadboard circuit ? RTC module ?

Well it look simple ... Need .. push button switch, led ( that will be the relay ) resistor 1 K , 330. A RTC ( any type ) <-- an RTC is optional. Need precise to the second , yes an RTC will be use. if not, a count cycle will work.

psudo code
start : begin
Check button if press 
No - go begin
Yes - go countdown
countdowm :
turn on led - relay
count up to 216000 for 1 second
turn off led ( relay )
go begin 

To calculate the final number ( the silly number ) 6 hr -> 360 min -> 216000 sec.

That work if the code just wait for 6 hours doing nothing.
By thinking about it, the code is simple.

byte button_pin = 2; 
byte relay_pin = 3;
boolean button_state;
unsigned long time_waiting = 216000;

void setup ()
{
   pinMode(button_pin, OUTPUT);
   pinMode(relay_pin, OUTPUT);
}

void loop()
{
    button_state = digitalRead(button_pin);
    if (button_state == false)
// entering a VERY LONG LOOP
   {
       digitalWrite(relay_pin, HIGH);
       for (unsigned long x=0; x<time_waiting;x++)
       {
           delay(1000);
       }
       digitalWrite(relay_pin, LOW);
   }
}
   

No RTC is needed. BUT if you want the Arduino do something during the 6 hours waiting, well you did not mention that extra detail.

It would be useful to know WHY you want to do this;

and how you expect the timer to cope with other conditions;
eg if the button is pressed again during the 6 hours of inactivity.

and if you will somehow signal the device is active, or the countdown cycle is progressing.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.