Random Nerd Tutorials
Share

ESP32 with DHT11 DHT22 Temperature Humidity Web Server using Arduino IDE

Share

In this project you’ll create a standalone web server with an ESP32 and a DHT11 or DHT22 sensor that displays temperature and humidity. The ESP32 will be programmed using Arduino IDE.

Recommended Resources:

Learn more about the ESP32: Learn ESP32 with Arduino IDE

Preparing the ESP32 board in Arduino IDE

There’s an add-on for the Arduino IDE that allows you to program the ESP32 using the Arduino IDE and its programming language. Follow one of the next tutorials to prepare your Arduino IDE:

Installing the DHT Sensor Library

The DHT sensor library provides an easy way to get temperature and humidity readings using Arduino IDE. Follow the next steps to install the DHT library:

  1. Click here to download the DHT sensor library. You should have a .zip folder in your Downloads
  2. Unzip the .zip folder and you should get DHT-sensor-library-master folder
  3. Rename your folder from DHT-sensor-library-master to DHT
  4. Move the DHT folder to your Arduino IDE installation libraries folder

Installing the Adafruit_Sensor library

To use the DHT sensor library, you also need to install the Adafruit Sensor library. Follow the next steps to install that library:

  1. Click here to download the Adafruit_Sensor library. You should have a .zip folder in your Downloads folder
  2. Unzip the .zip folder and you should get Adafruit_Sensor-master folder
  3. Rename your folder from Adafruit_Sensor-master to Adafruit_Sensor
  4. Move the Adafruit_Sensor folder to your Arduino IDE installation libraries folder
  5. Finally, re-open your Arduino IDE

Parts Required

To complete this tutorial you need the following parts:

You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!

Schematic

Wire the DHT22 or DHT11 temperature and humidity sensor to the ESP32 as shown in the schematic diagram.

cloud-download

Note: if you’re using a module with a DHT sensor, it normally comes with only three pins. The pins should be labeled so that you know how to wire them. Additionally, many of these modules already come with an internal pull up resistor, so you don’t need to add one to the circuit.

Uploading the code

In this example, you’re going to create a web server with the ESP32 on your local network that displays temperature and humidity readings from the DHT22 sensor.

Copy the following code to your Arduino IDE and upload it to your ESP32 development board.

Don’t forget to add your network credentials in the preceding code (SSID and Password).

const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASSWORD";

To upload code to the ESP32 follow the next instructions:

1) Select your board in Tools > Board menu (in my case it’s the ESP32 Dev Module).

2) Select the COM port.

3) To upload code to the ESP32: hold the BOOT button while you press the Upload button in the Arduino IDE and wait a few seconds while the code compiles and uploads to your board.

After successfully uploading the code, this is what you should see:

5) Restart your ESP32 to run the newly uploaded code.

Accessing your web server

When the ESP32 restarts, it prints the IP address on the Arduino IDE serial monitor (baud rate of 115200).

Demonstration

To access you web server, open a browser in your local network and type the ESP32 IP address. In my case it’s 192.168.1.116.

Here’s what you should see:

Your web page instantly refreshes every 30 seconds. If the temperature is above 25ºC, the temperature reading is displayed in a red color:

Wrapping Up

I hope you found this project useful. If you want to learn how to take the most out of the ESP32 capabilities, make sure you check our course: Learn ESP32 with Arduino IDE.

More resources about ESP32: 20+ ESP32 Projects and Tutorials

Do you have any questions? Leave a comment down below!

Thanks for reading. If you like this post probably you might like my next ones, so please support me by subscribing my blog.


Learn ESP32 with Arduino IDE

This is our complete guide to program the ESP32 with Arduino IDE, including projects, tips, and tricks! The registrations are open, so SIGN UP NOW »

Recommended Resources

Home Automation using ESP8266 »
Build IoT projects and home automation gadgets with the ESP8266 Wi-Fi module.

Build a Home Automation System »
Learn how to build a automation system using open-source hardware and software from scratch.

Arduino Step-by-Step Projects »
Build 25 cool Arduino projects with our course even with no prior experience!

Leave a Comment:

Add Your Reply

Enroll in our Electronics and Programming Courses:

ESP32, ESP8266, Arduino and much more.