Home Automation

Enter Your Electronics & Design Project for a chance to win a $100 Shopping Cart!

Back to The Project14 homepage

Project14 Home
Monthly Themes
Monthly Theme Poll

 

1、 Introduction

Normal clock runs with internal oscillation and the alarm shall be manually set. While the basic function of smart home shall be connected with the internet and reveal more information.

This smart clock has no push buttons, all the information is got from internet. The SNTP for time synchronization,  Sensor data from thingspeak channels can all be show in LCD panel of the smart clock.

This smart clock is information hub, it fetches information and send command to home automation.

 

2. Hardware

2.1 MKR1000

2.2 LCD1602 panel

2.3 LED lights

2.4 Arduino Creator Cloud

2.5 thingspeak API for publishing data and SNTP time service

3. Program Flow Chart

Here is flow chart shows how the MKR1000 can get access to cloud services.

 

4. Codes

4.1 There have been many types of arduino IDEs, the arduino create Cloud is by far the best one, log into https://create.arduino.cc/editor/ , you can get your IDE panel and standard library without downloading from web anymore.

4.2 The debuge console and Serial Monitor shows the running mode of the program.

In this screenshot, it can be seen that the thingspeak channel is connected, but later the link is lost with http error code -301.

4.3 Here is the code.

#include <LiquidCrystal.h>
#include "ThingSpeak.h"


#include <NTPClient.h>
#include <WiFi101.h> // for WiFi 101 shield or MKR1000
#include <WiFiUdp.h>


//#include "secrets.h"
#define CH_ID_WEATHER_STATION 12397           //MathWorks weather station
#define CH_ID_COUNTER 298725 //Test channel for counting
#define READ_APIKEY_COUNTER "SODG0O2UZVGKWAWG" //API Key for Test channel


#define LEDLIGHT 1 // LED light output for D1


const char *ssid     = SECRET_SSID;
const char *password = SECRET_PASS;


WiFiUDP ntpUDP;
//NTPClient timeClient(ntpUDP);
// You can specify the time server pool and the offset (in seconds, can be
// changed later with setTimeOffset() ). Additionaly you can specify the
// update interval (in milliseconds, can be changed using setUpdateInterval() ).
NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600, 60000);


WiFiClient  client;
int keyIndex = 0;            // your network key Index number (needed only for WEP)
unsigned int temperatureFieldNumber = 4;
unsigned int counterFieldNumber = 1; 
const char * myCounterReadAPIKey = READ_APIKEY_COUNTER;
unsigned long counterChannelNumber = CH_ID_COUNTER;
unsigned long weatherStationChannelNumber = CH_ID_WEATHER_STATION;


const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int gt_day,gt_hour,gt_minute;
String gt_time;


void setup(){
  lcd.begin(16, 2);
  lcd.print("Smart Clock.");
      pinMode(LEDLIGHT, OUTPUT);
  digitalWrite(LEDLIGHT, LOW);   // turn the LED on (HIGH is the voltage level)
         
  Serial.begin(115200);


  WiFi.begin(ssid, password);


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


  timeClient.begin();
   ThingSpeak.begin(client);  // Initialize ThingSpeak
   delay(1000);
}


void loop() {
  int statusCode = 0;
  timeClient.update();


  gt_time=timeClient.getFormattedTime();
   lcd.setCursor(0, 1);
    lcd.print("Ticks:");
  lcd.setCursor(6, 1);
  lcd.print(gt_time);
  Serial.println(gt_time);
  //lcd.print(millis() / 1000);


  float temperatureInF = ThingSpeak.readFloatField(weatherStationChannelNumber, temperatureFieldNumber);  
  // Check the status of the read operation to see if it was successful
  statusCode = ThingSpeak.getLastReadStatus();
  if(statusCode == 200){
    Serial.println("Temperature at MathWorks HQ: " + String(temperatureInF) + " deg F");
    lcd.setCursor(0, 0);
    lcd.print("Temp:");
    lcd.setCursor(6, 0);
    lcd.print( String(temperatureInF) + " F");
  }
  else{
    
    Serial.println("Problem reading channel. HTTP error code " + String(statusCode)); 
  }
  if (millis() >15000){
    onAlarm();
    }
  delay(500);  
}




void onAlarm() {


   digitalWrite(LEDLIGHT, HIGH);  
}

 

5. Final build

5.1 Here is how the smart clock wiring

Then, Put it into one case and tag Smart Clock. The leds hide in one mini desklamp, left red/black wires out.

5.2 The video.

 

6. Conclusion

This is prototype Smart Clock of Home Automation . More function can be added to this smart clock for rich features.