DHT11 Sensor Features
The DHT11 is a digital temperature and humidity sensor. This sensor is able to measure the humidity in the range of 20% to 80% with an accuracy of 5%. It can also measure the temperature in the range of 0 to 50 degrees Celsius with an accuracy of 2 degrees.
Note
You can download the DHT11 sensor datasheet here.
DHT11 temperature / humidity Sensor Datasheet
DHT11 Sensor Module Pinout
This module has 4 pins, which only 3 pins are used.
• VCC: Module power supply – 5V
• GND: Ground
• Data: Sensor output
You can see pinout of this module in the image below.
Required Material
Hardware component
Software Apps
Interfacing DHT11 Sensor with Arduino
Step 1: Circuit
Connect the module to Arduino according to the following image.
Note
The output pin of the DHT11 sensor is pulled up on the module with a resistor. therefore, you do not need to connect an external resistor.
Step 2: Installing Library
Note
If you need more help with installing a library on Arduino, read this tutorial: How to Install an Arduino Library
Step 3: Code
/*
DHT11 - Tempertature & Hummidity Sensor
modified on 08 Sep 2020
by Mohammad Reza Akbari @ Electropeak
Home
Based on Adafruit Example
*/
#include "DHT.h"
#define DHTPIN 8 // Digital pin connected to DHT11
// Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();
Serial.println("Initializing... Please wait.");
delay(2000);
}
void loop() {
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.print(F("°C "));
Serial.println(f);
delay(2000);
}
The code output is like this:
Comment (1)
thx a lot you are good Mohammadreza Akbari (are you engineer ?)
nice to contact and read to you
i’m naim tunisian computer science engineer and robotic teacher