
ESP32 Tutorial 51/55 - Temperature and Humidity over WiFi with DHT | SunFounder's ESP32 IoT Learning Kit
This tutorial demonstrates how to build a simple, yet effective, system for monitoring temperature and humidity using an ESP32 microcontroller, a DHT11 or DHT22 sensor, and a Wi-Fi connection. The project's real-world value lies in its ability to remotely monitor environmental conditions, making it applicable in various scenarios.
Practical Applications:
Monitoring a home greenhouse
Tracking temperature and humidity in a storage facility
Building a weather station
Creating a remote environmental monitoring system for a farm
Hardware/Components
This project utilizes SunFounder's ESP32 IoT Learning Kit (in video at 00:16), which includes an ESP32 microcontroller with built-in Wi-Fi and Bluetooth, a DHT11 or DHT22 sensor (in video at 00:07), and other necessary components. The kit also provides an 18650 lithium battery and charger (in video at 01:22), allowing for off-grid operation.
Wiring Guide
The tutorial demonstrates connecting the DHT sensor to the ESP32. Specific pin assignments are detailed in the code.
%%WIRING%%
Code Explanation
The provided code (in video at 04:02) uses the DHT sensor library to read temperature and humidity values. The ESP32 acts as a web server, serving a webpage that displays these readings. Key configurable parts of the code include:
Wi-Fi Credentials: The
ssid
andpassword
variables (in video at 06:21) must be set to your Wi-Fi network's SSID and password. Ensure that the SSID is case-sensitive.Sensor Type: The
DHTTYPE
(in video at 05:38) constant defines whether you are using a DHT11 or DHT22 sensor. Uncomment the appropriate line to select your sensor.Units: The
unit
variable (in video at 04:57) controls whether the temperature is displayed in Celsius (0) or Fahrenheit (1).Refresh Rate: The
refresh
variable (in video at 04:31) sets how often the webpage updates (in seconds).Serial Output: The
showSerial
variable (in video at 04:38) enables or disables serial monitor output.
The sendTemp()
function (in video at 06:55) constructs the HTML page to display the temperature and humidity readings. The handleNotFound()
function (in video at 08:42) handles requests for non-existent pages.
const char *ssid = "YOUR_SSID";
const char *password = "YOUR_PASSWORD";
const int refresh = 10; // Update every 10 seconds
boolean showSerial = false; // Disable serial output
unsigned int unit = 0; // 0 for Celsius, 1 for Fahrenheit
Live Project/Demonstration
The video (in video at 15:11) demonstrates the project's functionality. The ESP32's IP address is obtained, and the webpage is accessed via a web browser or mobile device to view the temperature and humidity readings. The video also shows how changing the unit
variable in the code alters the displayed units.
Chapters
[00:00] Introduction and Project Overview
[00:25] SunFounder ESP32 Starter Kit
[01:40] Internet of Things (IoT) Concept
[02:21] ESP32 as a Web Server
[03:35] Software and Library Installation
[04:02] Code Overview and Explanation
[13:29] Selecting the ESP32 Board and Port
[15:11] Project Demonstration
Comments will be displayed here.