How can i connect dht11 and two moisture sensor.. to turn on the pump as for when the temperature high, the moisture low

i am using arduino mega, 2 soil moisture sensor, 1 DHT11, relay, wifi shield and blynk…
this is my code… i am also searching for how to convert moisture sensor reading to percentage,…

#define BLYNK_PRINT Serial      //declaration to use Blynk

#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <DHT.h> 
#define DHTPIN 5                // Connect the signal pin of DHT11 sensor to digital pin 5
#define DHTTYPE DHT11 
int sensor_pin = A0;  //soil moisture sensor 1
int sensor1 = A1;     //soil moisture sensor 2
int output_value ;  //output value from soil moisture sensor 1
int sensor_value ;  //output value from soil moisture sensor 2
int Pump=13;

char auth[] = " f79df2aeed1945bab751cf4df80f246b"; // Author Token from email

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "TKP Class Room";
char pass[] = "TkpH0lding";

// Hardware Serial on Mega, Leonardo, Micro...
#define EspSerial Serial

// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);

BlynkTimer timer;
void sendSensor()
  output_value= analogRead(sensor_pin);
  sensor_value= analogRead(sensor1);
  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!");
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V6, h);
  Blynk.virtualWrite(V8, t);
  Blynk.virtualWrite(V9, output_value);
  Blynk.virtualWrite(V10, sensor_value);
//Blynk.virtualWrite(V7,  output_value );

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void myTimerEvent()
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, millis() / 1000);
void pump(){
  output_value= analogRead(sensor_pin);
  sensor_value= analogRead(sensor1);


void setup()
  // Debug console
  // Set ESP8266 baud rate

  Blynk.begin(auth, wifi, ssid, pass);
  // Setup a function to be called every second
  timer.setInterval(1000L, myTimerEvent);

void loop()
    output_value= analogRead(sensor_pin);
  sendSensor();; // Initiates BlynkTimer

Hello, I properly formatted your pasted code as per the directions you erased in order to post theis :wink:

Not sure of your question… we are here to help you learn how Blynk works, not teach programming.

When using Blynk, it has it’s own communication an timing needs, so you should be running your pump() and sendSensor() functions on their own timers and NOT in the main void loop()

oh… okay… sory… but i also have problem when connecting blynk… the device shows not connected although the wifi we use is strong… at first it connected but past 3 days we cannot connect at all… is there anything related to my coding or something else?

You may want to review this