Saturday, June 23, 2018

Relay-Timer Circuit with RTC (for auto-operating appliances) using AtmelStudio or Arduino

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.
    The Dual-channel Relay board used initially is from EmbeddedMarket.com:

    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 and the serial terminal is unused):

  Following is the simulation using ATmega328 (Arduino):

 (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 1230 HRS for start time and 1300 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):

       The 230V lines are properly screwed and totally insulated using glue-gun inside the box, 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 (when using Arduino, replace ATmega8 with ATmega328 in the circuit, in the same PCB):

       The PDF schematic can be downloaded from here.

The operation of the circuit is described here:

Circuit Operation:
For setting RTC Date/Time:
  1. Press 'SET' button and Power ON the circuit, keeping the button pressed while the circuit is starting.
  2. "RTC Setting.." message will be displayed on the first row of the LCD.
  3.  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.
  4.  Press 'UP' or 'DOWN' button to increase or decrease the Date. When desired date is displayed, press 'SET' button to store it
  5. "Month: XX" message will be displayed, where XX is the current month as per the RTC
  6. Press 'UP' or 'DOWN' button to increase or decrease the Month. When desired month is displayed, press 'SET' button to store it
  7. "Year: XXXX" will be displayed, use 'UP'/ 'DOWN' buttons to change the year and then press 'SET' button to store the year value
  8. 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.
  9. 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:
  1.  When the circuit is powered ON without pressing the 'SET' button, it displays "Welcome, -Relay timer-" message for two seconds and then directly enters into the normal mode
  2. 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
  3. 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. 
  4. 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
  5. 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:
  1.  Start and Stop time can be changed anytime  during the normal operation
  2.  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.
  3. 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.
  4. 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.
  5. After the Step 4, the new values are stored in EEPROM and normal operation resumes.
       Here are two more views of the operational unit:

  • 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 and Arduino project files along with the Proteus simulation files (please ensure programming the fuse bites for proper clock frequency values). When using Arduino, ATmega8 needs to be replaced with ATmega328:


Source Code (AtmelStudio) and Simulation Download (ATmega8, @8 MHz internal clock)

Source Code (Arduino) and Simulation Download (ATmega328, @16 MHz External clock)

KiCad Project Schematic, PCB and Gerber files

Datasheets/ Links:   ATmega8,   ATmega328,   DS1307,   Arduino Website


Thanks & Regards,
CC Dharmani 


Unknown said...

Garmin Download at www.garmin.com/express. Register, update and sync your garmin express today and get started with your Garmin maps


Unknown said...

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.


karenminton said...

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.



karenminton said...

mcafee.com/activate - Follow these basic strides to download, establishment and enact your mcafee item. for more data visit: www.mcafee.com/activate .


Gagan said...

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.

Gagan said...

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.

Gagan said...

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.

Gagan said...

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.

mannu aryan said...

It’s not my first time to go to see this web site, i am visiting this web page dailly and get good information from here all
the time.

Led Lcd Repairing Institute In Delhi
Led Lcd Tv Repairing Course In Delhi
Led Lcd Tv Repairing Course In Delhi

TechWhoop said...

I love this post. Thanks for starting it. Loved the thought that was put behind writing this. I'm glad. :)


norton.com/setup said...

I really happy found this website eventually. Really informative and inoperative, Thanks for the post and effort! Please keep sharing more such blog.


norton help

roadrunner email


aol mail

seattlelimoline said...

Now we know who the sagacious one is here. Thanks for Sharing Article

So, whenever you desire to hire or travel these limousines, you can visit our website or provide them a call through the exclusive numeral to hire these limousines.
Limo Service Seattle
Seattle Limo Service

seattlelimoline said...

Awesome, your post makes mine look feed able. Additional power to you!
Seattle is a good-looking city to travel when you require a break of you hustling lives.
• On time dropping off at your place.
Seattle Airport Transfer Services
Seattle City Tour Car Rental Services
Visit our website to experience the luxurious Limo Service Seattle at an affordable price.

