Problem in digital pins while ruing the project

hello
i build my project on arduino mega 2560 + Ethernet shield and i interface the dht11, ultrasonic sensor, PIR sensor, soil moisture sensor and 3 channel relay driver circuit to it.

dht11 sensor for humidity and temp
ultrasonic for water level detection and calculating water in litters
PIR for security
soil moisture for checking water level in soil
and 3 relay driver for turning motor and light on and off

out of this dht11, ultrasonic, PIR and Soil moisture sensor working properly.
and in blynk app i connect switch to virtual pin 22,24,26 and relays to pin 22,24,26 on arduino side when i press the button then the relay is not getting oON/OFF can you help to solve this problem.

please reply as early as possible…

code


 #define BLYNK_DEBUG           // Optional, this enables lots of prints
 #define BLYNK_PRINT Serial
 #define BLYNK_PRINT Serial  
 #include "DHT.h"
 #include <SPI.h>
 #include <Ethernet.h>
 #include <BlynkSimpleEthernet.h>
 #include <SimpleTimer.h>

 #define DHTPIN 8              // what digital pin we're connected to
 #define DHTTYPE DHT11         // DHT 11

SimpleTimer timer;
DHT dht(DHTPIN, DHTTYPE);

char auth[] = "8b91df7e49e041398125c7bb34ee4236"; //project tocken

WidgetLED led1(0);
WidgetLED led2(1);
WidgetLED led3(2);
WidgetLED led4(3);
WidgetLED sec_led(9);
WidgetLED Auto_led(7);
WidgetLED Man_led(8);
WidgetLED err_led(11);
WidgetLCD lcd(4);

int pingPin = 7;              //output 10us pulse to this pin
int inPin = 6;                //measure return pulse width from this pin
int security1_pin = 9;        // pin 22 connected to PIR1 sensor
int sec1_State = 0;           // waiting for signal 
int buzzer_pin = 3;           // pin 3 connected to buzzer
int inchconv = 147;           // ratio between puls width and inches
int cmconv = 59;              // ratio between pulse width and cm
int indec, cmdec;
int fixed=120,radius=33,actual,actual_ft=0,limit=0,water_litter;
float ltr1=0,water_per=0;
long duration, inches, cm;
unsigned long volume=0;
String hight,hight_A,hight_W,water_L,litter_val;


long microsecondsToInches(long microseconds)
{
  return microseconds / inchconv;
}

long microsecondsToCentimeters(long microseconds)
{
  return microseconds / cmconv;
}

void setup()
{
    Serial.begin(9600);
    Blynk.begin(auth);
    dht.begin();
    pinMode(pingPin, OUTPUT);
    pinMode(inPin, INPUT);
    pinMode(security1_pin, INPUT);
    while (Blynk.connect() == false) 
      {
         err_led.on();// Wait until connected
      }
    led1.off();
    led2.off();
    led3.off();
    led4.off();
    sec_led.off();
    Auto_led.off();
    Man_led.off();
    err_led.off();
    digitalWrite(buzzer_pin, LOW);
    Blynk.notify("CONNECTED TO AGRICULTURE AUTOMATION SYSTEM");
    delay(5000);
    lcd.clear(); 
    lcd.print(2, 0, "WEL-COME TO"); 
    lcd.print(0, 1, "AGRICULTUR AUTO SYS.");
    delay(5000);
    lcd.clear(); 
    lcd.print(3, 0, "SYSTEM IS");
    lcd.print(2, 1, "INITIAZING..");
    delay(5000);
    lcd.clear(); 
    lcd.print(3, 0, "SYSTEM IS"); 
    lcd.print(5, 1, "ONLINE");
    delay(5000);
    lcd.clear();
}

void cal_water()
{
    // Send a short LOW followed by HIGH pulse to Trigger input:0
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(pingPin, LOW);
  duration = pulseIn(inPin, HIGH);
  inches = microsecondsToInches(duration);
  indec = ((duration - inches * inchconv) * 10 / inchconv);
  cm = microsecondsToCentimeters(duration);
  cmdec = (duration - cm * cmconv) * 10 / cmconv;
  actual= fixed - inches;
  actual_ft=actual/12;
  volume=3.14*radius*radius*actual;
  ltr1=volume/61.0237;//in foot
  hight = String(inches) + "." + String(indec);
  hight_A = String(volume) + "." + String(indec);
  hight_W = String(actual_ft) + "." + String(indec);
  water_L = String(ltr1) + "." + String(indec);
  water_per=(ltr1/6724)*100;
  lcd.print(0,0,"WATER LTR:");
  lcd.print(10,0, ltr1);
  lcd.print(14,0, " L");
  lcd.print(0,1,"WATER LEV:");
  lcd.print(10,1, water_per);
  lcd.print(15,1, "%");
  //Automation is on
  Auto_led.on();
  if(water_per < 15)
    {
       Blynk.notify("WATER LEVEL IS LOW");
       delay(1000);
    }
  if(water_per > 15 && water_per < 25)
  {
    led4.on();
  }
  if (water_per > 15 && water_per <33.33 )
    {
      led1.on();
      led2.off();
      led3.off();
      led4.off();
    }
  if (water_per > 33.33 && water_per < 66.66 )
    {
      led1.on();
      led2.on();
      led3.off();
      led4.off();
    }
  if (water_per > 66.66 )
    {
      led1.on();
      led2.on();
      led3.on();
      led4.off();
    }
}

void cal_temp()
{
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);
  if (isnan(h) || isnan(t) || isnan(f)) 
  {
    Serial.println("Failed to read from DHT sensor!");
    err_led.on();
    return;
  }
  Blynk.virtualWrite(V5, t);
  Blynk.virtualWrite(V6, h); 
  delay(10);
}
void security()
{
  sec1_State = digitalRead(security1_pin);
  if (sec1_State == HIGH)
  {
    sec_led.on();
    digitalWrite(buzzer_pin, HIGH);
  } 
  else 
  {
    sec_led.off();
    digitalWrite(buzzer_pin, LOW);
  }
}

void moisture_cal()
{
  int val,val1,val2;
  val1=analogRead(A0);
  val2=analogRead(A1);
  val=(val1+val2)/2;
  delay(100);
  Serial.print("Moisture Sensor1 Value:");
  Serial.println(val1);
  Serial.print("Moisture Sensor2 Value:");
  Serial.println(val2);
  Serial.print("Moisture average Value:");
  Serial.println(val);
  Blynk.virtualWrite(V10, val);
}
void loop()
{
  while(1)
  {
    Blynk.run();
    timer.run();
    cal_water();
    cal_temp();
    moisture_cal();
    security();
    delay(1000);
  }
}<img src="/uploads/default/original/1X/f236589f8e7aa67ed273cc646fd5ecc26e0cd0e6.png" width="300" height="500">

I’d start with removing the delay form your loop and actually use the SimpleTimer library to do timed stuff.

SimpleTimer timer;

// Run the SomeThingTimed routine every 1 second
byte timerSomeThingTimed  = timer.setInterval(1000L,   SomeThingTimed);

void setup()
{
  Blynk.begin(blabla stuff);
}

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

void SomeThingTimed()
{
  doSomethingTimed;
}

This would actually be the correct way to do timed things. Delay() can cause all sorts of really weird stuff.

ok thanks i will modify my code and try… thanks

i modify my code and according to you but still it not working properly what should i do… any idea

I think I see your confusion, in the App you have to attach the buttons to Digital pins you use, 22, 24 and 26. Not Virtual ones. Virtual pins are used in other ways. If you want direct control of your Digital pins, just attach those to your buttons.