Multiple timers with Reset Button for each Timer ?

I need some help before I start.

I added a scheme to indicate what I want to do.
In my drawing I added 3x LED, and 3x switch, but the main goal is to have 7x.
To make it easy i start with only 3.

I want to have 3 lights that start with Green, after 4 days they turn Yellow, and after 7 days they turn RED.

But each time you press the RESET button, the timer will start from 0 again.

I could do this with 1 LED.

Timer 01
Start:
IF: Button pressed return to START.
else:
Turn on Green
Wait 4 days..
Then Turn on Yellow.
Wait 3 days Turn on RED..

This is how I imagine it would look like (with some more detailed code) .
But how do I do this when adding more Timer ?

Do I need to use a Clock timer module ?

Maybe something like this:

Timer 01 , start from 0, when button 01 pressed return to 0.
Timer 01 , start from 0, when button 02 pressed return to 0.

and then,
when timer 01 is 3 days turn on Yellow
when timer 02 is 3 days turn on yellow

When timer 01 is 7 days turn on RED
when timer 02 is 7 days turn on RED.

I`m very new to this.
But this is how I see it in my head how it should work.
I only need to figure out the coding after I figure out the correct way to do this.

I appriciate all help and ideas :slight_smile:

But each time you press the RESET button, the timer will start from 0 again.

So that means a state machine. There are lots of tutorials on this as we get asked all the time about this.

My take on this is here http://www.thebox.myzen.co.uk/Tutorial/State_Machine.html

Or this at the start of the project Guidance section
https://forum.arduino.cc/index.php?topic=223286.0

The blink without delay example in the IDE also uses the same effect.

For this I would use real time clock board, but you can do it without using the millis timer. You don’t start and stop it, it runs and you take note of the time now and when you started the current time period. When the required time has elapsed you do the action and set the next topics. In the same loop you also check your reset button.

Grumpy_Mike:
So that means a state machine. There are lots of tutorials on this as we get asked all the time about this.

My take on this is here http://www.thebox.myzen.co.uk/Tutorial/State_Machine.html

Thank you.
I did try to search for different help on youtube and google.
But I searched for timers, and not State Machine (as that is a new name for me)

But thank you for pointing me into the correct direction :slight_smile:

I think that first link maybe can help me in my project.

Your switches are wired WRONG.

Don’t use I/O pin D01.



FYI

Larry is right.
These four pin switches have each pair of pins connected together. I is easy to get them rotated by 90 dedrees and so the switch seems always to be pushed. the simple way round this is to always use the two pins diagonally opposite each other. The any rotation of the switch will not matter.

Not to mention that wiring three switches in parallel with one pull-down resistor is not - believe me - going to work in any meaningful fashion! :astonished:

Ok, thank you for the input.
I maybe need to redesign my wiring :o

But so far I cant figure out how to make this work.
So I considering just to use 1 arduino mini\nano for each LED.
The cost for a nano is so small that it does not matter.

I can then run a simple code that tell the LED to count millis to XX and then turn RED, and when I push button I restart the counting from start again.

I`m not sure if I got enought output for 7x Red\Green LEDs + 7x switch on the arduino anyway.

So I considering just to use 1 arduino mini\nano for each LED.

Now don’t be silly.

Have you red the links in reply #1?

Some question for confirmation or correction

So one button will reset one Timer of a group of LEDs?

e.g.
Button A1 will reset the group of LEDs on D2, D3, D4, (don't use D0 D1 as mentioned above!)
Button A2 will reset the group of LEDs on D5, D6, D7
Button A3 will reset the group of LEDs on D8, D9, D10

All timers will start on Power up?

I could do this with 1 LED.

please show your working code for one LED

If you have three groups of LEDs does each group have to have all the LEDs illuminated at the same time, or do you need individual control over each LED in a group.

If the former then simply run all three LEDs off the same pin. You will just need a transistor, like this.

You don't even need the transistor if you make the resistor on each LED such that you don't draw more than 30mA from the pin. That is fix then to take 10mA each and not 20. They will be bright enough.