Arduino

Arduino Tutorial #23 How to make Arduino Real Time Clock with Real Time Temperature.

Arduino Real Time Clock with Real Time Temperature

In this tutorial we will see how to make Arduino real time clock and it will also show real time temperature on LCD display. So let’s get started. For this you will need

  1. Arduino,
  2. Real time clock (DS1302),
  3. DHT22 sensor,
  4. LCD,
  5. Potentiometer,
  6. Jumper wires,
  7. Breadboard,
  8. And Resistors.

 

Circuit diagram for Real time clock with LCD
Circuit diagram for Real time clock with LCD

Do connection as shown in diagram. You can use I2C serial interface adapter to reduce wires in LCD. And make sure DHT sensor connected this 5V line before the real time clock otherwise it will not work.

 

Sketch for DS 1302 RTC with LCD
#include "DHT.h"
#define DHTPIN 10
#define DHTTYPE DHT22 
DHT dht(DHTPIN, DHTTYPE); 
#include <LiquidCrystal.h>
#include <DS1302.h>

// Init the DS1302
DS1302 rtc(2, 3, 4);

// Init the LCD
LiquidCrystal lcd(12, 11, 8, 7, 6, 5);

void setup()
{
 // Set the clock to run-mode, and disable the write protection
 rtc.halt(false);
 rtc.writeProtect(false);
 dht.begin();
 
 // Setup LCD to 16x2 characters
 lcd.begin(16, 2);

// The following lines can be commented out to use the values already stored in the DS1302
 rtc.setDOW(MONDAY); // Set Day-of-Week to FRIDAY
 rtc.setTime(12, 11, 0); // Set the time to 12:00:00 (24hr format)
 rtc.setDate(30, 10, 2017); // Set the date to August 6th, 2010
}

void loop()
{
 // Display time on the left conrner upper line
 lcd.setCursor(0, 0);
 lcd.print(rtc.getTimeStr());
 
 // Display abbreviated Day-of-Week in the lower left corner
 lcd.setCursor(0, 1);
 lcd.print(rtc.getDOWStr(FORMAT_SHORT));
 
 // Display date in the lower right corner
 lcd.setCursor(6, 1);
 lcd.print(rtc.getDateStr());
 float t = dht.readTemperature();
 // Display tempreture right side corner on the upper line 
 lcd.setCursor(9, 0);
 lcd.print(t);
 lcd.print("*C");

// Wait one second before repeating 
 delay (1000);
}

Now in programming part include DHT, real time clock and liquid crystal library. Download DHT sensor library and real time clock (DS 1302) library. If you are interested in to little bit more about DHT sensor you can check measure temperature and humidity with Arduino. Define DHT pin number and DHT type. Initialize real time clock library and LCD library. In setup function change the Day, Time, and Date to current time. In loop function it will print the day, time, date and temperature to set cursor. After changing date, time upload the sketch you can see it is showing current time but when we unplug the power and re-plug it. It is starting from where we set the clock. But we don’t want to set clock for every time.

 

 // The following lines can be commented out to use the values already stored in the DS1302
 rtc.setDOW(MONDAY); // Set Day-of-Week to FRIDAY
 rtc.setTime(12, 11, 0); // Set the time to 12:00:00 (24hr format)
 rtc.setDate(30, 10, 2017); // Set the date to August 6th, 2010

 

So we need to comment out this lines. This will set clock to run mode. And now you can see when I unplug the power and re-plug it. It is showing exact time. It is not starting over again where we have set it. Because when it was not powered it was running on battery. Even when I press reset button it is not affecting the clock. Now you can see real time clock and real time temperature on LCD display.

Remember this two step

  1. update time and upload sketch.
  2. then comment out the lines and  again upload sketch.

In next tutorial I will make video on Arduino alarm clock. Subscribe my Youtube channel to get latest update.

 

LIST OF COMPONENT BUY ONLINE:

http://amzn.to/2fvSRJq   (Arduino)

http://amzn.to/2gRFSiv (RTC DS1302)

http://amzn.to/2yBk7eT (LCD display)

http://amzn.to/2vqIKJP  (DHT22)

http://amzn.to/2vYitnO (Potentiometer)

http://amzn.to/2vmSK8l  (Resistor)

http://amzn.to/2wxPmWz  (Breadboard)

http://amzn.to/2vJ3lvo   (Jumper wire)

TILL THEN KEEP LEARNING KEEP MAKING 🙂

One thought on “Arduino Tutorial #23 How to make Arduino Real Time Clock with Real Time Temperature.

Leave a Reply

Your email address will not be published. Required fields are marked *