Sharifdeen Ashshak
Published

home Automation with Real time Alarm clock

In this Video I will show you Real Time clock home automation without using any RTC module such as DS3231 or DS1307.

BeginnerFull instructions provided1 hour3,252
home Automation with Real time Alarm clock

Things used in this project

Story

Read more

Schematics

circuit for LCD dispaly

circuit for relay connection

Code

Get the Code

C/C++
//for more projects visit www.blackkeyhole.com
//modified Ashshak Sharifdeen
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <NTPClient.h>
#include <TimeLib.h>
#include <LiquidCrystal.h>

const int RS = D3, EN = D4, d4 = D5, d5 = D6, d6 = D7, d7 = D8;
LiquidCrystal lcd(RS, EN, d4, d5, d6, d7);

int relay =5;
const int onhour=18;
const int onmin=18;

const int offhour=18;
const int offmin=20;

const long utcOffsetInSeconds = 19800;
 //srilankan time zone
 //+5 hr 30 Mins = 5x60x60 + 3060 = 19800

const char *ssid     = "ZTE WIFI";
const char *password = "kl2229834";

WiFiUDP ntpUDP;

 //srilankan time zone
 //+5 hr 30 Mins = 5x60x60 + 3060 = 19800

NTPClient timeClient(ntpUDP, "asia.pool.ntp.org", utcOffsetInSeconds );





void setup() {

  Serial.begin(115200);
  pinMode(relay,OUTPUT);
  digitalWrite(relay,LOW);
  lcd.begin(16,2);                 // Initialize I2C LCD module (SDA = GPIO21, SCL = GPIO22)
  lcd.setCursor(0, 0);
  lcd.print("Blackkeyhole");
  lcd.setCursor(0, 1);
  lcd.print("www.blackkeyhole.com");

  WiFi.begin(ssid, password);
  Serial.print("Connecting.");

  while ( WiFi.status() != WL_CONNECTED ) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("connected");
  timeClient.begin();
}


void loop() {

  timeClient.update();


//  Serial.print(daysOfTheWeek[timeClient.getDay()]);
  Serial.print(", ");
  Serial.print(timeClient.getHours());
  Serial.print(":");



  Serial.print(timeClient.getMinutes());
  Serial.print(":");
  Serial.println(timeClient.getSeconds());
  //Serial.println(timeClient.getFormattedTime());
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.println("Time:");
  lcd.setCursor(6, 0);
  lcd.print(timeClient.getHours());
  lcd.setCursor(8, 0);
  lcd.println(":");
  lcd.setCursor(9, 0);
  lcd.print(timeClient.getMinutes());
  lcd.setCursor(11, 0);
  lcd.println(":");
  lcd.setCursor(12, 0);
  lcd.print(timeClient.getSeconds());


  if(timeClient.getHours()==onhour && timeClient.getMinutes()==onmin)
  {
    digitalWrite(relay,HIGH);
    Serial.println("Light on");
    lcd.setCursor(0, 1);
    lcd.println("Light on");
  }
  else if(timeClient.getHours()==offhour && timeClient.getMinutes()==offmin)
  {
    digitalWrite(relay,LOW);
    Serial.println("Light off");
    lcd.setCursor(0, 1);
    lcd.println("Light off");
  }

  delay(1000);
}

Credits

Sharifdeen Ashshak
34 projects • 43 followers
Ai, IoT, embedded enthusiast

Comments