An ESP32-Powered Flame Sensing System for Unstoppable Safety!

undefined

Introduction to ESP32 with DHT11 Sensor

Relative humidity and temperature are measured using the DHT11 and DHT22 sensors. These are highly favored by producers and enthusiasts of electronics. One of the chips in these sensors converts analog data to digital data and outputs a digital signal that includes the temperature and humidity. Because of this, using them with any microcontroller is quite simple.

Components Required

This project uses the ESP32 along with a DHT11 sensor to read temperature and humidity. The setup is beginner-friendly and perfect for basic IoT projects.

  • Connect DHT11 VCC to ESP32 3.3V
  • Connect DHT11 GND to ESP32 GND.
  • Connect DHT11 Data Pin to ESP32 GPIO 4 (or another digital pin).
  • Open the Arduino IDE on your computer.
  • Go to Tools > Board > Boards Manager.
  • Search for ESP32 and install the ESP32 package.
  • Go to Tools > Board and select ESP32 Dev Module.
  • Connect your ESP32 to the computer via USB.
  • Go to Tools > Port and select the appropriate COM port.
  • Go to Sketch > Include Library > Manage Libraries.
  • Search for DHT sensor library and install it.
  • Search for 'Adafruit Unified Sensor' and install it.
  • Copy and paste the following code into a new Arduino sketch.
  • Click the upload button (right-arrow icon) in the Arduino IDE.
  • Wait for the code to compile and upload to the ESP32.
  • Open the Serial Monitor (Ctrl+Shift+M) in the Arduino IDE.
  • Set the baud rate in the Serial Monitor to 115200.
  • View the temperature and humidity readings displayed in the Serial Monitor.

Formula: Temperature & Humidity = Sensor Data from DHT11

undefined

Components List

  • 1 × ESP32 Development Board
  • 1 × DHT11 Sensor
  • Jumper Wires
  • Breadboard

Pin Configuration

  • VCC: Connect to 3.3V of ESP32
  • GND: Connect to GND of ESP32
  • Data: Connect to GPIO 4 (or any digital pin) of ESP32

Make sure to use a pull-up resistor (10kΩ) on the data line if you're facing unstable readings.

undefined - Pin Diagram

Wiring and Connections

  • -> 3.3V
  • -> GND
  • -> GPIO 4
undefined - Circuit Diagram

Code for ESP32 with DHT11 Sensor

1#include "DHT.h"
2
3#define DHTPIN 4     // GPIO where the data pin is connected
4#define DHTTYPE DHT11
5
6DHT dht(DHTPIN, DHTTYPE);
7
8void setup() {
9  Serial.begin(115200);
10  dht.begin();
11}
12
13void loop() {
14  float humidity = dht.readHumidity();
15  float temperature = dht.readTemperature();
16
17  if (isnan(humidity) || isnan(temperature)) {
18    Serial.println("Failed to read from DHT sensor!");
19    return;
20  }
21
22  Serial.print("Temperature: ");
23  Serial.print(temperature);
24  Serial.print(" °C	Humidity: ");
25  Serial.print(humidity);
26  Serial.println(" %");
27  delay(2000);
28}

Code Explanation

  • #include "DHT.h": Includes the library needed to communicate with the DHT sensor.
  • #define DHTPIN 4: Defines GPIO 4 as the data pin for the DHT11.
  • #define DHTTYPE DHT11: Specifies the type of DHT sensor used.
  • dht.begin();: Initializes communication with the DHT sensor.
  • float humidity = dht.readHumidity();: Reads the humidity from the sensor.
  • float temperature = dht.readTemperature();: Reads the temperature from the sensor.
  • Serial.print(...): Prints the readings to the Serial Monitor for debugging or display.
  • delay(2000);: Waits for 2 seconds before taking the next reading.

Applications

  • Weather monitoring systems
  • Home automation
  • Agricultural environmental sensing
  • Greenhouse climate monitoring

Conclusion

By following these steps, you can successfully connect a DHT11 sensor to an ESP32 and program it using the Arduino IDE. This setup enables you to monitor temperature and humidity readings, providing a simple and effective solution for various environmental sensing applications.