Temperature and Humidity Sensor With LCD 1602 I2C

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

SIGN IN

Temperature and
Humidity sensor
with LCD 1602 I2C
display © GPL3+
Here I am going to display the
temperature and humidity using
the DHT11 sensor and LCD display
1602 with an I2C module and a
relevant code.

dhtsensor lcddisplay weather

19,252 VIEWS 5 COMMENTS 7 RESPECTS

COMPONENTS AND SUPPLIES $

Arduino UNO × 1 !

DHT11
Temperature & × 1 !
Humidity Sensor
(3 pins)

DFRobot I2C
16x2 Arduino × 1 !
LCD Display
Module

NECESSARY TOOLS AND


MACHINES $

Breadboard, 170 Pin !

Premium Male/Male !
Jumper Wires, 40 x 3"
(75mm)

Premium Female/Male !
Extension Jumper Wires,
40 x 6" (150mm)

APPS AND ONLINE SERVICES $

Arduino Web Editor "

ABOUT THIS PROJECT $

Now I have been struggling with this


project for like hours now. But at the
end I find out I did not have the
correct knowledge. So people it is very
important to know what you are
making. In this case I recommend you
to go through the page and not just
copy and paste the code.
Now, this project uses a DHT11
temperature and humidity sensor with
the three pin but you can also use any
other sensor the changes in the code
should be as per the model. I have
used Arduino UNO for this project.
First, make the connection of the DHT
sensor with the Arduino board.
VCC - 5.5V
DATA - PIN 4(you can also use pins 3,
4, 5, 12, 13 or 14
Pin 15 can work but DHT must be
disconnected during program upload)
GND - GND
Second, make the connection of the
LCD 1602 I2C display with the above
circuit.
LCD connections with Arduino board
VCC - 5.5V
GND - GND
SDA - A4(Analog Pin 4)
SCL - A5(Analog Pin 5)
If you are thinking what I am thinking
then the circuit will look something
like this:

Red Wires indicate the VCC wires and


the black ones indicate GND wires.
NOTE- If you see that your sensor is
rapidly getting warm(only for 4 pin
sensors) then attach a 10K pull up
resistor joining VCC and Signal ends of
the sensor.
Lastly, the code part where the real
understanding begins. So, basically I
have used two libraries one for the
sensor and the other for the LCD 1602
I2C display. Then let us start:
We first insert the DHT library the link
to download this library is given
below. So it will go something like
this.
#include"DHT.h"

Then define the sensor pin. As I have


taken the data pin to be 4. My code
will be followed as
#defineDHTPIN4

After that we need to determine the


sensor that is being used. Now, I have
used the DHT 11 sensor but if you have
a different sensor then the code will
change as per the sensor model
#defineDHTTYPEDHT11

Then using the above data


DHTdht(DHTPIN,DHTTYPE);

After interfacing with the DHT sensor


we now are going to move on to the
LCD display
#include<LiquidCrystal_I2C.h>

LiquidCrystal_I2Clcd(0x27,16,2);

So, now we are ready to start with the


void setup and loop part.
I wrote the whole code together hope
you may not find it too difficult.

