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.

2 People Made This Project!


  • Trash to Treasure

    Trash to Treasure
  • Pocket Sized Contest

    Pocket Sized Contest
  • Build a Tool Contest

    Build a Tool Contest

45 Discussions


7 weeks ago

Hi, thanks for sharing.Hi, thanks for sharing Clepcea.

I have tested this timer in a UNO and a MEGA, both in Arduino 1.0.6 and Arduino 1.6.11 and it does not work, in the Settings function, the MENU button does not work, I do not have short circuits in the buttons.
I am new to Arduino and I would appreciate it if you would help me.
Thanks for your help.
My email:

Thank you.


2 months ago on Step 1

Hey Adrian,
I guess in the "Main.pdf" schematic, SCL & SDA must be pull-up, R1 & R2 are connected to GND. Please have a look.


Question 2 months ago on Step 2

Hi Adrian,
great piece of code, I have built the system and it seems to be working.
for debugging purpose what does "Cu ora" & "Fara ora" exactly mean in english. sorry my Romanian is bad.


2 answers

Reply 2 months ago

Hi thx.
Cu ora = with hour
Fara ora = without hour.
Sorry for now writing everything in english, but I never intended to share the code when I started working on it.


Reply 2 months ago

Thanks a lot for your reply. Great work. cheers!!


5 months ago

This is exactly what I needed for my project! That you so much for sharing. Although I have encountered a problem with setting the alarm. When I try to change it, both "hour" and "mins" change with either the PIN_STG or PIN_DR pressed. Sometimes it does change at all. Please I need your help, thanks in advance!

3 replies

Reply 5 months ago

This problem appeared on only one other ocassion. The culprit was a faulty connection as the owner said when he managed to solve it. You must have short circuit somewhere.


Reply 5 months ago

I solved the problem by using an older version of arduino 1.0.6. Is there a way to be able to use more relays? 12 relays for example? What change to the code should I do?


Reply 5 months ago

Hi! I actually did it! the problem was I used the latest arduino version i used it on 1.0.6 version and it worked perfectly. I have another question, what do I need to do if I want to put more relays? 12 relays for example. Thanks!


5 months ago

Thank you so much for sharing your project. I tried to upload the sketch on Arduino NG (Atmega8) but it was not possible and compilation failed with "Not possible to compile for Arduino NG" error.

But I see in the schematic you have provided, there is Atmega8 used. How it is possible? And how you load the Arduino UNO sketch on Atmega8?

P.S. I'm using an Arduino UNO as ISP programmer to load the sketch on Atmega8.

Thank you in advanced.


2 years ago

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

3 replies

Reply 1 year ago

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


1 year ago

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.

2 replies

5 months ago

I want to build a project that will water the plants every day morning at 9:00 for 5 minutes, spray a pesticides every 3 days and spray also a liquid fertilizer for every 2 weeks.. is this project of yours capable of doing that??, this is for our thesis project

i would like to have the codes is it possible? will registering to premium enable me to have the codes..heres my email

1 reply

Reply 5 months ago

Hi, the project does exactly that, the code is available inside the project, no need to use any premium account.

The only think that you must pay attention to is that the project is written in an old Arduino IDE version, so the last version will not work. That is written in the article however


2 years ago

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