Code chương trình:
#define BLYNK_TEMPLATE_ID "TMPL6PvsyMwFf"
#define BLYNK_TEMPLATE_NAME "SANG TAO KHKT 2023"
#define BLYNK_AUTH_TOKEN "ASNpA2rZPPrEL6bU4ymgCGx1ziDGRG2f"
#include <LiquidCrystal_I2C.h>
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <DHT.h>
#include <Wire.h>
#include "MQ135.h"
//Initialize the LCD display
MQ135 gasSensor = MQ135(34);
LiquidCrystal_I2C lcd(0x27, 16, 2);
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Duong Ha";
char pass[] = "1234567890";
const int ledPin = 14;
const int btnPin = 27;
#define DHTPIN 26
#define DHTTYPE DHT21
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
void sendSensor(){
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.println(t);
Blynk.virtualWrite(V6, h);
Blynk.virtualWrite(V5, t);
Serial.print("Temperature : ");
Serial.print(t);
Serial.print("Humidity : ");
Serial.println(h);
// if(t > 33){
// // Blynk.email("dientuthaihavn@gmail.com", "thong_bao", "Khi CO vuot nguong cho phep. Nguy hiem tinh mang nguoi trong xe oto");
// Blynk.logEvent("thong_bao","Khi CO vuot nguong cho phep. Nguy hiem tinh mang nguoi trong xe oto");
// }
}
void MQ135_sensor()
{
int air_quality = gasSensor.getPPM();
Serial.print("Air Quality: ");
Serial.println(air_quality);
//------------------------------
Blynk.virtualWrite(V3, air_quality );
lcd.setCursor(0, 1);
lcd.print("Air_quality:");
lcd.print(air_quality);
lcd.print(" ");
if(air_quality >3000){
// Blynk.email("dientuthaihavn@gmail.com", "thong_bao", "Khi CO vuot nguong cho phep. Nguy hiem tinh mang nguoi trong xe oto");
Blynk.logEvent("thong_bao","Khi CO vuot nguong cho phep. Nguy hiem tinh mang nguoi trong xe oto");
lcd.setCursor(0, 0);
lcd.print("Canh bao khi doc ");
delay(1500);
lcd.clear();
}
}
void setup(){
Serial.begin(115200);
lcd.init();
lcd.backlight();
Blynk.begin(auth, ssid, pass);
dht.begin();
lcd.setCursor(0, 0);
lcd.print(" Setup........ ");
for (int a = 5; a <= 10; a++) {
lcd.setCursor(a, 1);
lcd.print(".");
delay(1500);
lcd.clear();
}
timer.setInterval(2500L, sendSensor);
timer.setInterval(2500L, MQ135_sensor);
}
void loop(){
Blynk.run();
timer.run();
}
Không có nhận xét nào:
Đăng nhận xét