Introduction: Temp & Humidity Sensor With LCD Disp & LED Indicator

In this instructable, I have used the DHT11 Temperature & Humidity sensor & Arduino UNO to display the current temperature & humidity readings into a 16 x 2 LCD Display. Alongside, I have also created a 3-LED setup which indicates 3 sets of temperature readings (cold, hot, extreme).

The DHT11 is a digital sensor that lets you easily get relative humidity and temperature readings in your projects. Because of their low cost and small size, DHT11 sensors are perfect for lots of different DIY electronics projects. Some projects where the DHT11 would be useful include remote weather stations, home environment control systems, and agricultural/garden monitoring systems.

DHT11 Technical Specifications :

  • Humidity Range: 20-90% RH
  • Humidity Accuracy: ±5% RH
  • Temperature Range: 0-50 °C
  • Temperature Accuracy: ±2% °C
  • Operating Voltage: 3V to 5.5V

Next, I will be describing step-wise with relevant images, how to hook up the 16 x 2 LCD Display to the Arduino, the relative connections of the DHT11 sensor & the 3-LED setup.

Step 1: Stuffs You Will Need for This Project

  1. Breadboard
  2. 16 X 2 LCD Display
  3. Jumper wires
  4. Arduino UNO Board & Arduino IDE installed on your computer
  5. 3-LEDs (of 3 different colors)
  6. Mini Breadboard (not necessary)
  7. DHT11 Temp & Humidity Sensor

That's all you need to get started . . .

Step 2: Setting Up the Connections With the Arduino

The connection part is the most important part of the whole project. Make sure you follow the directions properly or else you might end up destroying the sensor directly. The image above (and in Step 3 below) shows the connections of the setup in the breadboard in a clean way. Deep-Blue wires correspond to the 5V connection & Black wires correspond to the Ground connection

1. The 16 x 2 LCD Display consists of 16 pins which are labelled with different names, written on the back of the display module. Make sure you follow the pin numbers correctly.

2. To know the pins of the DHT11 sensor, refer to the wiring diagram above.

In case, the wiring diagram feels a bit too complex, here is the connection setup list pin wise :

  • Arduino GND to breadboard Negative power rail (All black wires goes to this rail)
  • Arduino 5V to breadboard Positive power rail (All deep-blue wires goes to this rail)
  • DHT11 Positive pin to breadboard positive power rail
  • DHT11 Negative pin to breadboard negative power rail
  • DHT11 Signal pin to Arduino Analog A0 (this feeds data from DHT11 to Arduino)
  • LCD 1 to breadboard Negative power rail
  • LCD 2 to breadboard Positive power rail
  • LCD 3 to breadboard Negative power rail (if you connect this to a potentiometer, this helps to change the LCD brightness)
  • LCD 4 to Arduino Digital Pin 12 (LCD character coordinates)
  • LCD 5 to breadboard Negative power rail
  • LCD 6 to Arduino Digital Pin 11 (LCD initiate command)
  • LCD 11 to Arduino Digital Pin 5
  • LCD 12 to Arduino Digital Pin 4
  • LCD 13 to Arduino Digital Pin 3
  • LCD 14 to Arduino Digital Pin 2
  • LCD 15 to breadboard Positive power rail
  • LCD 16 to breadboard Negative power rail
  • Cold/Green LED Positive Pin to Arduino Digital Pin 7 (negative pin to breadboard negative rail)

  • Hot/Yellow LED Positive Pin to Arduino Digital Pin 8 (negative pin to breadboard negative rail)

  • Extreme/Red LED Positive Pin to Arduino Digital Pin 9 (negative pin to breadboard negative rail)

If you have made the connections properly, you are almost half-way through the project since the rest steps are easy to follow with.

Step 3: What Your Setup Will Probably Look Like

I have uploaded few images above to see how each connections look like. Since this is a complex circuit, I have tried my best to keep wiring connections as simple as possible. Hope this might help you at some stage.

