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.

Thanks for this wonderful project, I was wonder which functions to alter to have longer durations, say 12 hours. Regards
<p>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</p>
<p>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</p>
<p>You could change these 2 functions:<br><br>long valAlarmaMin(byte index){</p><p> return (alarme[index]).hour*3600L+(alarme[index]).minute*60L;</p><p>}</p><p>long valAlarmaMax(byte index){</p><p> byte multipl = (alarme[index]).unitAlarma?60:1;</p><p> return (alarme[index]).hour*3600L+(alarme[index]).minute*60L+multipl*(alarme[index]).duration;</p><p>}</p><p>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:</p><p>long valAlarmaMin(byte index){</p><p>if(index==0){</p><p>return 8*3600L+3*60L;</p><p>}else if(index==1){ //for the second</p><p>....</p><p>}... and so on</p><p>}</p><p>For the display, in the :</p><p>checkAlarms function you would have to modify the &quot;linia&quot; variable to say just &quot;on&quot; or &quot;off&quot;.</p>
<p>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 </p><p>thanks for the fast reply </p>
<p>And yes, the alarm would go off at 8 hours and 3 minutes.</p>
<p>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. </p><p>I am i no position now to do so, as I have no time and this would be a different project.</p>
<p>hi there is it possible you could share a simpler schematic my email Sameer.hoosain@gmail.com</p>
<p>Hello, </p><p>What do you mean by simpler? This is the standard way as far as i know. Give me an example and I will try to oblige.</p>
<p>thanks so much for your reply, something to this effect: follow link. </p><p><a href="https://goo.gl/images/xlWzBC" rel="nofollow">https://goo.gl/images/xlWzBC</a></p><p>i understand schematics but i dont have the software to open your files, apologies for the inconvenience</p>
<p>Here you have the pdf version of the schematic. It is kind of difficult to make a Fritzing schematic as the two shields are not commercially available, but ... the schematics are here</p>
<p>Salut bravo pentru acest proiect ma bucur ca Rominii fac lucruri frumoase !!!</p>
<p>Si eu ma bucur ca sunt si alti romani care se uita peste instructables.</p>
<p>What is the 'clopote PCB'in attached file for?it seems another pair of shoes.</p>
<p>Thanks so much for your kindness.</p>
<p>awesome.What is the rating of the relay and resistor of the relay board.</p>
<p>The resistor on the base of the transistor is 1kohm-4.7kohm (an 1/4 W will do).</p><p>The resistors on the leds are 330ohm - 1kohm, depending on the leds. (mine are 330 ohm here). <br></p><p>The relay is a 5V DC on coil, supporting a 5A 230V AC current (JV-5S-KT model).</p><p>The transistor is a bc547, but any NPN resistor would be ok.</p>
<p>Thanks,</p><p>If I total all the time, I would say about 24 hours from 0 to the stage it is now, but since I only worked on it now and then when I had some time, about 1 week.</p>
<p>This is a fun little timer. How long would you say that it took you to make?</p>

About This Instructable




More by clepcea:Arduino multiple timer. Day based and alarm based 
Add instructable to: