#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
const int Relay = 5;
const int analogInPin = A0;
int sensorValue = 0; // ตัวแปรค่า Analog
int outputValue = 0; // ตัวแปรสำหรับ Map เพื่อคิด %
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xSgDj9NPgBkeLZ7HqqUxbrRqwjrLcvaa";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "PUYZI";
char pass[] = "20102525";
BLYNK_WRITE(V2)
{
// You'll get HIGH/1 at startTime and LOW/0 at stopTime.
// this method will be triggered every day
// until you remove widget or stop project or
// clean stop/start fields of widget
Serial.print("Got a value: ");
Serial.println(param.asInt());
if(param.asInt() == 0)
{
digitalWrite(Relay, LOW);
}
if(param.asInt() == 1)
{
digitalWrite(Relay, HIGH);
}
}
void setup()
{
// Debug console
Serial.begin(9600);
pinMode(Relay,OUTPUT);
digitalWrite(Relay, LOW);
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
}
void loop()
{
sensorValue = analogRead(analogInPin);
outputValue = map(sensorValue, 0, 1023, 100, 0);
Blynk.virtualWrite(V83, outputValue);
Serial.print("Soil Moisture = ");
Serial.print(outputValue);
Serial.println(" %");
delay(500);
Blynk.run();
}
Soil Moisture ใช้ตัวไหนต้องเอามาดูครับ