MAKE AN LCD CLOCK THAT DISPLAYS TEMP AND HUMIDITY

If You have seen my last blog post I have shown how You can make a LCD clock using the Arduino. If not please Read the previous blog post As this is a continuation of the same. This time we will add temperature and Humidity data on the clock. Also make the Clock light up automatically when the light intensity falls below a certain level.

The parts that will be requiring to make this are:

  • Arduino Uno (actually any other arduino will do too)
  • bunch of connecting wires (multicolored)
  • breadboard (preferably small sized)
  • DS- 1302 Real time clock module
  • Serial 16×2 Character LCD
  • 9V battery (prefer using a rechargeable battery pack)
  • DHT-11 humidity and temperature sensor module
  • analog ambient light sensor module

Let us begin

The connections to the clock are the same as shown in the previous post. we shall only add a few more connections to two new parts. namely the DHT-11 temp and humidity sensor and the analog light sensor.

DHT-11 Temperature and humidity sensor

here is the pic of the sensor.dht 11 PINOUT

As you can see it has 3 pins, the Ground, Vcc and Signal

this is the component that will give us the temperature and humidity. here are the specifications:

  • Power Supply: 3.3~5.5V DC
  • Output: 4 pin single row
  • Measurement Range: Humidity 20-90%RH, Temperature 0~50℃
  • Accuracy: Humidity +-5%RH, Temperature +-2℃
  • Resolution: Humidity 1%RH, Temperature 1℃
  • Interchangeability: Fully Interchangeable
  • Long-Term Stability: <±1%RH/year

There is a higher variant of this sensor named DHT-22. It has a higher resolution and is more sensitive. but it is also costly. hence the modest DHT-11 is more practical.

Steps to install the DHT-11 library in Arduino

  • You need to download the library created by Rob Tillart for the DHT-11. You can get it from here.
  • Just click on the download zip to get the zip file.
  • Extract the zip file to the folder where you have installed Arduino software.
  • Also, cut and paste the Examples that are included to the examples folder in the Arduino folder. This should make the examples accessible through the Arduino IDE software.
  • Just check this by opening the software and clicking on the File menu and then on examples. you should find the two examples listed there.

Analog light intensity sensor

here is the light intensity sensor we will be usingANALOG LIGHT SENSOR

As you can see it also has three pins. Ground, Vcc and Signal

Sensors are basically of two types, Analog and digital. Analog sensors give a output voltage proportional to the input. here the light sensor gives a signal corresponding to the light intensity. the arduino scales the input it has received on a scale of 0-1023. digital sensors on the other hand give a high signal when the input has crossed a certain threshold.

Analog sensor output should be connected to the pins labelled as A0,A1,…etc on the arduino. digital sensors output should be connected to the pins on the opposite side labelled as 1,2,3…etc

we shall make the LCD light up if the light intensity falls below a certain level.

void light()
{
  int light_intensity = analogRead(A0);
  if (light_intensity > 800)
  {
    Serial.write(17);//backlight on
  }
  else
  {
    Serial.write(18);//backlight off
  }
  delay(10);
}

 

Above is the snippet of code that lights up the LCD if the light intensity is below a certain level. as you can see currently the level set is 800. you can change the set level if you want to

Warning the light sensor gives an output inversely proportional to the ambient light. i.e. if there is more light the output will be of a lower value. if there is less amount of light the output will be of a higher value

The Final Part

lets finish the build

  • Open the Arduino IDE software on your computer
  • Connect the Arduino
  • Upload the following code to the Arduino
//29/12/15

#include <virtuabotixRTC.h>
#include <dht.h>
dht DHT;

#define DHT11_PIN 5
virtuabotixRTC myRTC(6, 7, 8);
int day,year,hours,minutes,seconds, month,temperature,humidity;
int buzzer_pin = 9;

//myRTC.setDS1302Time(00, 59, 23, 6, 10, 1, 2014); //use to set time again

