Dual sharing RTC

Prototype

Necessity

I have an old window AC at my lab, situated at the terrace. The AC needs to be run intermittently more so often when I’m out of the station and the lab PC needs to be cooled down during the intense noon time when the temperature shoots 35+ degree centigrade irrespective of summer or winter. Of course, the thermostat works! But it needs to be changed continuously else it will keep on running for prolonged periods during summer time which I want to avoid especially.

The following timer based on Arduino does exactly that. I can set the on-time and off-time based on the entire calendar timings! It is based on a simple DS3231 RTC timer, an ATMEGA328 Arduino chip, a small 5-volt relay to run the 5KW contactor which will eventually control the AC.

Trigger to go further

‘Uncle you have made a whole calendar dependent timer but you are not showing clock/calendar or the alarm time etc. anywhere ,it should display time at least to know what it’s going to do next or what it has done so far etc.!’, My friend’s son Reon, declared his first impression.

And the whole can of worm got spilled out and I failed to comply miserably to his request! For running the on-time and off-time, I’ve used switch statements combined with ‘if’ statements. Therefore, the clock necessarily stops inside the ‘if’ loop. Only when the ‘if’ statement expires the loop ends, the clock starts and the next ‘switch’ statement is executed. Therefore, the clock display will run intermittently with this sketch when it executes the loop thus I failed to achieve the continuous display of the clock as Reon desired!

Alas!If I could run a second Arduino independently, at the same time sharing clock, it would solve the problem fully. Else, can I put a 2nd clock parallel to this Arduino!

Idea

A man with one clock always knows the time, with two clocks never quite sure. Therefore, when it’s a time-dependent project, it’s always better to have singular clock shared by all. However, I didn’t go through a lot of pains to make it super accurate, but it passes the eyeball test quite well and that’s good enough for me, I’m not managing satellites or cell towers. A multi-master I2C RTC set up is build up using RTC DS3231. RTC DS3231 is a pretty precise RTU which has an inbuilt temperature sensor for adjusting the clock frequencies for temperature corrections. It maintains very precise timings over a long duration.

The principle of operation

The DS3231 is a very precise RTU which is being shared here by two Arduinos and in the same principle, it can be shared by more Microcontrollers as well. One Arduino runs the timer while the other Arduino displays the time and all other allied displays whatsoever to be shown. For handling hour, minute and second in the simple decimal way, I’ve followed a trick that is also used by many on the Internet –

unsigned long now_time = hour*10000+minute*100+second; eg 72323 is 7:23:23
unsigned long on_Time=onhour*10000UL+onmin*100+onsec; 192123 is 19:21:23
unsigned long off_Time=offhour*10000UL + offmin*100 + offset; 212223 is 21:22:23

Now when now_time becomes >= 192123 and <212223 the timer will fire! So simple.
However, when the time reaches beyond 23:59:59 I’ve used another trick to manage the show…

TFT ILI9163 is a 128*128 dots color display runs on SPI bus along with Reset & AO & CS pin to run on the 2nd Arduino. When the alarm GPIO pin fires on the 1st Arduino the same is read by the 2nd Arduino on pin A3 using digitalRead (alarm_pin) to trigger the “alarm on” / “alarm off” display.

Schematic

Schematic

Digital pin-3,4 acts as alarm pin from the first Arduino, The A3 pin on the 2nd Arduino reads this status to process inside the 2nd Arduino. TFT ILI9163 is connected on the 2nd Arduino to display time, alarm time etc. The RTC DS3231 is shared by both these Arduino. The relay connection goes further to the contactors for switching of the AC machines which need to handle a bigger load. Bill of Materials & Price [aliexpress.com ]
1 * DS3231 – $1
2 * ATMEGA328 / UNO – $4
1 * 128*128 TFT [ILI9163] – $3.5
2* 5V sugar cube relays $1.5
————————————————–
Total: $10.0 [ Box , contactor, 5Volt power supply costs are separate ]

Prototype

Aftermath

More circuit ideas on dual sharing of RTC – In a stroboscope where one MCU will create the variable pulse while the other will display the pulse frequency and rotation of the shaft, while both the MCU will be sharing one I2C – RTC.

Download Source Folder

 

 

Read More Detail : Dual sharing RTC

 


About The Author

Ibrar Ayyub

I am an experienced technical writer with a Master's degree in computer science from BZU Multan University. I have written for various industries, mainly home automation and engineering. My writing style is clear and simple, and I am skilled in using infographics and diagrams. I am a great researcher and am able to present information in a well-organized and logical manner.

Follow Us:
LinkedinTwitter
Scroll to Top