Interfacing Temperature and Humidity Sensor (DHT11) with Arduino
DHT11 is a digital temperature and Humidity sensor. The sensor comes in 4 pin package as well as 3 pin board module.


Connections:
4-pin DHT11 | 3-pin DHT11 | Arduino UNO/ Mega |
VCC | VCC | 5V |
GND | GND | GND |
DATA | S or Signal | 2 |
Library Installation on Arduino IDE:
New versions of Arduino IDE (software) contains builtin libraries support. The user just needs to select a particular library and click Install. See step by step, how to add a DHT11 library.
Step # 01: In Arduino IDE, select Sketch > Include Library > Manage Libraries
Step # 02: Write DHT in search box
Step # 03: You will see two or more libraries in the box, install the “DHT Sensor Library” and “SimpleDHT” both libraries, if already installed, update them to latest version.
Execute the code:
Copy the following code and upload it to Arduino.
#include <SimpleDHT.h>
// for DHT11, void setup() { void loop() { // read without samples. Serial.print(“Sample OK: “); // DHT sampling rate is 1HZ. |
Results/ Output:
Arduino code that doesn’t show errors:
#include <SimpleDHT.h>
int pinDHT11 = 2; void setup() { void loop() { Serial.print((int)temperature); Serial.print(” *C, “); // DHT sampling rate is 1HZ. |
This code REALLY made my day. My DHT works like a charm.