ต้องการนำมาใช้งานในการคุมอุณหภูมิและความชื้นภายตู้ หลักการคล้ายตู้ฟักไข่ครับ ใช้หลอดให้ความร้อน
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#include <DHT.h>
#include <DHT_U.h>
#include <Adafruit_Sensor.h>
#define BLYNK_PRINT Serial
// define PIN Mapping
#define PIN_RELAY1 D1 // relay 1 HEATER1
#define PIN_RELAY2 D2 // relay 2 HEATER2
#define PIN_RELAY3 D3 // relay 3 FAN HEATER
#define PIN_RELAY4 D4 // relay 4 FAN EX
#define PIN_DHT D5 // dht temperture & humidity senser
#define ON LOW
#define OFF HIGH
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Adafruit_sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#define DHTPIN PIN_DHT
#define DHTTYPEDHT22 // DHT 22 (AM2302)
class DHT_Unified dht(DHTPIN, DHTTYPE)
sensors_event_t event;
char auth[] = "c8wCkh4SsaH3x2SuwGNZckoyghQgInkV";
char ssid[] = "ECUSHOP";
char pass[] = "0656499688";
float tempSensorData = 0;
float humisensorData = 0;
bool autoCondition;
int limitHigh = 35;
int limitLow = 33;
BlynkTimer timer;
void programProcess()
{
if(autoCondition)
{
Serial.println(limitHigh) ;
Serial.println(limitLow) ;
Serial.println(tempSensorData);
if(tempSensorData < limitLow)
{
//เปิด Heater
Serial.println("codition 1");
digitalWrite(PIN_RELAY1,ON);
Blynk.virtualWrite(V11,HIGH);
}
if((tempSensorData >= limitLow) && (tempSensorData <= limitHigh))
{
//เปิด Heater
Serial.println("Condition 1");
digitalWrite(PIN_RELAY1,ON);
Blynk.virtualWrite(V11,HIGH);
}
if(tempSensorData > limitHigh)
{
// ปืก Heater
Serial.println("Condition 2");
digitalWrite(PIN_RELAY1,OFF);
Blynk.virtualWrite(V11,LOW);
}
}
}
void updatasensor ()
{
//Check temperature
dht.temperature().getEvent(&event);
if (isnan (event.temperature)) {
Serial.println(F("Error reading temperature!"));
}
else {
tempSensorData = event.temperature;
Serial.print (F("Temperature: "));
Serial.print(tempSensorData);
Serial.print (F("°C"));
Blynk.virtualWrite(V0,tempSensorData);
}
//Check humidity
dht.humidity().getEvent(&event);
if (isnan (event.relative_humidity)) {
Serial.println(F("Error reading humidity!"));
}
else {
float humiSensorData = event.relative_humidity;
Serial.print (F("humidity: "));
Serial.print(humiSensorData);
Serial.print (F("°RH"));
Blynk.virtualWrite(V1,humiSensorData);
}
}
void setup()
{
//Set Pin Mode Output
pinMode(PIN_RELAY1, OUTPUT);
pinMode(PIN_RELAY2 , OUTPUT);
pinMode(PIN_RELAY3, OUTPUT);
pinMode(PIN_RELAY4 , OUTPUT);
//set default PIN Value HIG=0,LOW=1
digitalWrite(PIN_RELAY1 , OFF);
digitalWrite(PIN_RELAY2 , OFF);
digitalWrite(PIN_RELAY3 , OFF);
digitalWrite(PIN_RELAY4 , OFF);
//Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
void updateSensor();
timer.setInterval(2500L,updateSensor);
timer.setInterval(5000L,programProcess);
}
void loop()
{
Blynk.run();
timer.run();
}