This circuit is designed to monitor environmental parameters such as temperature, humidity, gas concentration, light intensity, and the presence of fire. It utilizes an ESP32 Devkit V1 microcontroller to process sensor data and control peripherals like buzzers, a relay, and an LCD display. The circuit is powered by a step-down module that converts a 12V input to a 5V output, suitable for powering the 5V components. The ESP32 reads sensor data from a DHT11 temperature and humidity sensor, an MQ-5 gas sensor, a photosensitive sensor module for light intensity, and a flame sensor for fire detection. The circuit includes two buzzers for audible alerts and a relay to control an AC bulb. The LCD display provides real-time feedback on the sensor readings.
VIN
connected to the 5V output of the Step-down Module.GND
connected to the ground of the Step-down Module.D4
connected to the signal pin of the DHT11.D5
, D18
connected to the PIN of the buzzers.D21
(SDA), D22
(SCL) connected to the I2C LCD Screen.D34
connected to the analog output of the MQ-5 Gas Sensor.D35
connected to the analog output of the Photosensitive Sensor Module.D32
connected to the analog output of the Flame Sensor.D12
connected to the signal pin of the 1-Channel Relay.5V
connected to the 5V output of the Step-down Module.GND
connected to the ground of the Step-down Module.S
connected to D4
on the ESP32 Devkit V1.VCC
connected to the 5V output of the Step-down Module.GND
connected to the ground of the Step-down Module.Analog out
connected to D34
on the ESP32 Devkit V1.24v IN+
not connected in the provided net list.12v IN+
connected to the +
of the 12V Power Supply.5v OUT+
connected to the 5V power rail of the circuit.5v OUT-
connected to the ground rail of the circuit.GND
connected to the -
of the 12V Power Supply.+
connected to 12v IN+
on the Step-down Module.-
connected to GND
on the Step-down Module.PIN
connected to D5
and D18
on the ESP32 Devkit V1 (two separate buzzers).GND
connected to the ground rail of the circuit.NC
not connected in the provided net list.signal
connected to D12
on the ESP32 Devkit V1.C
connected to P
on the AC Bulb.power
connected to the 5V power rail of the circuit.NO
connected to Live
on the 240V Power Source.ground
connected to the ground rail of the circuit.Live
connected to NO
on the 1-Channel Relay.Neutral
connected to N
on the AC Bulb.VCC
connected to the 5V power rail of the circuit.GND
connected to the ground rail of the circuit.A0
connected to D32
on the ESP32 Devkit V1.P
connected to C
on the 1-Channel Relay.N
connected to Neutral
on the 240V Power Source.SCL
connected to D22
on the ESP32 Devkit V1.SDA
connected to D21
on the ESP32 Devkit V1.VCC (5V)
connected to the 5V power rail of the circuit.GND
connected to the ground rail of the circuit.Analog Output
connected to D35
on the ESP32 Devkit V1.VCC
connected to the 5V power rail of the circuit.Ground
connected to the ground rail of the circuit.#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "DHT.h"
// Define DHT sensor settings
#define DHTPIN 4 // Connect your DHT sensor to GPIO4 (change if needed)
#define DHTTYPE DHT11 // DHT11 or DHT22, depending on your sensor
DHT dht(DHTPIN, DHTTYPE); // Initialize the DHT sensor
// Initialize the LCD with the I2C address and dimensions (16x2)
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Define gas sensor, LDR sensor, fire sensor, buzzers, and relay settings
#define GAS_PIN 34 // ESP32 analog pin for gas sensor (change if needed)
#define BUZZER_PIN 5 // Buzzer connected to GPIO5
#define GAS_THRESHOLD 3000 // Threshold for gas sensor (adjust based on your sensor)
#define LDR_PIN 35 // ESP32 analog pin for LDR sensor (change if needed)
#define RELAY_PIN 12 // Relay connected to GPIO12
#define LDR_THRESHOLD 1000 // Threshold for LDR sensor (adjust based on your environment)
#define FIRE_PIN 32 // ESP32 digital pin for fire sensor (change if needed)
#define BUZZER2_PIN 18 // Additional buzzer connected to GPIO13
// Variables to store sensor readings
float humidity;
float temperature;
int gasValue;
int ldrValue;
int fireValue;
void setup() {
lcd.begin(); // Initialize the LCD
lcd.backlight(); // Turn on the backlight
dht.begin(); // Initialize the DHT sensor
pinMode(GAS_PIN, INPUT); // Set the gas sensor pin as input
pinMode(LDR_PIN, INPUT); // Set the LDR sensor pin as input
pinMode(FIRE_PIN, INPUT); // Set the fire sensor pin as input
pinMode(BUZZER_PIN, OUTPUT); // Set the buzzer pin as output
pinMode(BUZZER2_PIN, OUTPUT); // Set the second buzzer pin as output
pinMode(RELAY_PIN, OUTPUT); // Set the relay pin as output
lcd.print("Starting..."); // Print a startup message
delay(2000); // Wait for 2 seconds
lcd.clear(); // Clear the display
}
void loop() {
// Read temperature and humidity from DHT sensor
humidity = dht.readHumidity();
temperature = dht.readTemperature();
gasValue = analogRead(GAS_PIN); // Read the gas sensor value
ldrValue = analogRead(LDR_PIN); // Read the LDR sensor value
fireValue = digitalRead(FIRE_PIN); // Read the fire sensor value (digital)
// Check if any readings failed and exit early (to try again).
if (isnan(humidity) || isnan(temperature)) {
lcd.setCursor(0, 0);
lcd.print("Sensor error!");
return;
}
// Display humidity and temperature on the first two rows
lcd.setCursor(0, 0);
lcd.print("Hum: ");
lcd.print(humidity);
lcd.print("%");
lcd.setCursor(0, 1);
lcd.print("Temp: ");
lcd.print(temperature);
lcd.print(" C");
delay(2000);
lcd.clear();
// Display gas sensor and LDR sensor values
lcd