How to Code DHT11 Temperature and Humidity Sensor?

How to Code DHT11 Temperature and Humidity Sensor?

DHT11 Sensor is Capable of sensing Temperature and Humidity. It is widely used to develop Arduino projects.

Using DHT11 we could make Weather Stations like Projects using Arduino and DHT11 Sensor.

Figure: DHT11 Sensor

DHT11 has 4 Pins where First Pin is VCC, Second Pin is Data, Third Pin is Null and Fourth Pin is for GND(Ground).

As we know, VCC refers to 5V, GND for Ground, and Data Pin will connect to Arduino Pins D0 to D13 any of them.

Required Components:

  1. Arduino Uno
  2. DHT 11 Sensor
  3. Breadboard
  4. Jumper Wire

Let’s make circuit diagram for this project.

Figure: DHT11 Circuit Diagram

Sample Code for DHT11 and Arduino

#define DHT11PIN 3
//Pin Declaration

dht11 DHT11;

void setup()
{
  Serial.begin(9600);
// Print or Display value to Monitor
 
}

void loop()
{
  Serial.println();

  int chk = DHT11.read(DHT11PIN);
//  Read Value from Sensor

  Serial.print("Humidity (%): ");
  Serial.println((float)DHT11.humidity, 2);
//  Display Humidity

  Serial.print("Temperature (C): ");
  Serial.println((float)DHT11.temperature, 2);
//  Display Temperature

  delay(2000);

//  Set Delay

}




Copyright © 2020-2021 Engineer Jagat All rights reserved. Developed by Ravindra Rana