Temp & Humidity Sensor With LCD Disp & LED Indicator





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

About: Product Designer obsessed with Science, Technology and Athletics.

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);


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 :)

4 People Made This Project!


  • Creative Misuse Contest

    Creative Misuse Contest
  • Water Contest

    Water Contest
  • Oil Contest

    Oil Contest

27 Discussions

Great project with a few challenges on the way.
I used a RGB LED and a DHT22 both work great, I will try and look at some stage saving the data to a SD card to use as a data logger.
Thanks for this cool little project :)

2018-02-04 10.45.28.jpg2018-02-04 10.45.55.jpg2018-02-04 10.46.13.jpg2018-02-04 10.56.00.jpg
1 reply

i'm trying to verify the sketch but it doesn't want it saying that "Error compiling". help me programming the sketch.?

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);

{digitalWrite(9, HIGH);

digitalWrite(7, LOW);

digitalWrite(8, LOW);

2 replies

The red High Led wil not work > = 22C wath can i do about it............

if (t<=19)


digitalWrite(7, HIGH);

digitalWrite(8, LOW);

digitalWrite(9, LOW);


else if (t>19)


digitalWrite(8, HIGH);

digitalWrite(7, LOW);

digitalWrite(9, LOW);


else if (t>=22)


Fantastic Final Project. This project was fun and challenging. I love to experiment and have something to show for it.

what do i do

M:\sketch_nov22b\sketch_nov22b.ino:3:17: fatal error: DHT.h: No such file or directory

#include "DHT.h"


compilation terminated.

exit status 1

Error compiling for board Arduino/Genuino Uno.

What is the pin layout for a 18 pin LCD

Thank you, i wanted to make this and your instructions were perfect. I wss thinking about replacing the LEDs with one RGB LED to save some space. I changed it to F from Celsius by putting
"float t = dht.readTemperature(true)" in the code instead of
"float t = dht.readTemperature()"
Then changed Print C to Print F.
I also changed the Values for the LED thresholds to correspond to using F values. I bought the Elegoo Super Starter kit on Amazon and it had everything i needed for this project. Thanks again.

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

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

1 reply

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...

3 replies

Agreed. Should always protect the LEDs!

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)

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

1 reply

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