void setup() {
dht.begin();// initialize the se
nsor
lcd.backlight();// turn on lcd b
acklight
lcd.init();// initialize lcd
}
void loop() {
lcd.clear();
lcd.setCursor(0,0);// set the
cursor on the first row and colum
n
lcd.print("Humidity=");
lcd.print((float)dht.readHumid
ity());//print the humidity
lcd.print("%");
lcd.setCursor(0,1);//set the c
ursor on the second row and first
column
lcd.print("Temp=");

Please note that the temperature is


automatically in the celsius scale ergo
you do not need to change any values
unless you want the answer in
Farenheit.
I strongly recommend the Arduino
Web Editor as you do not need to
download any additional libraries
since it is pre-included but if you do
not use the web editor and use the
software instead you may need to
make slight changes but the main part
remains the same.
NOTE- If you are using the software
then you do not need to download the
LiquidCrystal_I2C library as it is pre-
included in the software.
If you want to download the DHT
library then click here.
Looks like we have reached the end of
the project.
Bye guys, have fun.

CODE $

Temperature and Humidity


sensing with LCD 1602 I2C
display C/C++
% &

We are using the LCD display using the I2C


module to display the temperature and
humidity with the DHT 11 sensor.

2
1 //by Druhi Chakraborty
3 #include "DHT.h"
4 #define DHTPIN 4// you can use
5 #define DHTTYPE DHT11//#define D
6 //#define D
7 DHT dht(DHTPIN, DHTTYPE);//you c
8 // Pin 15 can work but DHT mu
9 #include <LiquidCrystal_I2C.h>
10 LiquidCrystal_I2C lcd(0x27,
11 void setup() {
12 dht.begin();// initialize the s
13 lcd.backlight();// turn on lcd
14 lcd.init();// initialize lcd
15 }
16 void loop() {
17 lcd.clear();
18 lcd.setCursor(0,0);// set the

SCHEMATICS $

Temperature and Humidity


sensing with LCD 1602 I2C display

DOWNLOAD

Please download it if required

#
temperature_and_humi
dity_sensor_vRLiYYT9rF.
fzz

COMMENTS $

Please log in or sign up to comment.

lavitz
7 months ago

Hello I like the project and pretty easy


to follow. The only problem I have
with it is that I get nan on the lcd
screen where the percentage number
and the Celsius number should be at.
It would mean alot to get some help.
Thanks.
1 thank

Druhi Chakraborty
7 months ago

So the problem is after the


names you get NAN instead of
the values?

Druhi Chakraborty
7 months ago

I'd like to know which library


are you using and did you check
your wiring maybe something is
faulty or if that doesn't work.
I'm going to give another code
to you don't worry...

oddjobber
5 months ago

If you have not managed to solve this


problem I just wanted to let you know
that I used the same code and got the
same result. No numbers in the
display but NAN.
After looking at the connections to
the sensor I realised that there are
various types.
The type I had was from a Chinese kit
of various sensors and has 3 pins like
the one used in this project. After a bit
of internet research however I found
that the connections are different on
mine to those shown in the project
notes.
Looking at the front, counting pin
connections from the left
Pin 1 data
Pin 2 Vcc
Pin 3 ground.
Having swapped these connections it
now works a treat.
Thanks to all involved.
1 thank

Druhi Chakraborty
5 months ago

Thank you for the information. I


didn't know the connections
were different to mine. I used
the sensor that comes with the
arduino kit.
I'm sorry to have caused any
trouble.

AUTHO R

Druhi Chakraborty
1 PROJECT 0 FOLLOWERS

FOLLOW

P U BL ISHED ON

January 15, 2021

' RESPECT PROJECT

( WRITE A COMMENT

) Share

M E M B ERS W HO RESPECT THI S PR OJ EC T

and 3 others

S IM IL AR PROJ E CTS Y OU MI GH T L I K E

DHT11 Humidity +
Temperature Sensor with 16x2
LCD
Projectdisplay
showcase by onatto22

53,188 VIEWS 13 COMMENTS 58 RESPECTS

Arduino DTH22 Humidity


Temperature With LCD I2C...
Project tutorial by Team GiftedMedia

76,646 VIEWS 23 COMMENTS 87 RESPECTS

Temperature Monitor with


DHT22 and I2C 16x2 LCD
Project tutorial by adrakhmat

41,635 VIEWS 18 COMMENTS 55 RESPECTS

Temperature + Humidity on
LCD
Project showcase by interpeo

38,088 VIEWS 19 COMMENTS 64 RESPECTS

Beautifully Finished Humidity


and Temperature Sensor
Project tutorial by Wicked Makers
25,997 VIEWS 23 COMMENTS
162 RESPECTS

Arduino Temperature -
Humidity - Rain Sensor
Project showcase by Mako

25,593 VIEWS 7 COMMENTS 25 RESPECTS

Powered by

You might also like