#define BLYNK_TEMPLATE_ID "TMPLxkfmRohc"
#define BLYNK_DEVICE_NAME "SmartFarm 2"
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#define BLYNK_PRINT Serial
#define DHTPIN 15
#define DHTTYPE DHT11
//#define APP_DEBUG
#define USE_NODE_MCU_BOARD
#define USE_WROVER_BOARD
#include "BlynkEdgent.h"
#include <DHT.h>
DHT dht(DHTPIN, DHTTYPE);
int SensorPin = A0;
int SensorValue = 0;
const int moisture1 = 32;
const int moisture2 = 33;
const int moisture3 = 34;
const int moisture4 = 35;
int moisture_value1 = 0;
int moisture_value2 = 0;
int moisture_value3 = 0;
int moisture_value4 = 0;
bool switchStatus = 0; // 0 = manual,1=auto
int soilMoistureLimit = 0;
bool manualSwitch = 0;
bool solenoid1 = 0;
bool solenoid2 = 0;
BLYNK_WRITE(V0)
{
switchStatus = param.asInt(); // Get value as integer
}
// update soilMosture setting
BLYNK_WRITE(V1)
{
soilMoistureLimit = param.asInt(); // Get value as integer
}
// update manualSwitch
BLYNK_WRITE(V5)
{
manualSwitch = param.asInt();
}
BLYNK_WRITE(V6)
{
solenoid1 = param.asInt();
}
BLYNK_WRITE(V7)
{
solenoid2 = param.asInt();
}
#define PUMP D0
#define relayone D2
#define relaytwo D3
void manualAutoAction()
{
moisture_value1 = analogRead(moisture1);
moisture_value2 = analogRead(moisture2);
moisture_value3 = analogRead(moisture3);
moisture_value4 = analogRead(moisture4);
Serial.print("Moisture1 = ");
Serial.println(moisture_value1);
delay(500);
Serial.print("Moisture2 = ");
Serial.println(moisture_value2);
delay(500);
Serial.print("Moisture3 = ");
Serial.println(moisture_value3);
delay(500);
Serial.print("Moisture4 = ");
Serial.println(moisture_value4);
delay(500);
if(switchStatus)
{
// auto
if(moisture_value1 < soilMoistureLimit||(moisture_value2 < soilMoistureLimit))
{
digitalWrite(PUMP,HIGH);
digitalWrite(relayone,HIGH);
}
else
{
digitalWrite(PUMP,LOW);
digitalWrite(relayone,LOW);
}
{
if(moisture_value3 < soilMoistureLimit||(moisture_value4 < soilMoistureLimit))
{
digitalWrite(PUMP,HIGH);
digitalWrite(relaytwo,HIGH);
}
else
{
digitalWrite(PUMP,LOW);
digitalWrite(relaytwo,LOW);
}
}
}
//manual
else
{
if(manualSwitch)
{
digitalWrite(PUMP,HIGH);
}
else
{
digitalWrite(PUMP,LOW);
}
if(solenoid1)
{
digitalWrite(relayone,HIGH);
}
else
{
digitalWrite(relayone,LOW);
}
if(solenoid2)
{
digitalWrite(relaytwo,HIGH);
}
else
{
digitalWrite(relaytwo,LOW);
}
// manaul
}
}
void checkTemp()
{
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;
}
Blynk.virtualWrite(V5, h); //V5 is for Humidity
Blynk.virtualWrite(V6, t); //V6 is for Temperature
}
void setup()
{
Serial.begin(9400);
delay(100);
pinMode(PUMP,OUTPUT);
digitalWrite(PUMP,HIGH);
digitalWrite(PUMP,LOW);
pinMode(relayone,OUTPUT);
digitalWrite(relayone,HIGH);
digitalWrite(relayone,LOW);
pinMode(relaytwo,OUTPUT);
digitalWrite(relaytwo,HIGH);
digitalWrite(relaytwo,LOW);
BlynkEdgent.begin();
timer.setInterval(1000L, manualAutoAction);
timer.setInterval(10000L, checkTemp);
}
void loop() {
BlynkEdgent.run();
SensorValue = analogRead(SensorPin);
SensorValue = map(SensorValue, 0, 1023, 0, 100);
Blynk.run();
timer.run();
}
มี เซนเซอร์ครบหรือยังครับ
ครบทุกอย่างแล้วครับ
เบื้องต้นเราก็จะต่อขา data เข้ากับ 4 พินนี้บนบอร์ด นะครับ แต่ผมดูขาที่ใช้แล้วเหมือนเราจะใช้ esp32 มากกว่า 8266 นะนิ
ลองต่อดูบ้างรึยัง
ช่วยเปลี่ยนขา esp32 ให้เปน 8266 ให้หน่อยได่มั้ยครับ