Arduino Multiple Timer. Day Based and Alarm Based


Introduction: Arduino Multiple Timer. Day Based and Alarm Based

So I was asked by someone if I can make something that will start a motor at a fixed time. Ok ... easy.

But the motor should start in each day at a different hour or perhaps Monday and Friday at an hour and Sunday not at all, or whenver he wants to program the motor to start. I thought this would make a nice project, especially that he came with the request to start three motors after all. After several discutions with several people I've ended up with a project that:

- Can have up to 6 "alarms". In fact the number can be bigger with small modifications of the code

- Can start up to 7 devices separatelly (each device being connected to a pin).

- Has a real time clock (DS1307)

- Is based on Arduino

- Saves the settings in EEPROM so that they will not be fogotten after a power failure.

For this project I have done two shields that are put on top of Arduino UNO.

One shield with the DS1307 RTC (I didn't have the time to wait for a ready made one)

One shield that has three buttons connected, an 16x2 LCD and three relays (the rest of the connections (4 of them) would have to be connected from the pins directly. I did provided the programming for them, but, since I did not needed more than 3 outputs, i did not made a greater shield :).

So for the functioning principle now:

The user can:

- Set up the current date and time and the current day of the week.

- Choose a time for each of the 6 possible alarms

- Choose the day that each alarm will be started

- Choose the time (in eaither secs or minutes) that an alarm can stay on

- Choose the outputs (relays) that will be started when each of the alarms will start.

All these will be shown on the 16x2 LCD screen and will be set up using the three buttons.

For example if I want the system to water my lawn Monday to Friday from 8.00 AM to 9.00 PM, Saturday to start heating the water in the pool at 8.20 (not that I have one ;) ) and stop at 9.00, and everyday to start the coffe making machine at 7.30 AM and stop it at 7.31, I would need to set up 3 alarms:

1. First alarm with the starting hour at 8.00 and a period of 60 mins that will run in the first six days of the week and will start two of the relays (if I have two pumps for the lawn)

2. The second would start at 8.20 and run for 40 mins and would start the relay number 3 and would run only Saturday

3. The third one would start each day at 7.30 and would run for 60 secs and would start the relay number 4 (if you have one connected)

Step 1: Making the Shields

The shields were made using the Toner transfer method, but any method would do. They were coroded using Feric Chloride.

1. The RTC

The first step for me was to make the RTC shield. If you are lucky you allready have one and you do not need to make it.

The schematic was made in Eagle and can be found in the download files.

As you can see, the shield has a battery holder (so that the time will be remembered if the power goes out). An Cr2032 battery is what I have chosen here. Also there is an variable resistor that can be used for an LCD, but in my project I did not used this one. It is there just in case I need it for some other project. There is also a reset button that can be put here to reset your Arduino in case you need it.

2. The relay shield

The relay shield can be seen in images before being coroded and after it was partially mounted with the electronic parts. The shreded paper is shreded just because I could not wait for the glue to harden and I used a cutter that was just not sharp enough :D.

The schematic and the board layout are in the attached files.

Step 2: The Code

The code was compiled using Arduino version 1.0.6.

The code uses the following libraries:

  • Wire.h - to communicate with the DS1307 clock
  • LiquidCrystal.h - to show the time on the screen and the menu
  • math.h - this library is here just because I wanted to see/show how you can use it in stead of bit shifting, but can be easily removed and the few places were it is used can be replaces with bitshifting
  • EEPROM.h - this is used to store the settings into the eeprom

The code is quite lengthy, but it takes about half of the available space in Arduino, so there is still room for improvements.

The entire code is in the attachement so I will just put some parts of it here just to explain a few things since the language used in comments is Romanian not English (well, what can I say ... I write what I speak :) ):

In the define portion of the program we have:

#define DS1307_I2C_ADDRESS 0x68 //this is the i2c address of the DS1307 chip

#define PIN_STG 8 //the arduino pin used for the left button in the menu

#define PIN_MENU 2 //the arduino pin used for the menu button

#define PIN_DR 10 //the arduino pin used for the rights button in the menu

#define PIN_COMMAND_A A1 //relay A

#define PIN_COMMAND_B A2 //relay B

#define PIN_COMMAND_C A3 //relay C

#define PIN_COMMAND_D A0 //relay D

