element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • More
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • More
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • More
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • More
  • Store
    Store
    • Visit Your Store
    • Choose Another Store
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
Home Automation
  • Challenges & Projects
  • Project14
  • Home Automation
  • More
  • Cancel
Home Automation
Blog Smart Clock over Cloud
  • Blog
  • Forum
  • Documents
  • Events
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Home Automation requires membership for participation - click to join
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: fyaocn
  • Date Created: 13 Mar 2019 4:19 AM Date Created
  • Views 346 views
  • Likes 11 likes
  • Comments 5 comments
  • homeautomationch
  • arduino_iot_cloud
  • mkr_1000
  • p14 mkr 1000
  • iotcloudch
Related
Recommended

Smart Clock over Cloud

fyaocn
fyaocn
13 Mar 2019

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.

You don't have permission to edit metadata of this video.
Edit media
x
Upload Preview

 

6. Conclusion

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

Anonymous
  • aspork42
    aspork42 over 3 years ago

    Nice job! I love it!

    • Cancel
    • Up 0 Down
    • Reply
    • More
    • Cancel
  • fyaocn
    fyaocn over 3 years ago in reply to DAB

    To make it simple,

    - GPS clock have got time SIGNAL from satelite and decode the TIME mark and flytime of signal.

    - SNTP can be understand as, the local time = standard server time + NETWORK latency /2 .Obviously, the network latency is not stable.

    Therefore, SNTP is good enough for home automation but not good enough for industrial purpose.

    Of course, both are more complex.

    It is amazing that Arduino can do SNTP job so easy.

    MKR1xxx would be perfect arduino board for beginners and professionals.

     

    But there is still issues you shall take notice of. Many Cloud IoT include WiFi control. Your shall read the source code carefully, or the sketch will not work. I work hard trying to bind the SNTP, Arduino Cloud, thingspeak IoT, and pubnub together.

    • Cancel
    • Up 0 Down
    • Reply
    • More
    • Cancel
  • jw0752
    jw0752 over 3 years ago

    Excellent project, Thanks for sharing it.

     

    John

    • Cancel
    • Up 0 Down
    • Reply
    • More
    • Cancel
  • fyaocn
    fyaocn over 3 years ago in reply to DAB

    SNTP is special time server protocle used in many WEB site.

    GPS is better but costly, need special GPS receiver and decoder.

    • Cancel
    • Up 0 Down
    • Reply
    • More
    • Cancel
  • DAB
    DAB over 3 years ago

    Nice project.

     

    How does the timing reliability compare to using a GPS clock?

     

    DAB

    • Cancel
    • Up 0 Down
    • Reply
    • More
    • Cancel
Element14

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2022 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • Facebook
  • Twitter
  • linkedin
  • YouTube