Next before moving on the coding part, what we need are two Arduino Libraries for our LCD Display & DHT11 sensors to work properly. I have had a tough time finding the correct library for the DHT11 sensor because most of them were outdated. However, the LCD Display library is inbuilt within the Arduino IDE.

Nevertheless, I have attached the two library files. If you don't know how to install an Arduino Library inside the IDE, it's quite easy : Open Arduino IDE --> Sketch --> Include Library --> Add Library and select the .zip files.

Step 4: The Sketch (a.k.a Arduino Code)

This is the code, you will have to compile & upload to your Arduino UNO board. If you have made all the connections & library installation exactly as described, the code compilation should probably produce no errors.

#include <LiquidCrystal.h>
#include <DHT.h>

#include "DHT.h"

#define DHTPIN A0 // what pin we're connected to

#define DHTTYPE DHT11 // we are using the DHT11 sensor

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

DHT dht(DHTPIN, DHTTYPE);

void setup() { Serial.begin(9600); for (int DigitalPin = 7; DigitalPin <= 9; DigitalPin++) { pinMode(DigitalPin, OUTPUT); } lcd.begin(16,2); //16 by 2 character display dht.begin(); } void loop() { delay(1000); // Reading temperature or humidity takes about 250 milliseconds! float h = dht.readHumidity(); float t = dht.readTemperature(); // Read temperature as Celsius (the default)

lcd.clear(); lcd.setCursor(0,0); lcd.print("Temp: "); lcd.print(t); //printing temperarture to the LCD display

lcd.print("'C"); lcd.setCursor(0,1); lcd.print("Humid: "); lcd.print(h); //printing humidity to the LCD display lcd.print("%");

//the 3-led setup process if (t<=22) { digitalWrite(7, HIGH); digitalWrite(8, LOW); digitalWrite(9, LOW); } else if (t>22) { digitalWrite(8, HIGH); digitalWrite(7, LOW); digitalWrite(9, LOW); } else if (t>=35) { digitalWrite(9, HIGH); digitalWrite(7, LOW); digitalWrite(8, LOW); } }

Step 5: Describing the Setup Overall

After the code/sketch has been successfully compiled & uploaded to the Arduino, you will see the current temperature & humidity of your surroundings. The sensor basically refreshes every 1 second to update you with the accurate temperature. Alongside this, you will notice any one of the LED being lit, depending upon your surroundings.

3-LED setup has been initiated with the following :

  • If the temperature is below 22℃, the Cold LED will glow. (Green)
  • If the temperature is between 22 - 35℃, the Hot LED will glow. (Yellow)
  • If the temperature is above 35℃, the Extreme LED will glow. (Red)

One can obviously modify the readings in the code as per your choice.

I have uploaded two images above with the normal temperature of our area 31 ℃ (with the Yellow/Hot LED being lit). I then, put the sensor near an Ice cube to drop the temperature below 22℃ (to make the Green/Cold LED lit up).

You can see the video attached, where i have shown the temperature change from 19℃ to 24℃ and the corresponding change in LED indicators.
P.S :
Sorry, I could not rise up to the temperature of 35℃ (to show the Red LED glow), but it will definitely work like the other two LEDs.


That't it !
Thanks a lot for following this. Hope I can upload a few more projects soon.

Incase you face any queries, feel free to ask in the comments :)

Comments

author
emrude made it! (author)2017-07-03

Very nice. Is there an easy way to display Fahrenheit?

Temp_Humidity.jpg
author
SzabolcsM2 (author)2016-10-11

if (t<=22)

{
digitalWrite(7, HIGH);

digitalWrite(8, LOW);

digitalWrite(9, LOW);
}

else if (t<35)

{
digitalWrite(8, HIGH);

digitalWrite(7, LOW);

digitalWrite(9, LOW);
}

