ESP with DHT 11 part 2





🔧 Components Involved

  • DHT11: A digital sensor that measures temperature and humidity.

  • ESP32: A powerful microcontroller with built-in Wi-Fi and Bluetooth.

  • Smartphone: Used to view sensor data via a web browser or mobile app.


📡 How It Works

  1. Sensor Reads Data:

    • The DHT11 periodically measures the temperature and humidity.

    • It sends this data as a digital signal to the ESP32 via a data pin.

  2. ESP32 Processes Data:

    • The ESP32 reads the DHT11 data using a library (e.g., DHT.h in Arduino).

    • It then serves the data over Wi-Fi or Bluetooth.

  3. Phone Displays Data:

    • Option 1: ESP32 runs a web server.

      • Your phone connects to the ESP32’s Wi-Fi or local network.

      • Open a browser and go to the ESP32’s IP address to see the data.

    • Option 2: Use Bluetooth to send data to a custom app or Bluetooth terminal.


✅ Simple Use Case (Web Server)

  • ESP32 creates a Wi-Fi hotspot or connects to your router.

  • It runs a web page showing temperature and humidity.

  • On your phone, connect to the same network and open a browser to see live data.


🧠 Example Output:

Temperature: 26°C
Humidity: 60%

CODE :

#define BLYNK_TEMPLATE_ID "TMPLIAjddf20T5"
#define BLYNK_DEVICE_NAME "Temperature and Humidity Monitor"
#define BLYNK_AUTH_TOKEN "122RywymdfdddgGfMd1jkZ0STNhRQecR12ayq"

#define BLYNK_PRINT Serial
#include <WiFi.h>
//#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp32.h>

#include <DHT.h>


char auth[] = BLYNK_AUTH_TOKEN;

char ssid[] = "";  // type your wifi name
char pass[] = "";  // type your wifi password

BlynkTimer timer;


#define DHTPIN 27 //Connect Out pin to D2 in NODE MCU
#define DHTTYPE DHT11  
DHT dht(DHTPIN, DHTTYPE);


void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
    Blynk.virtualWrite(V0, t);
    Blynk.virtualWrite(V1, h);
    Serial.print("Temperature : ");
    Serial.print(t);
    Serial.print("    Humidity : ");
    Serial.println(h);
}
void setup()
{  
 
  Serial.begin(115200);
 

  Blynk.begin(auth, ssid, pass);
  dht.begin();
  timer.setInterval(100L, sendSensor);
 
  }

void loop()
{
  Blynk.run();
  timer.run();
 }
some changes for code (compulsory):




Comments

Popular posts from this blog

ESP 32 ADVENTURE

ESP 32 TO DHT 11