IoT-based Indoor Environment Monitoring With ESP32 and DHT22 (Adafruit IO)
by sarful in Circuits > Arduino
26 Views, 0 Favorites, 0 Comments
IoT-based Indoor Environment Monitoring With ESP32 and DHT22 (Adafruit IO)
In this project, you will build an indoor environment monitoring system using an ESP32 microcontroller and a DHT22 sensor. The system will measure temperature and humidity in real-time and send the data to Adafruit IO, a cloud platform designed for IoT applications. This project can be used to monitor indoor environments like homes, offices, or storage rooms for better environmental control. The data will be visualized on Adafruit IO’s dashboard, allowing users to analyze the conditions of their indoor environment.
Supplies
Components Required:
- ESP32 – Microcontroller with Wi-Fi capabilities.
- DHT22 Sensor – Temperature and humidity sensor (DHT22 is more accurate than DHT11).
- Jumper Wires – For wiring the components.
- Breadboard – For prototyping.
- 4.7kΩ Resistor – Pull-up resistor for the DHT22 data line.
- Power Supply – To power the ESP32.
- Adafruit IO Account – Cloud platform to visualize and store sensor data.
Wiring the Components:
- DHT22 to ESP32:
- VCC of DHT22 → 3.3V pin on ESP32.
- GND of DHT22 → GND pin on ESP32.
- Data Pin of DHT22 → Pin D4 on ESP32.
- 4.7kΩ Resistor: Place a resistor between VCC and Data Pin of the DHT22.
Setting Up Adafruit IO:
Step 1: Create an Adafruit IO Account
- Go to Adafruit IO and sign up for a free account.
- After logging in, you'll be directed to the Adafruit IO Dashboard.
Step 2: Create a New Feed
- In the Adafruit IO dashboard, click on the Feeds tab.
- Click + New Feed and create two feeds:
- Temperature Feed (for storing temperature data)
- Humidity Feed (for storing humidity data)
- These feeds will allow the ESP32 to send temperature and humidity data to Adafruit IO.
Step 3: Create an Adafruit IO Key
- Go to AIO Key in your account settings.
- Copy the AIO Key. This key is required for your ESP32 to communicate with Adafruit IO.
Setting Up Arduino IDE:
- Install ESP32 Board Support:
- Open Arduino IDE and go to File → Preferences.
- Add the following URL in Additional Boards Manager URLs:
- Then go to Tools → Board → Board Manager, search for ESP32, and install it.
- Install Necessary Libraries:
- Go to Sketch → Include Library → Manage Libraries.
- Install the following libraries:
- DHT sensor library (by Adafruit)
- Adafruit IO Arduino (for sending data to Adafruit IO)
Complete Arduino Code:
Code Explanation:
- Wi-Fi Setup:
- The code connects the ESP32 to your local Wi-Fi network using the WiFi.begin() function. The program waits until it successfully connects to Wi-Fi.
- Adafruit IO Setup:
- The Adafruit IO credentials (username and key) are used to authenticate the ESP32 with the Adafruit IO cloud platform.
- The program creates two feeds on Adafruit IO to store temperature and humidity data.
- DHT22 Sensor Setup:
- The DHT22 sensor is initialized on Pin D4 of the ESP32.
- The program continuously reads temperature and humidity using dht.readTemperature() and dht.readHumidity().
- Data Sending to Adafruit IO:
- The temperature and humidity readings are sent to their respective feeds on Adafruit IO using temperatureFeed->save() and humidityFeed->save().
- Looping:
- The readings are taken every 10 seconds, and the data is updated on the Adafruit IO dashboard.
Testing the Project:
- Upload the Code:
- Connect your ESP32 to your computer and upload the code using the Arduino IDE.
- Monitor the Serial Output:
- Open the Serial Monitor to view the temperature and humidity readings from the sensor.
- Check Adafruit IO Dashboard:
- Go to your Adafruit IO account and check the Dashboard. You should see live updates of your temperature and humidity readings.
Conclusion:
This ESP32-based Indoor Environment Monitoring system allows you to monitor temperature and humidity data in real-time and store it on the Adafruit IO platform for analysis. You can view the data on your personal dashboard, track historical trends, or integrate this project with automation systems for controlling fans, air conditioners, or dehumidifiers based on the environmental conditions.
Affiliate Disclaimer:
Some links in this article are affiliate links, meaning that I may earn a small commission if you make a purchase through them, at no additional cost to you. Thank you for supporting my work!