LAMP TIMER WITH RTC

lamp timer rtc

#include <Wire.h>

#include “RTClib.h”

RTC_DS1307 RTC;

int led1 = 5;

void setup () {

pinMode(led1, OUTPUT);

Serial.begin(9600);

Wire.begin();

RTC.begin();

if (! RTC.isrunning()) {

Serial.println(“RTC is NOT running!”);

// following line sets the RTC to the date & time this sketch was compiled

RTC.adjust(DateTime(__DATE__, __TIME__));

}

}

void loop () {

DateTime now = RTC.now();

Serial.print(now.hour(), DEC);

Serial.print(‘:’);

Serial.print(now.minute(), DEC);

Serial.print(‘:’);

Serial.print(now.second(), DEC);

Serial.println();

if(now.hour() >= 19 || now.hour() < 7){

digitalWrite(led1, HIGH);

}

if(now.hour() >= 7 && now.hour() < 19){

digitalWrite(led1,LOW);

}

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s