Problem in reading/displaying sensor data

no i did not work

i tried with 10000 but i did not resolve.
there is no serial output, it is like void loop is not visiting sensor function.

Change your Display widgets to terminal widgets on Blynk and try this :

#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
float moisture[10],Ph[10],light[10],sum_Moisture=0, sum_Ph=0, sum_light=0,moistureAvg=0,Avg_Ph=0,Avg_light=0 ;
   //Your Project authentication key
char auth[] = "*********";  
//char ssid[] = "*********;
//char pass[] = "*********";  // Corresponding Password
#include <SoftwareSerial.h>

SoftwareSerial EspSerial(2, 3); //RXPin, TXPin 
//SoftwareSerial ss(RXPin, TXPin);
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);



BlynkTimer sensorTimer;
WidgetTerminal terminal1(V5);
WidgetTerminal terminal2(V6);
WidgetTerminal terminal3(V7);

void setup()
{
  pinMode(A0,INPUT);
  pinMode(A2,INPUT);
  Serial.begin(9600);
  EspSerial.begin(ESP8266_BAUD);
  delay(10);
  Blynk.begin(auth, wifi, ssid, pass); 
 sensorTimer.setInterval(2000L, sensor); 
}

 void sensor()
{
   sum_Moisture=0, sum_Ph=0, sum_light=0,moistureAvg=0,Avg_Ph=0,Avg_light=0 ;
    for (int i=0; i<10; i++){
    moisture[i] = analogRead(A0);
    moisture[i]=moisture[i]*5/1023; 
    Ph[i]=analogRead(A2);
    Ph[i]=Ph[i]*5/1023;
  sum_Moisture=sum_Moisture+moisture[i];
  sum_Ph=sum_Ph+Ph[i];
  }
   moistureAvg=sum_Moisture/10;
  Avg_Ph=sum_Ph/10; 
//  Blynk.virtualWrite(V5,moistureAvg);
  //Blynk.virtualWrite(V6,Avg_Ph);

// if conditions
    if(Avg_Ph>=0.38){
     Serial.println("Ph < 3, Not Suitable");
  //  Blynk.virtualWrite(V5,"Ph < 3, Not Suitable");
     terminal1.println("Ph < 3, Not Suitable");
    }
    else if(Avg_Ph<=0.37&Avg_Ph>=0.36){
     Serial.println("Ph:3-4, Not Suitable");
    // Blynk.virtualWrite(V5,"Ph:3-4, Not Suitable");
     terminal1.println("Ph:3-4, Not Suitable");
    }
     else if(Avg_Ph<=0.35&Avg_Ph>=0.34){
     Serial.println("Ph:4-5, Not Suitable");
   //  Blynk.virtualWrite(V5,"Ph:4-5, Not Suitable");
     terminal1.println("Ph:4-5, Not Suitable");
    }
    else if(Avg_Ph<=0.33&Avg_Ph>=0.32){
     Serial.println("Ph:5-6, Not Suitable");
   //  Blynk.virtualWrite(V5,"Ph:5-6, Not Suitable");
     terminal1.println("Ph:5-6, Not Suitable");
    }
    else if(Avg_Ph<=0.31&Avg_Ph>=0.20){
     Serial.println("Ph:6-7, Suitable");
  //   Blynk.virtualWrite(V5,"Ph:6-7, Suitable");
     terminal1.println("Ph:6-7, Suitable");
    }
     else{
     Serial.println("Ph:7-8, Suitable");
   //  Blynk.virtualWrite(V5,"Ph:7-8, Suitable");
     terminal1.println("Ph:7-8, Suitable");
     }

     if(moistureAvg<=0.65){
     Serial.println("soil is too much DRY");
      //   Blynk.virtualWrite(V6,"soil is too much DRY");
       terminal2.println("soil is too much DRY");
      }
    else if(moistureAvg>=0.66 & moistureAvg<=0.68){
     Serial.println("soil is much DRY");
      //   Blynk.virtualWrite(V6, "soil is much DRY");
    terminal2.println("soil is much DRY");
    }

    else if(moistureAvg>=0.69 & moistureAvg<=0.73){
     Serial.println("soil is DRY");
       //  Blynk.virtualWrite(V6,"soil is DRY");
    terminal2.println("soil is DRY");
    }
    else if(moistureAvg>=0.74 & moistureAvg<=0.76){
     Serial.println("soil is least moist");
      //   Blynk.virtualWrite(V6,"soil is least moist");
    terminal2.println("soil is least moist");
    }
  else if(moistureAvg>=0.77 & moistureAvg<=0.79){
     Serial.println("soil is Partially moist");
       // Blynk.virtualWrite(V6,"soil is Partially moist");
    terminal2.println("soil is Partially moist");
      }
     else if(moistureAvg>=0.80 & moistureAvg<=0.82){
     Serial.println("soil is moist");
  //   Blynk.virtualWrite(V6,"soil is moist");
   terminal2.println("soil is moist");
    }
     else if(moistureAvg>=0.83 & moistureAvg<=0.85){
     Serial.println("soil is least wet");
   //  Blynk.virtualWrite(V6,"soil is least wet");
   terminal2.println("soil is least wet");
    }
     else if(moistureAvg>=0.86 & moistureAvg<=0.88){
     Serial.println("soil is partially wet");
   //  Blynk.virtualWrite(V6,"soil is partially wet");
   terminal2.println("soil is partially wet");
    }
    else {
     Serial.println("soil is fully wet");
   //  Blynk.virtualWrite(V6,"soil is fully wet");
  terminal2.println("soil is fully wet");
    }
    }



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

