ผมต้องการจะเขียนโปรแกรมทำโปรเจ็คครับแต่ผมติดอยู่ที่ว่า อยากนำค่าความชื้นจากDHT11 นำมาใส่ในโค้ดตรงส่วน if แต่หาวิธีไม่ได้ ลองทำหลายๆอย่างแล้วแต่ก็ยังไม่ได้ รบกวนพี่ๆช่วยหน่อยครับ
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <Wire.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "XXXXXXXXXXXXX";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "AndroidAP";
char pass[] = "123654789a";
#define DHTPIN D4 // What digital pin we're connected to
// Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
SimpleTimer timer;
// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
int Relay1 = D2;
void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V5, h);
Blynk.virtualWrite(V6, t);
}
void setup()
{
pinMode(D4,INPUT);
pinMode(D2,OUTPUT);
Serial.begin(115200); // See the connection status in Serial Monitor
Blynk.begin(auth, ssid, pass);
dht.begin();
// Setup a function to be called every second
timer.setInterval(1000L, sendSensor);
Serial.begin(115200);
Serial.println();
Serial.println("Status\tHumidity (%)\tTemperature (C)\t(F)");
}
void loop()
{
int t = digitalRead(V6);
int C = digitalRead(V5);
if (V6==V7){ Serial.println ("Yes");
delay(500);
}else{
Serial.println ("No");
delay(500);
}
delay(500);
Blynk.run(); // Initiates Blynk
timer.run(); // Initiates SimpleTimer
}
ผมต้องการที่จะเปรียบเทียบค่า ความชื้น ให้ == ปุ่มกดในแอพ blynk ทำไงดีครับ
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <Wire.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "XXXXXXXXXXXXX";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "AndroidAP";
char pass[] = "123654789a";
#define DHTPIN D4 // What digital pin we're connected to
// Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
SimpleTimer timer;
// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
int Relay1 = D2;
void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V5, h);
Blynk.virtualWrite(V6, t);
}
void setup()
{
pinMode(D4,INPUT);
pinMode(D2,OUTPUT);
Serial.begin(115200); // See the connection status in Serial Monitor
Blynk.begin(auth, ssid, pass);
dht.begin();
// Setup a function to be called every second
timer.setInterval(1000L, sendSensor);
Serial.begin(115200);
Serial.println();
Serial.println("Status\tHumidity (%)\tTemperature (C)\t(F)");
}
void loop()
{
int t = digitalRead(V6);
int C = digitalRead(V5);
if (V6==V7){ Serial.println ("Yes");
delay(500);
}else{
Serial.println ("No");
delay(500);
}
delay(500);
Blynk.run(); // Initiates Blynk
timer.run(); // Initiates SimpleTimer
}