Here is Connection & Working Code for ESP32 Arduino with DHT11 Sensor. We will use Adafruit’s libraries for DHT11 and DH22 Temperature Humidity Modules. For using DHT11, DHT21, DHT22 with non-ESP32 Arduino please read our previous guide on Arduino Temperature Humidity Sensor. For ESP32, it is mandatory to have the common required setup for Arduino IDE (ESP32 does not work with Arduino IDE out of the box).
We will need two libraries. First install them (unless you already have them) :
1 2 3 4 | # https://github.com/adafruit/Adafruit_Sensor https://github.com/adafruit/DHT-sensor-library # |
DHT22 is modern, sensitive but more costly. DHT11 is commonly used module. If you newly purchased some kind of China DHT11 temperature humidity sensor, it will appear to you that they have lot of pins. That blue or white coloured plastic outside is a mini casing. If you open it up it (not needed for operation but for optional learning) you will find a PCB inside which has a resistive type humidity sensor, a negative temperature coefficient thermistor for measuring temperature and an 8-bit microcontroller. Left to right the pins are :
---
VCC – to connect with 5v of Arduino
Data – to connect with digital pin of Arduino
NC – not needed to do anything
GND – to connect with GND of Arduino
Essentially we have one data pin for our actual need, it is obvious that one pin will go to 3v and one to GND. The 2nd pin, which is Data, needs some operational voltage. Adding a 220 Ohm resister to 3v of ESP32 and adding it to Data pin will work fine. Then Data pin will go to digital pin of Arduino. Here are the pins :
1 2 3 4 5 6 | # ------------------------[5v of Arduino]-------------+-------+ ---[5K Ohm resister]----[Digital Pin of Arduino]----| DT | ---[Not needed]-------------------------------------| 11 | ------------------------[GND of Arduino]------------+-------+ # |
Here is the diagram for required connection :
We have attached the data pin to pin 15 of ESP32. You will get the required Fritzing diagram and Arduino code on our Github repo.
Here is the required code, which is nothing but minimal modification of our code for Arduino UNO. Open the serial monitor on Arduino IDE and set it to 9600 baud rate. Use the code from our GitHub repo (there can be error of web rendering on this site) :
The code definitely works as we have tested it.
Tagged With esp32 dht11 , arduino IDE esp32 with dht11 sensor , connect dht11 to esp32 , dht11 sensor connection , dht22 thingspeak using uno code , arduino code for dht11 sensor , dht11 with arduino connection , dht11 esp32 , arduino esp32 dht11 , sensor connectivity code arduino