ESP 32 TO DHT 11
Low Cost & Easy Integration: The DHT11 is an affordable sensor that easily interfaces with the ESP32, making it ideal for budget-friendly projects.
Wireless Connectivity: The ESP32 has built-in Wi-Fi and Bluetooth, allowing remote monitoring and data transmission.
Low Power Consumption: Suitable for battery-powered applications, the ESP32 efficiently manages power while collecting environmental data.
Digital Output: The DHT11 provides a digital signal, simplifying data processing without requiring complex analog conversions.
Versatile Applications: Used in smart homes, weather stations, and IoT-based automation systems.
🔧 Components Overview:
-
ESP32:
-
A powerful microcontroller with Wi-Fi and Bluetooth built in.
-
Suitable for IoT applications due to its wireless capabilities and low power consumption.
-
Has multiple GPIO (General Purpose Input/Output) pins to connect sensors and other devices.
-
-
DHT11 Sensor:
-
Measures temperature (in °C) and humidity (in %).
-
Simple and low-cost sensor.
-
Communicates with the ESP32 using a single digital pin.
-
Accuracy:
-
Temperature: ±2°C
-
Humidity: ±5%
-
-
🔌 How It Works:
-
Connection:
-
The DHT11 sensor is connected to one of the ESP32's GPIO pins.
-
Power (3.3V or 5V), ground (GND), and data line are used.
-
-
Data Reading:
-
ESP32 uses a library (like
DHT.h
in Arduino IDE) to communicate with the sensor. -
It sends a start signal to the DHT11.
-
The sensor responds with temperature and humidity data in digital form.
-
-
Processing:
-
ESP32 reads the data, processes it, and can display it (e.g., on a serial monitor, OLED screen, or via a web server).
-
-
Optional:
-
Use Wi-Fi to send the data to the cloud or a smartphone app for remote monitoring.
-
📦 Common Applications:
-
Home automation
-
Weather stations
-
Smart agriculture
-
Environmental monitoring
code :
- #include <WiFi.h>#include <WebServer.h>#include "DHT.h"// Uncomment one of the lines below for whatever DHT sensor type you're using!//#define DHTTYPE DHT11 // DHT 11//#define DHTTYPE DHT21 // DHT 21 (AM2301)#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321/*Put your SSID & Password*/const char* ssid = "YourNetworkName"; // Enter SSID hereconst char* password = "YourPassword"; //Enter Password hereWebServer server(80);// DHT Sensoruint8_t DHTPin = 4;// Initialize DHT sensor.DHT dht(DHTPin, DHTTYPE);float Temperature;float Humidity;void setup() {Serial.begin(115200);delay(100);pinMode(DHTPin, INPUT);dht.begin();Serial.println("Connecting to ");Serial.println(ssid);//connect to your local wi-fi networkWiFi.begin(ssid, password);//check wi-fi is connected to wi-fi networkwhile (WiFi.status() != WL_CONNECTED) {delay(1000);Serial.print(".");}Serial.println("");Serial.println("WiFi connected..!");Serial.print("Got IP: "); Serial.println(WiFi.localIP()
); server.on("/", handle_OnConnect);server.onNotFound(handle_NotFound); server.begin();Serial.println("HTTP server started");}void loop() {server.handleClient();}void handle_OnConnect() {Temperature = dht.readTemperature(); // Gets the values of the temperatureHumidity = dht.readHumidity(); // Gets the values of the humidityserver.send(200, "text/html", SendHTML(Temperature,Humidity)); }void handle_NotFound(){server.send(404, "text/plain", "Not found");}String SendHTML(float Temperaturestat,float Humiditystat){String ptr = "<!DOCTYPE html> <html>\n";ptr +="<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\">\n";ptr +="<title>ESP32 Weather Report</title>\n";ptr +="<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}\n";ptr +="body{margin-top: 50px;} h1 {color: #444444;margin: 50px auto 30px;}\n";ptr +="p {font-size: 24px;color: #444444;margin-bottom: 10px;}\n";ptr +="</style>\n";ptr +="</head>\n";ptr +="<body>\n";ptr +="<div id=\"webpage\">\n";ptr +="<h1>ESP32 Weather Report</h1>\n";ptr +="<p>Temperature: ";ptr +=(int)Temperaturestat;ptr +="°C</p>";ptr +="<p>Humidity: ";ptr +=(int)Humiditystat;ptr +="%</p>";ptr +="</div>\n";ptr +="</body>\n";ptr +="</html>\n";return ptr;}
our chip data's temperature = 26.60 c
compare to Pune weather= 26.24 c
from local server humidity = 84.80 c
from our server humidity = 81. 32 c
Comments
Post a Comment