💬 Real Time Clock Module, LCD Display and Controller Time

  • Admin

    This thread contains comments for the article "Real Time Clock Module, LCD Display and Controller Time" posted on MySensors.org.

  • Thank you for this nice write up.

    I have some "low power" questions:

    • Will the RTC continue to work when the Arduino is set to Sleep?
    • Is there a way to save battery and wake up the Arduino using the RTC?
    • What is the power consumption of a get time request?
    • What is the autonomy of the RTC?

  • Admin

    Yes, the RTC will continue to function while the Arduino is sleeping.

    On the DS3232RTC you can set alarm (which triggers the INT pin of the module). See more info here:

  • I was modify code to Present temp to controller .

     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     * Version 1.0 - Henrik Ekblad
     * Example sketch showing how to request time from controller which is stored in RTC module
     * The time and temperature (DS3231/DS3232) is shown on an attached Crystal LCD display
     * Wiring (radio wiring on www.mysensors.org)
     * ------------------------------------
     * Arduino   RTC-Module     I2C Display 
     * ------------------------------------
     * GND       GND            GND
     * +5V       VCC            VCC
     * A4        SDA            SDA
     * A5        SCL            SCL
     * http://www.mysensors.org/build/display
    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    #include <SPI.h>
    #include <MySensors.h>  
    #include <TimeLib.h> 
    #include <DS3232RTC.h>  // A  DS3231/DS3232 library
    #include <Wire.h>
    #include <LiquidCrystal_I2C.h>
    //#include <LCD_1602_RUS.h>
    bool timeReceived = false;
    unsigned long lastUpdate=0, lastRequest=0;
    int numSensors=0;
    #define CHILD_ID_TEMP 15
    #define COMPARE_TEMP 1                            // Send temperature only if changed? 1 = Yes 0 = No
    MyMessage msg(0,V_TEMP);
    float lastTemperature;
    // Initialize display. Google the correct settings for your display. 
    // The follwoing setting should work for the recommended display in the MySensors "shop".
    LiquidCrystal_I2C lcd(0x3F, 16, 2);
    //LCD_1602_RUS lcd(0x3F, 16, 2);
    void setup()  
      // the function to get the time from the RTC
      // Request latest time from controller at startup
      // initialize the lcd for 16 chars 2 lines and turn on backlight
      lcd.init();                    // Инициализируем экран
      lcd.backlight();               //включаем подсветку
    void presentation()  {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("RTC Clock + Temp", "1.1.1");
      present(0, S_TEMP); 
      numSensors = 1 ;
    // This is called when a new time value was received
    void receiveTime(unsigned long controllerTime) {
      // Ok, set incoming time 
      Serial.print("Time value received: ");
      RTC.set(controllerTime); // this sets the RTC to the time from controller - which we do want periodically
      timeReceived = true;
    void loop()     
      unsigned long now = millis();
      // If no time has been received yet, request it every 10 second from controller
      // When time has been received, request update every hour
      if ((!timeReceived && (now-lastRequest) > (10UL*1000UL))
        || (timeReceived && (now-lastRequest) > (60UL*1000UL*60UL))) {
        // Request time from controller. 
        Serial.println("requesting time");
        lastRequest = now;
      // Update display every second
      if (now-lastUpdate > 1000) {
        lastUpdate = now;
    void updateDisplay(){
      tmElements_t tm;
      // Print date and time 
      lcd.print(" ");
    //  lcd.print(":");
    //  printDigits(tm.Second);
      // Go to next line and print temperature
      lcd.setCursor ( 0, 1 );  
      lcd.print("Temp: ");
      lcd.write(223); // Degree-sign
      float temperature = (RTC.temperature()/4);
      #if COMPARE_TEMP == 1
        if (lastTemperature != temperature && temperature != -127.00 && temperature != 85.00) {
        if (temperature != -127.00 && temperature != 85.00) {
          // Send in the new temperature
          send(msg.setSensor(0).set(temperature, 1));
          // Save new temperatures for next compare
    void printDigits(int digits){
      if(digits < 10)

  • @cadet
    Hi all

    Can I display Temp from other sensor ?

    Thank you

  • Hi, I wanted to know if it was possible to create a node in each room with a temperature sensor and display and send it all to the controller

  • Mod

    @cadet sure you can, in the send() function you can specify a destination ID of the node with the display

    @exagon_46 of course is possible, just add some code to display the temperature (use the examples of the LiquidCrystal_I2C library as reference)

Log in to reply

Suggested Topics

Looks like your connection to MySensors Forum was lost, please wait while we try to reconnect.