Anonymous said...

Hey, this is a very impressive and great article. Get connect with our professional lawyers. Then, if you have any kind of matters regarding Accident Attorney in Los Angeles and also connect with our website.
Accident Attorney in Los Angeles

Accident Attorney in Los Angeles said...

Hey, this is a very impressive and great article. Get connect with our professional lawyers. Then, if you have any kind of matters regarding Accident Attorney in Los Angeles and also connect with our website.

QuickBooks helpline number said...

this was really a great blog. Looking forward to getting more information like this.

pbn netbanking said...

Great stuff and great presentation.

Oty Emmanuel said...

The safety pyramid was created by H. W. Heinrich, about 88years ago.

The Safety Pyramid compares the frequency of different types of incidents, ranging in severity from generally unsafe behaviors and hazards, to incidents that end in serious injuries or fatalities.

It offers a ratio formula that encouraged safety professionals to focus on the causes of minor injuries as a way to reduce the probability of having major accidents.

From the pyramid, unsafe behaviours and resultant negative outcome increases as you move up the pyramid.

What the pyramid encourages us to correct those little violations at the base of the pyramid; if that is done, the pyramid will never have the chance to reach the upper catastrophe level.

Make it a habit to observe, investigate, and document each incident thoroughly no matter how minor. The Safety Pyramid is a reference tool that can help to encourage an effective safety culture within your organization and promote accountability throughout the workplace.

Norton.com/setup said...

Norton.com/NU16 – Norton Utilities 16 does way more than just disk defragmentation. Norton NU16 is an app that runs on personal computers and Macs, which makes it unique among defragmentation programs, and it also has a bootup optimization method. Norton.com/setup

xpert said...

Through these business owners or entrepreneurs can easily manage their business (financial and accounting information) accurately. But sometime when using it you might need appropriate and effective Quickbooks help by either you or your QuickBooks online accountant for top and effective usage of this software. The QuickBooks Support is toll-free while the professional technicians handling your support call will come up with a sudden solution that can permanently solve the glitches.

happy new year 2020 Images said...

This is really an awesome post.

norton.com/setup said...

I really happy found this website eventually. Really informative and inoperative, Thanks for the post and effort! Please keep sharing more such blog.




kaspersky activation code

free pogo games

roadrunner email

aol mail

norton.com/setup said...

I really happy found this website eventually. Really informative and inoperative, Thanks for the post and effort! Please keep sharing more such blog.




kaspersky activation code

free pogo games

roadrunner email

aol mail

Chauhan Mandis said...

Thumbs up for the great information you share on this post.

QuickBooks Error Code 15241

Fix QuickBooks Error Code C=51

QuickBooks Error 3371 Status Code 11118

TechnoBridage InfoTech said...

If you are interested in IT company in surat then we can provide services.

John Trump said...

Quicken vs QuickBooks is a thought which comes in user mind while choosing the accounting software. To know the difference contact us at 1-877-263-2742.
Quicken vs QuickBooks | QuickBooks Online vs Desktop | What is QuickBooks

jobs in nigeria said...

Hi there to everyone, it’s actually a good for
me to go to see this site, it contains useful Information.

NJC Recruitment

Nigerian Prisons Service Recruitment

NAPTIP Recruitment

NUC Recruitment

NDIC Recruitment

NAMA Recruitment

TETFUND Recruitment

PPPRA Recruitment


Aim Packers and Movers said...

Aim Packers Movers Navi Mumbai Provide Best Home Shifting Services. For Affordable Near Me Packers and Movers in Navi Mumbai Contact us and Get Free Quote.
Packers and Movers Near Me | Packers and Movers in Pune

Wewpyou said...

stripe micropayments

