Home
About Us
Achievement
Home
Raspberry-Pi Projects
_Raspberry Pi 4 Complete Guide
Arduino Project
_All Projects
Esp8266 Project
_All Projects
Esp32 Project
_Automation-with-feedback
Esp32 Based Wather Stations
Just Do Electronics
April 12, 2020
ESP32 DHT11 Web Server – Temperature and Humidity using Arduino IDE
In this project, you’ll learn how to build an asynchronous ESP32 web server with the DHT11 that displays temperature and humidity using Arduino IDE.
Circuit Diagram :-
Code :-
//Prateek //www.prateeks.in #include "WiFi.h" #include "ESPAsyncWebServer.h" #include
#include
// Replace with your network credentials const char* ssid = "justDo"; const char* password = "pratik123"; #define DHTPIN 15 #define DHTTYPE DHT11 DHT dht(DHTPIN, DHTTYPE); // Create AsyncWebServer object on port 80 AsyncWebServer server(80); String readDHTTemperature() { float t = dht.readTemperature(); if (isnan(t)) { Serial.println("Failed to read from DHT sensor!"); return "--"; } else { Serial.println(t); return String(t); } } String readDHTHumidity() { // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) float h = dht.readHumidity(); if (isnan(h)) { Serial.println("Failed to read from DHT sensor!"); return "--"; } else { Serial.println(h); return String(h); } } const char index_html[] PROGMEM = R"rawliteral(
ESP32 DHT Server
Temperature
%TEMPERATURE%
°C
Humidity
%HUMIDITY%
%
)rawliteral"; // Replaces placeholder with DHT values String processor(const String& var){ //Serial.println(var); if(var == "TEMPERATURE"){ return readDHTTemperature(); } else if(var == "HUMIDITY"){ return readDHTHumidity(); } return String(); } void setup(){ // Serial port for debugging purposes Serial.begin(115200); dht.begin(); // Connect to Wi-Fi WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.println("Connecting to WiFi.."); } // Print ESP32 Local IP Address Serial.println(WiFi.localIP()); // Route for root / web page server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){ request->send_P(200, "text/html", index_html, processor); }); server.on("/temperature", HTTP_GET, [](AsyncWebServerRequest *request){ request->send_P(200, "text/plain", readDHTTemperature().c_str()); }); server.on("/humidity", HTTP_GET, [](AsyncWebServerRequest *request){ request->send_P(200, "text/plain", readDHTHumidity().c_str()); }); // Start server server.begin(); } void loop(){ }
0 Comments
Newer
Older
ESP32 Interfacing With LDR Sensor
ESP32 Led Blink With Push Button
IoT Based Patient Health Monitoring System Using Blynk App
Ultrasonic Sensor as a Counter with Arduino
Esp32 Cam Based Face Unlock
MLX90614 Non-Contact Infrared Thermometer With Arduino
Measure CO2 Level in Air Using Arduino
Sign Language to Speech Conversion using Arduino With Flex Sensor
ESP32 Interfacing Potentiometer
How to Make a Conveyor Belt System | Counter Machine
YouTube
Like on Facebook
Follow on Twitter
Follow on Google+
Follow on Instagram
Subscribe on Youtube
Hi WelCome To My Website If you have a creative mind and want to learn Electronics even without studying it then FRIENDS this Website And Youtube Channel is for you, I am crazy creators who love making Electronics things. I have a bunch of more than 130 Tutorial Videos on My YouTube Channel and I upload a new Tutorial every Sunday.
Tags
Arduino Project
Esp32 Project
Esp8266 Project
0 Comments