Random Nerd Tutorials
Shares

ESP8266 DHT11/DHT22 Temperature and Humidity Web Server with Arduino IDE

Shares

In this project you’ll create a standalone web server with an ESP8266 that displays the temperature and humidity with a DHT11 or DHT22 sensor.

Recommended Resources:

If you like the ESP and you want to do more projects you can read my eBook Password Protected Web Server Accessible from Anywhere using ESP8266 and Arduino IDE.

Let’s get started!

First, watch the video demonstration below


Installing the DHT Sensor Library

The DHT sensor library provides an easy way of using any DHT sensor to read temperature and humidity with your ESP8266 or Arduino boards.

1) Click here to download the DHT sensor library. You should have a .zip folder in your Downloads

zip

2) Unzip the .zip folder and you should get DHT-sensor-library-master folder

folder

3) Rename your folder from DHT-sensor-library-master to DHT

rename

4) Move the DHT folder to your Arduino IDE installation libraries folder

moving

5) Then re-open your Arduino IDE

Uploading your ESP8266 code

Having the ESP8266 add-on for the Arduino IDE installed (How to Install the ESP8266 Board in Arduino IDE).

Go to Tools and select “Generic ESP8266 Module”.

Arduino IDE select esp8266

Copy the sketch below to your Arduino IDE. Replace the SSID and password with your own credentials.

After modifying my sketch upload it to your ESP8266 (if you can’t upload code to your ESP8266, read this troubleshooting guide).

Note: you can comment/uncomment the sketch, if you prefer to use the DHT22 sensor.

Schematics

To complete this project you need the following components:

Note: Other DHT sensor types will also work with a small change in the code (as described in the sketch comments).

Here’s the schematics:

ESP8266_schematics_bb

Important: the DHT sensor requires 5V to operate properly, so make sure you use the Vin pin from your ESP8266 that outputs 5V.

ESP8266 IP Address

Open the Arduino IDE serial monitor at a baud rate of 115200. After a few seconds your IP address should appear. In my case it’s 192.168.1.95.

Arduino IDE

Demonstration

For the final demonstration open any browser from a device that is connected to the same router that your ESP is. Then type the IP address and click Enter!

web server

Now you can easily see the current temperature in Celsius and Fahrenheit and the humidity.

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 and my Facebook Page.

P.S. If you got stuck during this tutorial make sure you read “ESP8266 Troubleshooting Guide

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 couse even with no prior experience!

Leave a Comment:

Add Your Reply

⏰ Early Black Friday 2017 Special ⏰
Download all our courses up to 35% off