ESP32-Based Smart Temperature and Humidity Monitor with LED and Buzzer Alerts
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to monitor temperature and humidity using a DHT11 sensor and an ESP32 microcontroller. It includes visual and auditory alerts using LEDs and a piezo buzzer. The circuit reads temperature and humidity data from the DHT11 sensor and triggers the LEDs and buzzer based on predefined thresholds.
Component List
DHT11 Humidity and Temperature Sensor
- Description: Measures temperature and humidity.
- Pins: VDD, DATA, NULL, GND
ESP32 (30 pin)
- Description: Microcontroller used to process sensor data and control outputs.
- Pins: EN, VP, VN, D34, D35, D32, D33, D25, D26, D27, D14, D12, D13, GND, Vin, D23, D22, TX0, RX0, D21, D19, D18, D5, TX2, RX2, D4, D2, D15, 3V3
LED: Two Pin (red)
- Description: Red LED used for visual alerts.
- Pins: cathode, anode
Piezo Buzzer
- Description: Buzzer used for auditory alerts.
- Pins: negative pin, positive pin
LED: Two Pin (blue)
- Description: Blue LED used for visual alerts.
- Pins: cathode, anode
Wiring Details
DHT11 Humidity and Temperature Sensor
- VDD connected to 3V3 of ESP32
- DATA connected to D5 of ESP32
- GND connected to GND of ESP32
ESP32 (30 pin)
- 3V3 connected to VDD of DHT11
- D5 connected to DATA of DHT11
- GND connected to GND of DHT11, cathode of red LED, negative pin of Piezo Buzzer, cathode of blue LED
- D14 connected to anode of blue LED
- D4 connected to positive pin of Piezo Buzzer
- D2 connected to anode of red LED
LED: Two Pin (red)
- cathode connected to GND of ESP32
- anode connected to D2 of ESP32
Piezo Buzzer
- negative pin connected to GND of ESP32
- positive pin connected to D4 of ESP32
LED: Two Pin (blue)
- cathode connected to GND of ESP32
- anode connected to D14 of ESP32
Code Documentation
#include <DHT.h>
#define DHTPIN 5 // Pin where the DHT11 data pin is connected
#define DHTTYPE DHT11
const int tempLedPin = 14; // LED pin for Temperature
const int humidityLedPin = 2; // LED pin for Humidity
const int buzzerPin = 4; // Buzzer pin
const float HUMIDITY_HIGH_THRESHOLD = 85.0; // High humidity threshold
const float HUMIDITY_LOW_THRESHOLD = 65.0; // Low humidity threshold
const float TEMP_HIGH_THRESHOLD = 20.0; // High temperature threshold
const float TEMP_LOW_THRESHOLD = 18.0; // Low temperature threshold
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(115200);
dht.begin();
pinMode(tempLedPin, OUTPUT);
pinMode(humidityLedPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
}
void loop() {
float humidity = dht.readHumidity();
float temperatureC = dht.readTemperature();
if (humidity > HUMIDITY_HIGH_THRESHOLD || humidity < HUMIDITY_LOW_THRESHOLD) {
digitalWrite(humidityLedPin, HIGH);
tone(buzzerPin, 3000);
} else {
digitalWrite(humidityLedPin, LOW);
noTone(buzzerPin);
}
if (temperatureC > TEMP_HIGH_THRESHOLD || temperatureC < TEMP_LOW_THRESHOLD) {
digitalWrite(tempLedPin, HIGH);
tone(buzzerPin, 3000);
} else {
digitalWrite(tempLedPin, LOW);
noTone(buzzerPin);
}
Serial.print("Temperature (°C): ");
Serial.print(temperatureC);
Serial.print(" , Humidity (RH %): ");
Serial.println(humidity);
delay(30000); // Wait for 30 seconds
}
This code initializes the DHT11 sensor and sets up the pins for the LEDs and buzzer. In the loop function, it reads the temperature and humidity values and triggers the LEDs and buzzer if the values exceed the predefined thresholds. The data is also printed to the serial monitor every 30 seconds.