Back to Tutorial

ESP32 with DHT11 and BLYNK Dashboard

ESP32 and DHT11 with BLYNK

ESP32 and DHT11 with BLYNK: A Step-by-Step Guide

Hardware Setup:

  1. ESP32 Board: Obtain an ESP32 development board (e.g., ESP32-WROOM-32).
  2. DHT11 Sensor: Acquire a DHT11 temperature and humidity sensor.
  3. Breadboard: Use a breadboard to connect the ESP32 and DHT11.
  4. Resistors: Prepare 4.7kΩ resistors for the DHT11’s data and VCC pins.
  5. Jumpers: Use male-to-female jumpers to connect the components on the breadboard.

iotwebplanet.com - 1

Wiring Diagram:

ESP32 Pins | DHT11 Pins
------------|-----------
3.3V         | VCC
GND          | GND
D1 (GPIO5)   | DATA

Software Setup:

  1. Arduino IDE: Install the Arduino IDE and the ESP32 board support package.
  2. BLYNK Library: Download and install the BLYNK library from the Arduino Library Manager.
  3. DHT11 Library: Install the DHT11 library from the Arduino Library Manager.

Code:

//C++

#define BLYNK_TEMPLATE_ID “XXXX”
#define BLYNK_TEMPLATE_NAME “XXXX”
#define BLYNK_AUTH_TOKEN “XXXXX”

#include <DHT.h>
#include <Wire.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

#define DHTPIN 15
#define DHTTYPE DHT11

DHT dht(DHTPIN,DHTTYPE);

float temp=0;
float hum=0;

BlynkTimer timer; // Creating a timer object

char ssid[] = “SSID”;
char pass[] = “PSW”;

void setup() {
dht.begin();
timer.setInterval(1000L, myTimerEvent); //Staring a timer
Blynk.begin(BLYNK_AUTH_TOKEN,ssid,pass);

}

void myTimerEvent() // This loop defines what happens when timer is triggered
{

Blynk.virtualWrite(V0,temp);
Blynk.virtualWrite(V1, hum);

}

void loop()
{
temp=dht.readTemperature();

hum=dht.readHumidity();
Blynk.run();
timer.run(); // runs the timer in the loop
}

Explanation:

  1. Include Necessary Libraries: Include the ESP32WiFi, BlynkSimpleEsp32, and DHT11 libraries.
  2. Define Constants: Define the BLYNK authentication token, DHT11 pin, and WiFi credentials.
  3. Create DHT11 Object: Create a DHT11 object.
  4. Setup Function: Initialize serial communication, BLYNK, and DHT11.
  5. Loop Function:
    • Run BLYNK.
    • Read humidity and temperature from the DHT11.
    • Check for errors.
    • Print sensor readings to the serial monitor.
    • Send sensor data to BLYNK virtual pins.

Additional Tips:

  • Replace YOUR_BLYNK_AUTH_TOKEN with your actual BLYNK authentication token.
  • Ensure correct WiFi credentials.
  • Use a suitable power supply for the ESP32 and DHT11.
  • Experiment with different delay values to optimize data refresh rate.
  • Consider adding error handling and data validation to improve reliability.
  • Explore BLYNK’s features for data visualization, notifications, and more.

By following these steps and incorporating the additional tips, you can successfully integrate an ESP32 and DHT11 sensor with BLYNK to monitor temperature and humidity and visualize the data on your smartphone or other devices.

Share this post

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to Tutorial