else
{digitalWrite(9, HIGH);

digitalWrite(7, LOW);

digitalWrite(8, LOW);
}

author
SzabolcsM2 (author)2016-10-11

HI! I think this code is wrong and Red Led will not work..

author
Siopao_0623 (author)2016-08-16

Sir, "error compiling for board....." what should I do. Thanks.

author
PeterD196 (author)Siopao_06232016-09-11

Yes, same here. Void loop error

author
abbabba (author)2016-06-04

Hi Rahul, nice project. I do have some comments to make. Please do not take it personally, as this is for the benefit of those who would like to recreate your device. For the start when you specify temperature accuracy in your specifications, do not put degrees Celsius after the % sign. You either say ± 2 °C, or ± 2 %, but not both. Now to the LCD. You can create your own characters with these displays (I think up 4 off, check the data sheet) so you can make degrees symbol instead of apostrophe. OK and last comment, probably the most important. The use of LEDs without series resistors will most definitely damage your ports on the microcontroller eventualy. Use one resistor around 470 Ω to 1kΩ in series with each LED. Good luck and keep at it. It's fun...

author
PeterD196 (author)abbabba2016-09-11

Agreed. Should always protect the LEDs!

author
HckmstrRahul (author)abbabba2016-06-12

Thanks a lot :) I will keep those in mind. I am a newbie to the LCD,and could u please share the procedure to print a degree symbol? I could not find any relevant hex code for that (it didnt show up in the LCD, so i went for apostrophe sign)

author
abbabba (author)HckmstrRahul2016-06-15

Hi Raul. The instructions how to make custom characters are in the LCD data sheets. If you do not have the data sheet at hand, google "how to create custom characters on 16x2 lcd" . Here is one of them to get you started: https://www.arduino.cc/en/Reference/LiquidCrystalCreateChar
Good luck. abbabba

author
Luchtkwast made it! (author)2016-06-27

Very fun project. Thanks for sharing.

temp_1390194605.jpg
author
HckmstrRahul (author)Luchtkwast2016-08-03

Thank you so much! Glad!!

author
Steamworx (author)2016-06-26

Dht22 is more precise. I have made a bit different clock/thermometer based on it.

IMG_20160620_211751.jpgIMG_20160620_211745.jpg
author
HckmstrRahul (author)Steamworx2016-08-03

Wow :) Keep it up buddy!

author
metejnik (author)2016-06-01

How to connect it if i have IIC/I2C for lcd and what part of code to change. Thanks in advance!

author
HckmstrRahul (author)metejnik2016-06-01

This might help you :
https://arduino-info.wikispaces.com/LCD-Blue-I2C

author
SaptarshiB5 (author)2016-05-28

great job bro !!! keep up the good job !!! :D

author
HckmstrRahul (author)SaptarshiB52016-05-28

Thanks ! :)

author
artmez (author)2016-05-27

Nice. Here is a suggestion: Add a blue LED and use that for cool. Then green can be "perfect", and yellow warm. Not if it's too cold/hot, then flash red with the blue/yellow to signify they're out of range. You won't even need the LCD except for humidity (or humidity can be incorporated into the comfort "equation" too).

author
HckmstrRahul (author)artmez2016-05-27

Thanks for your ideas. Even I thought of doing so. But the blue LED i had was infact way more brighter than all the rest. I had to switch to Green/Yellow/Red setup :D

author
KNEXnCoding (author)2016-05-26

This is cool! You should use Xbee radios to send this data wirelessly.That would be sick.

I have to try this myself, I'll let you know when I get the parts and build it!

author
HckmstrRahul (author)KNEXnCoding2016-05-26

Hey that would be awesome. Do upload the project.

About This Instructable

9,874views

142favorites

Bio: Product Designer obsessed with Science, Technology and Athletics.
More by HckmstrRahul:Temp & Humidity Sensor with LCD Disp & LED IndicatorSeven Segment Display using LEDs
Add instructable to: