Countdown timer

Hi there. I need to build a timer that counts to 55 minutes, then turns a switch on for 5 minutes and then repeats the cycle until reset. I believe it is more of a microcontroller than a timer, but let's just call it timer. I have an Arduino UNO and a MEGA 2560 and I am not very good at it; I am a newbie and all help I can get will be greatly appreciated. Thank you.

Have you Googled? Arduino countdown timer

“until reset” What does this mean?

Why are you wanting to do this?

larryd: Have you Googled? Arduino countdown timer

“until reset” What does this mean?

Why are you wanting to do this?

Probably my message is confusing, and it is... I need a timer: which is off 55 minutes, then turns on a relay or whatever for 5 minutes, then repeats the cycle; I do not need the time displayed. I googled and I found nothing close. Thanks

“I am a newbie”, but what software/hardware experience do you have?

Why are you wanting to do this?

Do you know what the BWD (blink without delay) technique is all about?

Show us what you have done so far.

Actualy, the task is simply. You can do it easy. Loot @ Countimer library, it's great!

larryd: Do you know what the BWD (blink without delay) technique is all about?

If your code doesn't need to do anything other than control the 55/5 minute timing, you don't even need blink without delay, using delay() is fine under those conditions. It's a forum knee jerk to say that whenever timing is involved that it must be delay()-less. (That said, if your code does need to do more than just the described timing, blink without delay will very likely be a requirement.)

If the code doesn't need to do anything else, it's a simple matter of using blink with two different delay() values.

You will need to consider what means on and what means off though. You talk of a "relay or whatever": many relay modules are so-called "active low" which means a low is on and a high is off.

How exactly 55 minutes and 5 minutes? Arduinos that have resonator clocks (most) can drift > 3 minutes a day. If real time is required you should get a Real Time Clock Module (about $2 or less) as your time source.

We were all beginners once. It takes practice at your own level to let you reach the next one.

Countimer on GitHub

this may be what Adam DerBent was referring to.

but the idea is simple.

Going for Smoke adds a very valid point.

when you use a stopwatch there is an extra time needed to re-set the watch. over many-many iterations this can add up.

the simple BlinkWithoutDelay concept is rather easy and has many variants. here is one of the many variants.

this is NOT workable, but shows the basic concept. you have to work out your timing of seconds and minutes for simplicity, I show 55 and 60, but that is milliseconds, not minutes.

timing = (millis() - then) ;

if (timing >= 55 ) {    // this is just to show the concept,  55 here is 55 milliseconds 
action = LOW ;
}

if (timing >=60){
action = HIGH ;
then = millis() ;  // resets the counter
}

digitalWrite(motor, action)

dave-in-nj:
Going for Smoke adds a very valid point.

when you use a stopwatch there is an extra time needed to re-set the watch. over many-many iterations this can add up.

Oh no, we can keep from that. Add interval to start time, not millis() and you never gain a step.

The resonator is just inaccurate and does vary with temperature. A crystal is far more accurate. An RTC will have circuits with temperature effects that cancel each other and a battery of its own all for like $2.

Build a free-running one-second millis() timer. When this timer reaches preset, increment a counter and reset the timer.

As long as the counter is <= 54 the output is off. When counter goes over 54, output turns on. When counter > 59 reset counter.

moShellShocker: If your code doesn't need to do anything other than control the 55/5 minute timing, you don't even need blink without delay, using delay() is fine under those conditions. It's a forum knee jerk to say that whenever timing is involved that it must be delay()-less. (That said, if your code does need to do more than just the described timing, blink without delay will very likely be a requirement.)

If the code doesn't need to do anything else, it's a simple matter of using blink with two different delay() values.

You will need to consider what means on and what means off though. You talk of a "relay or whatever": many relay modules are so-called "active low" which means a low is on and a high is off.

Thanks @moShellShocker, this should work; I need to turn a small (computer) fan on and off and I will use a Reed relay for that.

“It's a forum knee jerk to say that whenever timing is involved that it must be delay()-less. (That said, if your code does need to do more than just the described timing, blink without delay will very likely be a requirement.)”

“I am a newbie” means nothing other than they are new to the forum.

The OP gave no information on their skill set with writing code or assembling hardware.

Unfortunately, we often have to drag information out of questioners as they do not read or follow even the basics of forum rules.

No knee jerk here on the forum at all.

As for delay(), it can be used to write timing code, but hopefully we can present techniques to new people that they will use over and over to make them better programmers.

As for delay(), it can be used to write timing code, but hopefully we can present techniques to new people that they will use over and over to make them better programmers.

Agreed++! I believe we should see more of the advanced features like direct port manipulation and hardware timer operation so beginners won’t always be beginners and more easily move on to advanced timing and higher speed.
Yet another variant, runs on Arduino Nano:

unsigned long timeKeeper,
              offTime = 1000UL * 60 * 55, // 55 minutes
              onTime = 1000UL * 60 * 5; // 5 minutes
void setup()
{
  bitSet(DDRB,5); // set pin 13 as OUTPUT
}
void loop() {
  if(millis() - timeKeeper >= (onTime + offTime))
  {
    timeKeeper += (onTime + offTime); // reset timeKeeper to current millis()
  }
    //switch pin 13
  bitWrite(PORTB,5,millis() - timeKeeper > offTime);
}

Now you are just being mean to the noob. ;)

larryd: Now you are just being mean to the noob. ;)

Nah, just trying to help him / her become an ex noob. :)

Let’s be fair now, you should include a comment which Arduino board the code must be used with.

Maybe tell them why too.

Naughty and nice code though.

Let's be fair now, you should include a comment which Arduino board the code must be used with.

Fair enough, code runs on Nano and probably UNO, Mini and other AtMega 328 based Arduinos, DDRB is the data direction register (INPUT or OUTPUT) for PORTB (pins 8 thru 13 on UNO), PORTB, bit 5 is pin 13 on UNO, setting it HIGH / LOW (1 or 0) turns the built in LED ON / OFF. Is that acceptable? :)

At least you didn't warn him to make sure he got the polarity of the resistor right

Hmmm, think I should? Which of those color bands is +?

Delay(1000); CounCount++;

If ( count>=3000) Action= high

If (count>= 3600) Action=low

Would allow a few things to occur Over the course of an hour.

I cant find brackets on my phone