Thursday, December 1, 2022
Home Arduino How to use DHT 11 Sensor in Arduino

How to use DHT 11 Sensor in Arduino

Good day, Today, we will talk about how to use a DHT 11 sensor.

DHT 11 is a module used to measure Temperature and Humidity. By this, values ​​can be obtained as analog.

First, let’s see what we need for this.

  1. An Uno board.
  2. A DHT 11 Sensor.
  3. Jumper Wires.
DHT 11 Sensor

Now set up the circuit as below


Now let’s explain the code.

First, we need to install the library called DHT.h for this. For that, go to Sketch-> Include Library -> Manage Library, search for DHT 11, and download and install it.


Now include that library at the top of the code.

#include <DHT.h>

Then we are using the DHT 11 sensor, so it should be defined as a type.

define DHTTYPE DHT11

Now we need to define the analog pin to be used.

define dht_apin A0

Now we create an object called DHT from the class called DHT. For that, we have to give the pin and the type used as parameters.

Now let’s see the process in void setup().

Here, the code to open the serial monitor and the code to turn ON our sensor is written in this way. There we give a little delay to give time for the sensor to turn ON correctly before taking the values.

void setup() {

Now let’s see the process in the void loop().

There we have called the function called readHumidity() through the DHT object created at the top. That gives us the required Humidity value. It can be seen as a percentage.

And when we call the readTemperature() function of the same object, we can get the corresponding temperature in Celsius.

void loop() {
Serial.print("Current humidity = ");
Serial.print("% ");
Serial.print("temperature = ");
Serial.println("C ");


So, guys, we say goodbye for today. I will come back with another article like this. Don’t forget to comment your suggestions and shortcomings. good day


1 Comment

Leave a reply

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments

Kaushi ki on Arduino IDE Lesson 02
Osiru Domnic on Identify Arduino Component