You will need to replace 3 display widgets with 3 terminal widgets and assign V5, V6, V7 pins to them. Here is the app layout

If it does not work I am at my wits end. Sorry, I couldn’t help !

@Mustafeez, when you say:

do you mean that there is nothing at all? - No Blynk connection messages, no Ping time etc?
The answer to this question is very important!

You said in your initial post that without the if statements it did display daya, but you wanted to make that data morte user friendly.
Can you go back to your original code, without theif statements, and check that this still works?
If it does then can you please post that code?

Pete.

sc
Hi Pete
sorry, yesterday i ran out of daily replies.
above is the screen shot of serial output when it does not work means when i include if conditions.
here is the code when it works means when i do not include if statements

#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
float moisture[10],Ph[10],light[10],sum_Moisture=0, sum_Ph=0, sum_light=0,moistureAvg=0,Avg_Ph=0,Avg_light=0 ;
char auth[] = "*******"; 
char ssid[] = "*******";
char pass[] = "*********"; 

#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); //RXPin, TXPin 
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);

void setup()
{
  //Serial.println("so far 2");
  pinMode(A0,INPUT);
  pinMode(A2,INPUT);
  Serial.begin(9600);
  EspSerial.begin(ESP8266_BAUD);
  delay(10);
  Blynk.begin(auth, wifi, ssid, pass);  
}

void loop()
{
sensor();
Blynk.run();   
}
 
void sensor()
{
   //Serial.println("so far 3");
   sum_Moisture=0, sum_Ph=0, sum_light=0,moistureAvg=0,Avg_Ph=0,Avg_light=0 ;
    for (int i=0; i<10; i++){
    moisture[i] = analogRead(A0);
    moisture[i]=moisture[i]*5/1023; 
    Ph[i]=analogRead(A2);
    Ph[i]=Ph[i]*5/1023;
  sum_Moisture=sum_Moisture+moisture[i];
  sum_Ph=sum_Ph+Ph[i];
  }
   moistureAvg=sum_Moisture/10;
  Avg_Ph=sum_Ph/10; 
  Blynk.virtualWrite(V5,moistureAvg);
  Blynk.virtualWrite(V6,Avg_Ph);

    }

Okay, I hate nested else if statements, i find them so difficult to evaluate in my head.

However, the first thing that leaps out is that you should have double ampersands in your comparison statements otherwise C++ does a bitwise comparison.

this means that:

else if(Avg_Ph<=0.37&Avg_Ph>=0.36){

should be this:

else if(Avg_Ph<=0.37 && Avg_Ph>=0.36){

If that doesn’t fix the problem then I would put serial print statements immediately before your “if conditions” section that print-out the values of Avg_Ph and moistureAvg so you can see which (if any) of the nested if / else if statements should be evaluating as true.

Pete.

i applied double ampersands and also checked the true evaluation of if / else if but the issue is still there.
i just observed that my project in mobile app is continuously connecting and disconnecting, when i apply if statements, i think due to this void loop is unable to visit sensor function.

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

As mentioned and shown in previous posts. The sensor() function needs to be in a timed function.

I think it’s time to post your full code, and the corresponding serial output.

Pete.