#define BLYNK_TEMPLATE_ID "TMPL6r9MX7k0g"
#define BLYNK_DEVICE_NAME "DHT"
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <TridentTD_LineNotify.h>
#include <BlynkSimpleEsp8266.h>
#include "DHT.h"
DHT dht;
int analogPin = A0; //ประกาศตัวแปร
int val = 0;
#define LINE_TOKEN "5LeQd7C9ONP4DC32tqP63qo9XMUNWRl3Fi9DzuYh9Dh"
char auth[] = "FqO0_6irvdX4VCYQt1na0FVsa7o5H5Pn"; // ใช้ Token ที่คัดลอกจากแอพเรามาวางแทน
char ssid[] = "Def_2G";
char pass[] = "0817664814"; // กรอกรหัส WIFI แทนนะครับ
bool notifiedRain = false, notifiedHarvest = false;
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass, "blynk.iot-cm.com", 8080);
LINE.setToken(LINE_TOKEN);
Serial.println();
Serial.println("Status\tHumidity (%)\tTemperature (C)\t(F)");
dht.setup(D2); // data pin 2
pinMode(analogPin, INPUT);
}
void loop()
{
delay(dht.getMinimumSamplingPeriod());
float humidity = dht.getHumidity(); // ดึงค่าความชื้น
float temperature = dht.getTemperature(); // ดึงค่าอุณหภูมิ
float H = humidity ;
Serial.print(dht.getStatusString());
Serial.print("\t");
Serial.print(H, 1);
Serial.print("\t\t");
Serial.print(temperature, 1);
Serial.print("\t\t");
Serial.println(dht.toFahrenheit(temperature), 1);
Blynk.run();
delay(100);
Blynk.virtualWrite(V0, temperature);
Blynk.virtualWrite(V1, H);
// LINE.notify("Humidity is: "+String(humidity)+" %");
// LINE.notify("Temperature is: "+String(temperature)+" C");
val = analogRead(analogPin); //อ่านค่าสัญญาณ analog ที่ต่อกับ LDR
val = map(val, 0, 1024, 0, 100);
Serial.print("val = "); // พิมพ์ข้อมความส่งเข้าคอมพิวเตอร์ "val = "
Serial.println(val); // พิมพ์ค่าของตัวแปร val
Blynk.virtualWrite(V2, val);
// LINE.notify("Rain is: "+String(val)+" %");
if (H > 60)
{
if (!notifiedHarvest)
{
LINE.notify("อุณหภูมิไม่เหมาะสมเเก่การเก็บผลผลิต" + String(humidity) + " %");
// delay(1000);
notifiedHarvest = true;
}
}
else
{
notifiedHarvest = false;
}
if (val < 40)
{
if (!notifiedRain)
{
LINE.notify("มีฝนตกไม่เหมาะสมต่อการกรีดยาง");
notifiedRain = true;
}
}
else
{
notifiedRain = false;
}
// int rain = analogRead(D3);
// rain = map(rain,0,1023,0,100);
// Blynk.virtualWrite(V3,rain);
// Serial.println(rain);
}
ลองตามนี้ได้ไหมครับ
#define BLYNK_TEMPLATE_ID "TMPL6r9MX7k0g"
#define BLYNK_DEVICE_NAME "DHT"
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <TridentTD_LineNotify.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
DHT dht(D2, DHT22); // Assuming DHT22 sensor, use DHT11 if applicable
int analogPin = A0;
int val = 0;
#define LINE_TOKEN "5LeQd7C9ONP4DC32tqP63qo9XMUNWRl3Fi9DzuYh9Dh"
char auth[] = "FqO0_6irvdX4VCYQt1na0FVsa7o5H5Pn";
char ssid[] = "Def_2G";
char pass[] = "0817664814";
bool notifiedRain = false, notifiedHarvest = false;
void setup() {
Serial.begin(9600);
Blynk.begin(auth, ssid, pass, "blynk.iot-cm.com", 8080);
LINE.setToken(LINE_TOKEN);
dht.begin();
pinMode(analogPin, INPUT);
Serial.println("Status\tHumidity (%)\tTemperature (C)\t(F)");
}
void loop() {
delay(dht.getMinimumSamplingPeriod());
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
float H = humidity;
Serial.print(dht.getStatusString());
Serial.print("\t");
Serial.print(H, 1);
Serial.print("\t\t");
Serial.print(temperature, 1);
Serial.print("\t\t");
Serial.println(dht.toFahrenheit(temperature), 1);
Blynk.run();
delay(100);
Blynk.virtualWrite(V0, temperature);
Blynk.virtualWrite(V1, H);
val = analogRead(analogPin);
val = map(val, 0, 1023, 0, 100);
Serial.print("val = ");
Serial.println(val);
Blynk.virtualWrite(V2, val);
if (H > 60) {
if (!notifiedHarvest) {
LINE.notify("อุณหภูมิไม่เหมาะสมเเก่การเก็บผลผลิต " + String(humidity) + " %");
notifiedHarvest = true;
}
} else {
notifiedHarvest = false;
}
if (val < 40) {
if (!notifiedRain) {
LINE.notify("มีฝนตกไม่เหมาะสมต่อการกรีดยาง");
notifiedRain = true;
}
} else {
notifiedRain = false;
}
}