Hello every one , welcome back . In this new arduino tutorial series I’m gonna show you how to control every thing in your home on time basis . After doing this project you will be able to control your home appiliences like TV , Radio,Fan, and other thing on time basis . Let’s say you want to switch on TV exactly on 8 ‘O clock morning and fan on 12 PM and so on ,, This is on going series and will be updated if something new application is added on this project .
The concept of this project is very simple , DS1307 Real Time Clock sends Time,Date,and Day to the Arduino microcontroller , and according to the time set on code we can switch on relay to turn on LAMP,FAN etc .
Brief Introduction of DS1307
The DS1307 serial real-time clock (RTC) is a low-power, full binary-coded decimal (BCD) clock/calendar plus 56 bytes of NV SRAM. Address and data are transferred serially through an I²C, bidirectional bus. The clock/calendar provides seconds, minutes, hours, day, date, month, and year information. The end of the month date is automatically adjusted for months with fewer than 31 days, including corrections for leap year. The clock operates in either the 24-hour or 12-hour format with AM/PM indicator. The DS1307 has a built-in power-sense circuit that detects power failures and automatically switches to the backup supply. Timekeeping operation continues while the part operates from the backup supply. DS1307: Typical Operating Circuit DS1307: Typical Operating Circuit Enlarge+
Key Features
- Completely Manages All Timekeeping Functions
- Real-Time Clock Counts Seconds, Minutes, Hours, Date ofthe Month, Month, Day of the Week, and Year with Leap-Year Compensation Valid Up to 2100 A.D.
- 56-Byte, Battery-Backed, General-Purpose RAM with Unlimited Writes
- Programmable Square-Wave Output Signal
- Simple Serial Port Interfaces to Most Microcontrollers
- I2C Serial Interface
- Low Power Operation Extends Battery Backup Run Time
- Consumes Less than 500nA in Battery-Backup Mode with Oscillator Running
- Automatic Power-Fail Detect and Switch Circuitry
- 8-Pin DIP and 8-Pin SO Minimizes Required Space
- Optional Industrial Temperature Range: -40°C to +85°C Supports Operation in a Wide Range of Applications
Underwriters Laboratories® (UL) Recognized
note:crystal used in this project is 32.768Hz since it provide exact time to operate it on real time
you can buy this chip from this link
In the next part we will show you how to adjust time with push button . For now we are just setting time on code and everything will be control as exactly set on code . You can download complete project file with code , and proteus7simulation file from this link download project RTC home . And short description of the code and project is shown below the code .
Real Time Home Automation Using Arduino Uno R3 and DS1307 RTC (Part-1) Code
//created by prasant
//all right reserved to electronify.org
//you can copy edit or do what ever with this code
#include
#include "RTClib.h"
#include
LiquidCrystal lcd(12, 13, 8, 9, 10, 11);
RTC_DS1307 RTC;
void setup () {
Wire.begin();
RTC.begin();
lcd.begin(20, 4);
pinMode(7,OUTPUT);
pinMode(6,OUTPUT);
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
}
void loop () {
DateTime now = RTC.now();
lcd.setCursor(0, 0);
lcd.print(now.day(), DEC);
lcd.print('/');
lcd.print(now.month(), DEC);
lcd.print('/');
lcd.print(now.year(), DEC);
lcd.print(' ');
lcd.setCursor(0, 1);
if (now.hour()<10)
lcd.print('0');
lcd.print(now.hour(), DEC);
lcd.print(':');
if (now.minute()<10)
lcd.print('0');
lcd.print(now.minute(), DEC);
lcd.print(':');
if (now.second()<10) lcd.print('0'); lcd.print(now.second(), DEC); if ( ( now.hour() == 12 ) && ( now.minute() == 20 ) ) { digitalWrite(7,HIGH); lcd.setCursor(0, 2); lcd.print("TM:12:20 MOTOR IS ON"); } else { digitalWrite(7,LOW); lcd.setCursor(0, 2); lcd.print("MOTOR TM 12:20-12:21"); } if ( ( now.hour() == 12 ) && ( now.minute() > 20 )&& ( now.minute() <= 25 ) )
{
digitalWrite(6,HIGH);
lcd.setCursor(0, 3);
lcd.print("TM :12:20 LAMP IS ON");
}
else
{
digitalWrite(6,LOW);
lcd.setCursor(0, 3);
lcd.print("LAMP TM 12:20-12:25");
}
delay(50);
}
Real Time Home Automation Using Arduino Uno R3 and DS1307 RTC (Part-1) Schematic Diagram
Short Description
Yeah! the code is very simple to understand ,because it’s arduino code . Arduino code generally have lot’s of ready made library ,so its easy to use them provided with their documentation and without these library programming is very complex. So let’s talk about the code .First we have included RTClib and Wire library . You can download these two library from this link real time home automation library . Wire library is used for TWI interface , and RTClib library is used to receive real time data from the real time clock chip . ( if you want to learn about TWI or I2C feature of AVR chip go to this link and more information like register etc about real time clock in this link . )
After including the libraries what I have did is initialize LCD and also pinMode for relays output . Then after inside never ending loop we get time using structure we have created now . Using now.day() function we get day value , using now.year() we get year value , and now.hour() we get hour value and so on ,, and coverted these different value with appropriate representation and then displayed on LCD .
To make automatic switch we have defined value of time (hour, minute , second ) on the if statement and if time reached that point Arduino automatically send HIGH on that perticular pin . That’s it .
If you did not understand what i exactly mean , please leave a comment below , i will try to solve your question . keep learning and if you found this information useful please share this on your time line .