This circuit integrates an ESP32 microcontroller with a DHT11 temperature and humidity sensor. The ESP32 is a versatile microcontroller with Wi-Fi capabilities, which is used here to read data from the DHT11 sensor and send it to the Blynk IoT platform. The DHT11 sensor is a basic, low-cost digital temperature and humidity sensor that provides readings which the ESP32 processes and then transmits over the internet.
The following code is written for the ESP32 microcontroller to interface with the DHT11 sensor and send data to the Blynk platform.
#define BLYNK_PRINT Serial
/* Fill in information from Blynk Device Info here */
#define BLYNK_TEMPLATE_ID "TMPL39uRWQ5AP"
#define BLYNK_TEMPLATE_NAME "NVIDIA RTX 4090"
#define BLYNK_AUTH_TOKEN "PAUlOh6Dq3eATQVGA4OzGpCC-j00X2UC"
#include <DHT.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#define DHTPIN 27 // ESP32 pin connected to DHT11 data pin
#define DHTTYPE DHT11 // DHT11 sensor type
DHT dht(DHTPIN, DHTTYPE);
// Blynk virtual pins
#define VIRTUAL_PIN_TEMP V5
#define VIRTUAL_PIN_HUM V6
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "StarLink"; // WiFi SSID
char pass[] = "nitesh@123"; // WiFi password
void setup()
{
// Debug console
Serial.begin(115200);
dht.begin();
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
}
void loop()
{
Blynk.run();
// Read temperature and humidity
float h = dht.readHumidity();
float t = dht.readTemperature();
// Check if any reads failed
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Print values to serial monitor
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" % ");
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(" *C");
// Send values to Blynk
Blynk.virtualWrite(VIRTUAL_PIN_TEMP, t);
Blynk.virtualWrite(VIRTUAL_PIN_HUM, h);
// Wait a few seconds between measurements
delay(2000);
}
This code initializes the DHT11 sensor and sets up the Wi-Fi and Blynk configurations. It continuously reads the temperature and humidity from the DHT11 sensor and sends this data to the Blynk platform, where it can be monitored remotely. The BLYNK_PRINT
macro is used for debugging purposes, and the BLYNK_TEMPLATE_ID
, BLYNK_TEMPLATE_NAME
, and BLYNK_AUTH_TOKEN
are placeholders for the user's specific Blynk configuration. The Wi-Fi credentials should be replaced with the actual SSID and password for the network to which the ESP32 will connect.