#define PIN_COMMAND_E 7 //relay E

#define PIN_COMMAND_F 9 //relay F

#define PIN_COMMAND_G 13 //relay G

#define DESCHIS LOW //Deschis means open so that the relays will be normally opened

#define INCHIS HIGH //Inchis means closed so that when an alarm goes on, the relays will be closed

I would say that the rest of the code is straight forward. It contains some gibberish code that makes the microcontroller happy and does not take space so that I can move in the menu or read the settings etc.), but the rest is just Arduino code.

Step 3:

Enjoy the alarm. (the photos from this step are provided by a user of this project Hibs H).

Thanks to Hibs H for providing photos and for testing the project and giving me the feedback needed to solve some bugs. Especially he contributed to the possibility to add longer alarm times and to program the alarms across the entire day.



  • Casting Contest

    Casting Contest
  • Make it Move Contest

    Make it Move Contest
  • Planter Challenge

    Planter Challenge

We have a be nice policy.
Please be positive and constructive.




what would i have to change to have the alarms set in the code and and have the display just if the relay was on or off? thanks so much

5 replies

You could change these 2 functions:

long valAlarmaMin(byte index){

return (alarme[index]).hour*3600L+(alarme[index]).minute*60L;


long valAlarmaMax(byte index){

byte multipl = (alarme[index]).unitAlarma?60:1;

return (alarme[index]).hour*3600L+(alarme[index]).minute*60L+multipl*(alarme[index]).duration;


The first one should check for the index (0 for first alarm, 1 for the second and so on) and put an exact value for each. For example for the first alarm (min) hour 08:03 would be:

long valAlarmaMin(byte index){


return 8*3600L+3*60L;

}else if(index==1){ //for the second


}... and so on


For the display, in the :

checkAlarms function you would have to modify the "linia" variable to say just "on" or "off".

would this allow me to remove any of the functions? the example alarm you said would go off at 8 hours and 3 minutes? just want to make sure i understand

thanks for the fast reply

I do not understand the question. Sorry.

And yes, the alarm would go off at 8 hours and 3 minutes.

This are the minimal changes you could do so that the arduino would do what you want. With only these modifications you could not safely remove any functions. Of course it is possible to make more modifications and remove functions, but this requires more code modification and verification.

I am i no position now to do so, as I have no time and this would be a different project.

could i use this to turn on and off aquarium lights at different time points every day? example i would like to turn on a light around 12:00 and off at 13:00 then at 14:00 turn off 2 other lights but then at 1500 turn on of them back on then turn everything off at 20:00 and back on at 09:00

2 replies

Of course you can. This project would be an exact match for your requirements.

can i add more relays to it to control more devices?? How can i set the alarm in hours, like, if I want to turn on the relay at 8:30 in morning and turn off at 9:30 i the night??

5 replies

Arduino uno does not have any more ports than that, so the simple answer is NO. You could however modify the code to use an i2c (or rs232) extension which can have as many relays as you want.

You can add more relays only if you use an i2c bus for extension. There are only some many ports on arduino.

Of course using an i2c bus would mean you would also have to make some code changes.

To add hours you can multiply minutes by 60. As far as I can remember I have limited the interval to 240 (could have been a maximum of 255 because it stored as a byte). So that would be 240/60 = 4 hours. That is the maximum interval. You could however add another interval following the first so that you would end up with 8 hours. If you continue, you can get more in increments of 4 hours.


thank you..

I was thinking of doing it o Arduino Mega to connect more relays. But will that change the relay shield for mega??

As far as I know Arduino Mega exposes the same ports as Arduino Uno for the first part of pins. So you should be ok.

Using an Arduino Mega will absolutely give you more ports, but you will still have to add them to the source code. Of course, this is an open-source project and you can do that freely.

if i want to do a project about water and fertilise plant and setting 2 different times to on and off . can i use this code to modify..and what i need to have.

1 reply

Thanks for this wonderful project, I was wonder which functions to alter to have longer durations, say 12 hours. Regards

1 reply

For now the time is in minutes and the intervals are limited to 240. So the maximum interval wold be 240 minutes (4 hours).

To obtain 12 hours you could use three intervals one after the other each one having 240 minutes.

hi there is it possible you could share a simpler schematic my email