This project is an Internet of Things (IoT) application that uses an ESP32 microcontroller to monitor temperature and humidity. The data is collected using a DHT21 sensor and displayed on a web page hosted on the ESP32. Additionally, the web interface allows users to toggle a lamp and download the recorded data.
- WiFi Connectivity: Connects to a specified WiFi network.
- DHT21 Sensor: Reads temperature and humidity data.
- Web Server: Hosts a web page to display sensor data and control a lamp.
- SPIFFS: Stores data locally on the ESP32 filesystem.
- JSON: Uses JSON for data interchange between the ESP32 and the web interface.
- ESP32 microcontroller
- DHT21 temperature and humidity sensor
- LED lamp (optional)
- Resistors, breadboard, and jumper wires
- Arduino IDE with ESP32 support
- ArduinoJson library
- DHT sensor library
- WiFi library
- WebServer library
- SPIFFS library
Connect the DHT21 sensor to the ESP32 as follows:
- VCC to 3.3V
- GND to GND
- DATA to GPIO4
Connect the lamp to GPIO2 with an appropriate resistor.
- Library Inclusions: Includes necessary libraries for WiFi, web server, DHT sensor, SPIFFS, and JSON.
- WiFi Configuration: Sets up WiFi credentials for network connection.
- DHT Sensor Configuration: Initializes the DHT21 sensor.
- Web Server Routes: Defines routes for the main page, toggling the lamp, reading sensor data, and downloading data.
- Main Page: Serves an HTML page that displays temperature and humidity data and provides buttons for toggling the lamp and downloading data.
- Data Handling: Reads sensor data and appends it to a file on the SPIFFS filesystem.
- Install Arduino IDE: Make sure you have the Arduino IDE installed on your computer.
- Install ESP32 Board in Arduino IDE:
- Go to
File
>Preferences
. - Add
https://dl.espressif.com/dl/package_esp32_index.json
to theAdditional Board Manager URLs
. - Open the
Boards Manager
fromTools
>Board
and install theesp32
package.
- Go to
- Install Required Libraries:
- Go to
Sketch
>Include Library
>Manage Libraries
. - Install the following libraries:
ArduinoJson
,DHT sensor library
,WiFi
,WebServer
,SPIFFS
.
- Go to
- Connect ESP32 to Your Computer: Use a USB cable to connect the ESP32 to your computer.
- Upload the Code: Open the provided code in Arduino IDE and upload it to the ESP32.
- Power the ESP32: After uploading the code, power the ESP32 using the USB connection or an external power source.
- Connect to WiFi: The ESP32 will attempt to connect to the specified WiFi network.
- Access the Web Interface:
- Open a web browser on a device connected to the same WiFi network.
- Enter the IP address of the ESP32 displayed in the Serial Monitor.
- Monitor Data: View temperature and humidity data, toggle the lamp, and download recorded data from the web interface.
Feel free to fork this repository and contribute by submitting pull requests. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the MIT License - see the LICENSE file for details.
If you find this project helpful, consider making a donation: