0% found this document useful (0 votes)
3 views3 pages

Blynk DHT11 Temperature Monitor Code

The document contains an Arduino sketch for an ESP32 that reads temperature and humidity data from a DHT11 sensor and displays it on a LiquidCrystal LCD. It connects to WiFi and uses Blynk to send the sensor data to a mobile application. The code includes configuration for the DHT sensor, LCD, WiFi credentials, and Blynk authentication token.

Uploaded by

đạt
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Blynk DHT11 Temperature Monitor Code

The document contains an Arduino sketch for an ESP32 that reads temperature and humidity data from a DHT11 sensor and displays it on a LiquidCrystal LCD. It connects to WiFi and uses Blynk to send the sensor data to a mobile application. The code includes configuration for the DHT sensor, LCD, WiFi credentials, and Blynk authentication token.

Uploaded by

đạt
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

#define BLYNK_TEMPLATE_ID "TMPL12345" // Thay bằng Template ID từ Blynk

#define BLYNK_TEMPLATE_NAME "nhietdo" // Thay bằng Template Name từ Blynk


#define BLYNK_AUTH_TOKEN "d9e7f9c0a4b84b45a1d2c9e123456789" // Blynk Auth
Token
#include <Wire.h>
#include <LiquidCrystal.h>
#include <DHT.h>
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
// DHT11 Pin Configuration
#define DHTPIN 12 // GPIO pin where the DHT11 is connected
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

// LCD Pin Configuration (RS, EN, D4, D5, D6, D7)


LiquidCrystal lcd(13, 14, 7, 9, 10, 11);

// WiFi and Blynk Configuration


char auth[] = "d9e7f9c0a4b84b45a1d2c9e123456789"; // Blynk Auth Token
char ssid[] = "VIETTEL_LUUTHU"; // WiFi SSID
char pass[] = "Thu180979"; // WiFi Password

// Timer for sending data to Blynk


BlynkTimer timer;

void sendSensorDataToBlynk() {
float temp = [Link]();
float hum = [Link]();

if (isnan(temp) || isnan(hum)) {
[Link]("Failed to read from DHT sensor!");
return;
}

// Send data to Blynk


[Link](V0, temp); // Send temperature to virtual pin V0
[Link](V1, hum); // Send humidity to virtual pin V1
}

void setup() {
// Serial Monitor
[Link](115200);

// Initialize DHT sensor


[Link]();
// Initialize LCD
[Link](16, 2); // 16x2 LCD
[Link]("Initializing...");

// Connect to WiFi
[Link](ssid, pass);
while ([Link]() != WL_CONNECTED) {
delay(1000);
[Link]("Connecting to WiFi...");
[Link](0, 1);
[Link]("WiFi Connecting ");
}
[Link]("Connected to WiFi");
[Link]();
[Link]("WiFi Connected");

// Initialize Blynk
[Link](auth, ssid, pass);

// Setup Blynk timer


[Link](2000L, sendSensorDataToBlynk);
}

void loop() {
[Link]();
[Link]();

float temp = [Link]();


float hum = [Link]();

if (!isnan(temp) && !isnan(hum)) {


// Display data on LCD
[Link](0, 0);
[Link]("Temp: ");
[Link](temp);
[Link](" C");

[Link](0, 1);
[Link]("Hum: ");
[Link](hum);
[Link](" %");
} else {
[Link]();
[Link]("Sensor Error");
[Link]("Failed to read from DHT sensor!");
}

delay(2000); // Delay for LCD update


}

You might also like