Arduino Multiple Timer. Day Based and Alarm Based

Intro: 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.

Share

Recommendations

  • Plastics Contest

    Plastics Contest
  • Electronics Tips & Tricks Challenge

    Electronics Tips & Tricks Challenge
  • Audio Contest 2018

    Audio Contest 2018

40 Discussions

0
None
RamC39

4 days 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
0
None
clepceaRamC39

Reply 4 days 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.

0
None
RamC39clepcea

Reply 4 days 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?

0
None
RamC39RamC39

Reply 4 days 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!

0
None
kooroshi60

7 days 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.

0
None
AndrewM512

1 year 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
0
None
clepceaAndrewM512

Reply 1 year ago

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

0
None
Alvisy1

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
0
None
Razsec

14 days 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 rancorpces@gmail.com

1 reply
0
None
clepceaRazsec

Reply 13 days 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

1
None
LeviD12

1 year 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

5 replies
0
None
clepceaLeviD12

Reply 1 year ago

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){

if(index==0){

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".

0
None
LeviD12clepcea

Reply 1 year ago

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

0
None
clepceaLeviD12

Reply 5 months ago

I do not understand the question. Sorry.

0
None
clepceaLeviD12

Reply 1 year ago

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

0
None
clepceaLeviD12

Reply 1 year ago

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.