Hi There,
I am using Blynk with ESP8266, DHT22 3PIN, Capacitive Soil moisture Sensor v1.2 & Water pump.
I would like to water my plan based on the moisture sensor condition.
also, i want my DHT22 to read the humidity & temperature and populate to my Blynk app
I have try similar project with Arduino + Soil moisture & water pump that’s works.
but using ESP8266 is giving an error.
Please, any advice?
below is the code.
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <DHT.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";
#define WATER_PUMP 27
boolean state = false;
#define DHTPIN 2 // D4
// Uncomment whatever type you're using!
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21 // DHT 21, AM2301
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
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, t);
Blynk.virtualWrite(V6, h);
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
pinMode(WATER_PUMP, OUTPUT);
dht.begin();
// Setup a function to be called every second
timer.setInterval(1000L, sendSensor);
}
void loop()
{
Blynk.run();
}
BLYNK_WRITE(V1)
{
if (state == false) {
state = true;
Blynk.notify("You just watered your plant.");
digitalWrite(WATER_PUMP,HIGH);
delay(1000);
}
else {
state = false;
digitalWrite(WATER_PUMP,LOW);
}
}
void loop()