[url=https://www.wewpyou.com/paypal-vs-stripe/]stripe fees vs paypal[/url]

Wewpyou said...

internal server error wordpress
wordpress error 500
500 internal server error wordpress
wordpress 500 internal server error
500 internal server error wordpress wp-admin

Florida Vacation rentals said...

Florida Vacation Rentals
Cape Coral Vacation Rentals
Siesta Key Vacation Rentals
Wild Life ranch borne texas hill country
vacation rentals in galveston
Long beach condo
Anglers reef villa oceanfront rentals

anajuliausany said...

Thanks for sharing your knowledge via this post.

QuickBooks Sync Manager Error | QuickBooks Update Error 12007

ashley said...

The information you shared was useful. You have brought up a very wonderful points , regards for the post.
canon printer support | brother printer support| epson printer support | hp printer support

HTTP Error When Uploading Images to WordPress said...

Hello guys I, am a content marketer and WordPress Developer. My technical experience gives a completely different perspective and also helps me to make my blogs simple yet informative. With my tutorials and other informative articles, I try to help people who are working in the same field.

lucifer1413 said...

Norton.com/setup - Consumers and small businesses are experiencing a new sense of security for over 25 years with Norton. Norton setup downloaded from the norton.com/setup page helps to work and explore the ever-changing digital landscape. Norton makes it as easy to protect and manage your devices while installing an application on your smartphone.

For More Information Visit Our Site: norton.com/setup 

Tom Clark said...

The fact that you can get a fully unique paper in a matter of hours is impressive. I needed an essay overnight and I was lucky to turn to superior papers. It was ready in six hour and it was ready just as it was.

Shweta gaur makeup artist said...

Shweta gaur is one of the famous makeup artist in all over India. We are providing the best makeup artist courses and more other courses in over branches in Delhi.

Makeup Artist in Delhi
Makeup Artist
Best Makeup Artist in Delhi
Best Makeup Artist in East Delhi

Chauhan Mandis said...

Thanks for sharing this fantastic blog, really very informative. Your writing skill is very good, you must keep writing this type of blogs.

QuickBooks Online (QBO) Login Problems on Chrome
fix QuickBooks error 30159
QuickBooks Error 1935
How to Fix QuickBooks Enterprise Error 15107

anajuliausany said...

Thanks for sharing such an informative post.
How to Fix QuickBooks Error 404?
Most Common QuickBooks Enterprise Errors and Troubleshooting
How to Recover QuickBooks Password?
How to Fix QuickBooks Error 3371 Status Code 11118?

Florida Vacation rentals said...

Find the Best Florida Vacation Rentals By Owners

Florida Vacation Rentals
Cape Coral Vacation Rentals
Siesta Key Vacation Rentals
Wild Life ranch borne texas hill country
vacation rentals in galveston
Long beach condo
Anglers reef villa oceanfront rentals

Anonymous said...

I am fully dependent on QuickBooks, accounting software and keeping all important information of my business dealings in the software. I know that it is totally free from accounting mistakes or errors. Now, I am very frustrated by seeing QuickBooks Error code 102, when your bank’s official website has some technical issues, a server has some problems in transferring data between official website of the bank and QuickBooks online, or website maintenance is carrying on. I am unable to solve it correctly. So please someone can suggest me the quick solutions for solving this error code permanently.

edward mosan said...

Aol is an email services software that provides message sending services like you can send or receive emails and messages in a safe and secure way as AOL desktop says there message services cant be hacked plus with new features you can entertain your self on AOL desktop gold by listening music, watching news, surfing internet.

QuickBooks Help said...

QuickBooks is one of the efficient and powerful accounting software’s that is mainly used by small and mid-sized business people. It is very easy to use and download if you face any issue related to QuickBooks then dial QuickBooks Help number.
QuickBooks Online TLS Error
QuickBooks Error 6209
QuickBooks Web Connector Error 1039
QuickBooks Error Code 404
Capital One QuickBooks Error Code

accountsconfidant said...

CPA near me | BookKeeper Near Me

Wewpyou said...

I, am a WordPress engineer by calling however an author by enthusiasm. I attempt to help the WordPress people group with my online journals every way under the sun I can. My experience gives me the ability of taking a gander at an issue from the clients' perspective so I can give them the most ideal arrangement. Visit:
Wordpress Customer Service Phone Number | 24/7 WordPress Update Service |
Wordpress Website Backup Service | 24/7 Wordpress Security Service | 24/7 Wordpress Speed Optimization Services | WordPress Support Phone Number

Will Dudley said...

Qweetly.com is a place where you can have a look at various samples of academic papers. They are absolutely free and can be used to do your own assignments

QuickBooks Premier Support said...

This is an informative post.
QuickBooks Error code 6150 1006 mainly occurs when creating, opening, or using company files. When this error occurs you may see the following error message on your desktop screen.
This informative Tech blog is created for the global QuickBooks users who encounter the same error code, or else you can contact the QuickBooks Support experts for better assistance to resolve QuickBooks error 12007.

Bizz Accounting Solutions said...

I am really glad I have found this information. Recently Intuit launched QuickBooks Desktop 2020. However, the new version needs to be Install QuickBooks Desktop 2020 in the system.However, you can contact QuickBooks support team at +1-800-880-6389 in order to resolve the error with the help of QuickBooks accounting software experts.

How to Fix QuickBooks Error 404?
QuickBooks Error Code 80029c4a

Wewpyou said...

Hi, i am mia mart from usa and i'm work for wewpyou as a blogger or writer. I have experiance in writing about wordpress services, sequrity, error, plugin and much more. So you can visit: https://www.wewpyou.com/ to know more about wordpress. Visit:best wordpress analytics plugin |what is a syntax error | wordpress transfer domain | how to change wordpress theme | websites using weebly

Wewpyou said...

Are you looking for a tool that allows you to keep a track of visitors that are coming to your website, where they come from, and what are their activities? If yes then you need an analytics tool for your website. Finding one is not that difficult a task. All you have to do is make google search like ‘best wordpress analytics plugin’ and you will have a plenty of options to choose from. Visit: websites using weebly | how to change wordpress theme | wordpress transfer domain | what is a syntax error | best wordpress analytics plugin | wordpress login with google

Wewpyou said...
This comment has been removed by the author.
Wewpyou said...

Hi I am mia mart from usa, am a writer and work for wewpyou.com if u want to know about wordpress please visit: wordpress clear cache | clear wordpress cache | clear cache in wordpress | how to clear wp cache | wordpress clear cache manually

Wewpyou said...

wordpress clear cache

Wewpyou said...
This comment has been removed by the author.
Wewpyou said...

I, am a WordPress developer and blogger. I write about everything that is related to WordPress and other development platforms. My articles include error blogs to news, update to tutorials, tips & tricks blogs and much more. With my blogs I try to contribute to the WordPress community. Read more about wordpressfooter code weebly | weebly seo | weebly plugins | Custom WordPress Theme | How to Create a Custom WordPress Theme | wordpress fatal error | syntax errors in writing

nortonsetuprmt said...

I really happy found this website eventually. Really informative and inoperative, Thanks for the post and effort! Please keep sharing more such blog.





ester and christmas ornaments

parry Smith said...

I love your article so much and I appreciate your thought and views. This is really great work.

QuickBooks error code 12029
QuickBooks Error Code H202
Resolve QuickBooks Error code 1935
File Types and Extensions Used by QuickBooks Desktop

Wewpyou said...

WordPress Support Services | Wordpress Speed Optimization Service

QbEnterpriseSupport said...

The Accountant's Copy feature in QuickBooks Desktop lets accountants and clients to work on a company file at the same time.
QuickBooks accountant copy | quickbooks accountant's copy |how to create an accountant's copy in quickbooks | quickbooks accountant's copy

QbEnterpriseSupport said...

The 502 bad gateway can occur when your computer's server tries to connect to the QuickBooks server and it fails.
502 bad gateway QuickBooks |
QuickBooks Remote Access Tool |
QuickBooks database server manager |
QuickBooks pdf and print repair tool