Automation of pump using a conditional

Hi,
I am working on an automatic soil watering system using blynk. I’ve made the app UI and have added a button that is connected to a 5v relay module which switches on and switches off the motor pump with the button. To make this more automatic I was thinking of adding an if-else statement that switches on and off the pump if the moisture content is low and if the conditions are dry and will switch it off if there is enough moisture. The parameter can be set as to when it should start automatically and when to stop. Here’s my code -

#define BLYNK_PRINT Serial
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
#define BLYNK_PRINT Serial
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS D2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

char auth[] = "4pd1tQr1dAilNauRpvQQR0--wfNMaoDW";
char ssid[] = "KUMAR";
char pass[] = "SRAVENKY@861614";

#define sensorPin D3
int sensorState = 0;
int lastState = 0;
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  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()
{
  Blynk.begin(auth, ssid, pass);
  pinMode(sensorPin, INPUT);
  dht.begin();

  timer.setInterval(10000L, sendSensor);
  Serial.begin(115200);
  sensors.begin();
  timer.setInterval(10000L, sendTemps);
}

void sendTemps()
{
  int sensor = analogRead(A0);
  int blynkVal = map (sensor, 1023,0, 0,100);
  Blynk.virtualWrite(V2, blynkVal);  
  sensors.requestTemperatures();
  float temp = sensors.getTempCByIndex(0);
  Serial.println(temp);
  Serial.println(sensor);
  Blynk.virtualWrite(V1, temp);

}
void loop()
{
  Blynk.run();
  timer.run();
}

Is there any way I can achieve this task?
Your help will be greatly appreciated.

A post was merged into an existing topic: Soil moisture sensor readings on Blynk