void setup() 
{ 
 Serial.begin(9600);
 pinMode(buzzer_pin,OUTPUT);
 init_lcd();
}

void loop()
{ 
 clock();
 lcd_write();
 light();
}

void init_lcd()
{
 int backlight_on = 17;
 int backlight_off = 18;
 int line_feed = 10;
 int clear_disp = 12; //clears screen; provide 5ms delay
 delay(5020);
 
 Serial.write(22);
 delay(10);
 Serial.write(12);
 delay(500);
 Serial.write(18);
 delay(50);
 
 Serial.write(250); //humidity chr 3
 Serial.write(4); //00100
 Serial.write(4); //00100
 Serial.write(14); //01110
 Serial.write(14); //01110
 Serial.write(31); //11111
 Serial.write(31); //11111
 Serial.write(14); //01110
 Serial.write(4); //00100
 delay(500);

 Serial.write(251); //temp degess celc chr 4
 Serial.write(0); //00000
 Serial.write(19); //10011
 Serial.write(4); //00100
 Serial.write(4); //00100
 Serial.write(4); //00100
 Serial.write(4); //00100
 Serial.write(3); //00011
 Serial.write(0); //00000
 delay(500);
 
 Serial.write(150);
 Serial.print("%");
 Serial.write(2);
 
 Serial.write(130);
 Serial.write(3);
 
 Serial.write(155);
 Serial.print(':');
 
 Serial.write(158);
 Serial.print(':');
 
 temp_humidity();
} 

void clock()
{
 myRTC.updateTime(); 
}

void lcd_write()
{
 if( myRTC.dayofmonth != day)
 {
 Serial.write(132);
 if (myRTC.dayofmonth<10)
 {
 Serial.print(0);
 }
 Serial.print(myRTC.dayofmonth);
 day = myRTC.dayofmonth;
 }
 if (myRTC.month != month)
 {
 Serial.write(135);
 if (myRTC.month<10)
 {
 Serial.print(0);
 }
 Serial.print(myRTC.month);
 month = myRTC.month;
 }
 if (myRTC.year != year)
 { 
 Serial.write(138);
 Serial.print(myRTC.year);
 year = myRTC.year;
 }
 if (myRTC.hours != hours)
 { 
 Serial.write(153);
 if (myRTC.hours<10)
 {
 Serial.print(0);
 }
 Serial.print(myRTC.hours);
 hours = myRTC.hours;
 }
 if (myRTC.minutes != minutes)
 {
 Serial.write(156);
 if (myRTC.minutes<10)
 { 
 Serial.print(0);
 }
 Serial.print(myRTC.minutes);
 minutes = myRTC.minutes;
 }
 if (myRTC.seconds != seconds)
 {
 Serial.write(159);
 if (myRTC.seconds<10)
 {
 if(myRTC.seconds == 0)
 {
 temp_humidity();
 Serial.write(159);
 } 
 Serial.print(0);
 }
 Serial.print(myRTC.seconds);
 seconds = myRTC.seconds;
 }
 delay(100);
}

void light()
{
 int light_intensity = analogRead(A0);
 if (light_intensity > 800)
 {
 Serial.write(17);//backlight on
 }
 else
 {
 Serial.write(18);//backlight off
 }
 delay(10);
}

void temp_humidity()
{
 int chk = DHT.read11(DHT11_PIN);
 Serial.write(128);
 temperature = DHT.temperature;
 Serial.print(temperature);

 Serial.write(148);
 humidity = DHT.humidity;
 Serial.print(humidity);

 delay(10);
}
  • After the program is done uploading Disconnect the Arduino
  • Connect all the parts as per the circuit diagram below

DHT 11 connections

 

  • Wait for a few second for the clock to print its data

Here is a pic of how the clock should look likeIMG_20151229_164356304

Also now the LCD lights up in the darkIMG_20151225_235036281

Will post new content next week. Please feel free to like,Share and comment if you will.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s