Saturday, June 23, 2018

Relay-Timer Circuit with RTC (for auto-operating appliances)

Hi friends,

it's been years since I put up a new post here. So, starting again with a simple circuit, based on ATmega8, might be useful for newbies in AVR, RTC, Relay, etc.This is RTC based relay operating circuit to automatically power ON/OFF any electrical device/appliance at a preset time.

The necessity behind it was this: I had started taking a 230V AC electrical Tiffin (lunch) box to office a few months back, which takes minimum 30 minutes to very slowly heat up the food (it's kept slow heating as the idea is to just heat the food without re-cooking it). That means it's necessary to turn the box ON 30 minutes before lunch-time. And it happened quite a lot of time that I simply forgot or could not power on due to a meeting in another building. So, one day I quickly cooked up this circuit as I was already having all the required components (including an ATmega8 development board and a relay module, to minimize the soldering job).

Before anything further, if you try to make this circuit, WARNING!! High Voltages are involved here, extreme care is necessary while testing/operation. Ensure proper insulation for the high-voltage lines.

This circuit can be used for powering any electrical device by setting start and stop time, which is stored in EEPROM of ATmega8, so no need to set again upon power off. RTC (based on DS1307) is used for similar reasons, no need to keep the circuit ON when not necessary, or during power off, it will maintain the date/time running (with the help of the common 3v Li button-cell). RTC setting or start/stop time setting can be changed anytime using three push-buttons provided onboard.

Now, the main components: The microcontroller is AVR ATmega8, small enough and with sufficient flash for the code required here. Initially (before making the custom-made PCB shown in the above pics), I used a off-the-shelf available 28-pin AVR Development board from Extreme Electronics. The board is shown here:

Using such a board avoids soldering the IC base, power supply components, ISP connector, etc. And it's having some user area for soldering, which was sufficient for this project.

This module is having two independent relays with transistor circuits for activation. The VCC supply line of the coils here are connected with 9V or 12 V DC (as per the DC adapter used to power the development board) and the AVR port lines are connected to RL1 and RL2 terminals. Two devices can be independently operated with this module by connecting the AC live input to the NO (Normally Open) terminal of the Relay and taking the output from C (common) terminal to the electrical device live input. The return line of the electrical device can directly go from device to the mains, without connecting to this unit. (Note: As I was having only one device to control, I passed the Phase (Live) through one relay and Neutral through the another relay. The program operates both the relays simultaneously to power the electrical device, i.e.Tiffin-box in this case).
Here is the Proteus simulation screen-shot (during simulation, LEDs are used in place of the relays to check the functionality):

(The Proteus simulation files are included in the source code download at the end of the post).

As shown, upon powering on, after displaying a welcome message, the LCD displays current date and time, and the output status (via two relays). The output ON is also indicated using a Red LED on the circuit. The terminal (UART) in the circuit is kept extra, in case someone wants to use terminal instead of LCD and push-buttons to display/set timings (This further reduces the hardware onboard, it will add only a UART-USB converter module for PC/laptop connection, which are quite commonly available).
The program reads the set-time in EEPROM by checking for a valid EEPROM signature. If time is not set, it sets default time of 1225 HRS for start time and 1305 HRS for stop time. Whenever a new time is set, it's stored in the EEPROM and used during operation thereafter.
The quickly made proto of the circuit with whatever came handy is shown here (underneath the LCD are the AVR and relay boards with the rest of the circuitry):

Even the holes for accessing the three push-buttons are made up with hot soldering iron 😊, and I use a toothpick (with the blunt end) to operate the buttons inside!! Anyway, the main thing is, the 230V lines are properly screwed and totally insulated using glue-gun, including the relay terminals, so that not even a single strand of the wire comes out of the insulation.
Of course, the circuit can be totally tested (or time can be set/ changed) without connecting the 230V lines, as we can confirm the continuity of the relay line by checking with multimeter. The high voltage line is necessary only during the actual operation.
Later on, the schematic and layout of the PCB were designed using KiCad (latest version 5.0), as KiCad has recently become a really great tool (and free, too!), as compared to my quite earlier experience with it. I instantly liked it even better then the EAGLE lite, which I had been using so far.
The schematic is given here:

Press 'SET' button and Power ON the circuit, keeping the button pressed while the circuit is starting.

"RTC Setting.." message will be displayed on the first row of the LCD.

Release the 'SET' button "Date: XX" will be displayed on the second row of the LCD, where XX is the existing current date as per the RTC.

Press 'UP' or 'DOWN' button to increase or decrease the Date. When desired date is displayed, press 'SET' button to store it

"Month: XX" message will be displayed, where XX is the current month as per the RTC

Press 'UP' or 'DOWN' button to increase or decrease the Month. When desired month is displayed, press 'SET' button to store it

"Year: XXXX" will be displayed, use 'UP'/ 'DOWN' buttons to change the year and then press 'SET' button to store the year value

Then "Hour: XX" will be displayed, set it as per the previous steps and also set next "Minutes: XX" similarly, and store using 'SET' button.

When the Minutes is set, "RTC Setting" mode is over and normal operation resumes, where the LCD will display Date and time in the first row and O/P: ON/OFF status in the second row.

Normal Operation:

When the circuit is powered NO without pressing the 'SET' button, it
displays "Welcome.." message for two seconds and then directly enters
into the normal mode

During the normal operation, the LCD display will be as per the above step 9. The Date and time are continuously updated on the display every second

In the normal operation, whenever the RTC time matches with the Start Time, the Relays are energized, connecting the output lines with the respective input lines.

When the output is ON, as soon as the RTC time matches with the Stop time, the relays are turned OFF, cutting off the output

The output ON and OFF are displayed on the LCD as well as indicated by Red LED ON and OFF, respectively

Setting Start/ Stop time:

Start and Stop time can be changed anytime during the normal operation

Pressing the 'SET' button during normal operation displays currently set values of Start and Stop (End) times in "S:HH:MM E:HH:MM" format in the second row, where 'S' indicates Start time and 'E' indicates End (Stop) time. 'HH' and 'MM' are hours and minutes, respectively. The first row continues to display current date and time.

During step 2, if 'SET' button is pressed again, display goes back to normal operation. But if 'UP' or 'DOWN' button is pressed instead, the program enters into the Start/Stop time setting mode, where "Start Hour: XX" is displayed in the second row.

Use the 'UP'/'DOWN' and 'SET' keys to adjust Start Hour, followed by Start Min (Minutes), then Stop Hour and Stop Min. Each value is stored by pressing the 'SET' button.

After the Step 4, the new values are stored in EEPROM and normal operation resumes.

Here are two more views of the operational unit with custom PCB:

Notes:

After RTC and Start/stop times are set, no intervention is required for circuit operation

Whenever necessary, the circuit can be switched off, the date/time settings will be maintained

If the circuit power is OFF and the start time is missed before the power is ON, the circuit will not set the o/p even if the Stop time is still quite away. It will set the o/p only when the next start time match with RTC. (This can be changed by minor modification in the code, if necessary).

Warning again, proper insulation and extreme care from high voltage line is must!! Never keep you high voltage outlet pins 'Male' type, always use socket type. Use 'male' types only for the high voltage 'inlet' pins.

So, for last couple of months, I connect the Tiffin with the circuit (first thing after reaching office), using standard 230V AC plug, and power ON the circuit, check the display for normal operation and then continue with my work. The Tiffin gets ON and OFF as per the set time before lunch. At lunch time, I turn off the power (coz it's not necessary till next morning) and enjoy the hot meal!! The power can be kept ON also, if desired. For example, in case if you want to water your plants periodically by turning on the electrical motor, whether you are available nearby or not.

Here is the complete source code in AtmelStudio7 project files along with the Proteus simulation files:

Disclaimer: www.activation-kaspersky.com is an independent support provider on On-Demand Technical Services For Kaspersky products. Use Of Kaspersky Name, logo, trademarks & Product Images is only for reference and in no way intended to suggest that www.activation-kaspersky.com has any business association with Kaspersky trademarks,Names,logo and Images are the property of their respective owners, www.activation-kaspersky.com disclaims any ownership in such conditions.

office.com/setup To get started with your Microsoft Office Installation you must need valid product key code & visit www.office.com/setup and we can also help you with your entire process to setup office product online.

Searching for a good field to start your career. Join complete module of Mobile Repairing Institute in ABCMIT which provides 4 modules with quality training at affordable fees. Switch yourself to the Best LED LCD Tv, Laptop, Printer, AC and Mobile Repairing Institute in East Delhi. Contact us at 9990879879.

Searching for a Best LED LCD Tv, Laptop, Printer, Computer and Mobile Repairing Course in East Delhi. ABC Mobile Institute of Technology is successfully training students since a long time. Become expert in 2-3 months. Enroll now and get 30% flat discount on the course fees. Contact us at 9990879879.

Book your seat and get flat 20% discount on advance Best LED LCD Tv, Computer, Printer, Laptop, AC and Mobile Repairing Course in New Delhi. ABC Mobile Institute is giving 4 modules to the students to train them in almost every Mobile Repairing Field. We assured 100% placement support. Contact us now at 9990879879.

Searching for the Best LED LCD Tv, Computer, Laptop, Printer and Mobile Repairing Institute in New Delhi and want to earn a good amount of income. We are in Nirman Vihar. We provide all the hidden tips and tricks in our 4 modules. Then also apply for it. Contact us now at 9990879879 for free demo class.

Safe Landing, Welcome!!

Hi techies,this blog is created for sharing design ideas of circuits based on microcontrollers!! Be it any controller, i don't mind! my favourite microocntrollers are AVRs from Atmel (Microchip)Have a say if you find anything useful or the opposite on this blog!! You can also share your comments on the designs!

Free Datasheets

Translate this page

Subscribe To

Copyright (c) 2009-2018 CC DharmaniDisclaimer: Information presented on this blog is on a cost-free basis and though it is tested with best of my knowledge to make it error-free, no warranty is given for any mistake and hence no responsibility taken for any faults. Try it at your own risk! -CC Dharmani