BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

ESP8266, Blynk, DHT22 3PIN, Capachitive Soil moinsture Sensor v1.2 & water pump

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()

Not surprising, as you’re using the ESP32 library…

Pete…

1 Like

Excellent! thanks Pete.

Shall I replace syntax with 32 to
#include <BlynkSimpleEsp8266.h>

I’ll try that asap. Thx

Regards
KM

That’s the correct library for your board, so yes.

Pete.

1 Like

Cool, I’ll try that update on the outcome :wink:

Regards
KM