How to calibrate PH sensor and TDS sensor using ESP32

Okay, I’ll try. Thank you

Do I have to comment/remove the WidgetLED ledglow?

You need to expand on your question, because it could be referring to the first part of what i said in my last post - in which case you don’t seem to have understood what I was saying at all.
Or it could refer to my suggestion to move away from using the WidgetLED wrapper altogether - in which case you probably need to post your revised sketch to demonstrate how you are now handling the Blynk.virtualWrites (are you using virtual pin numbers or aliases).

Pete.

I’m sorry. This is now the new uploaded code

#define BLYNK_TEMPLATE_ID "TMPL7li3j7BK"
#define BLYNK_DEVICE_NAME "PH TDS and FLOAT sensor"

#define BLYNK_FIRMWARE_VERSION        "0.1.0"

#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG

#define APP_DEBUG

// Uncomment your board, or configure a custom board in Settings.h
#define USE_WROVER_BOARD
//#define USE_TTGO_T7
//#define USE_ESP32C3_DEV_MODULE
//#define USE_ESP32S2_DEV_KIT

#include "BlynkEdgent.h"

BlynkTimer timer; // Announcing the timer
//PH SENSOR
#define PH_Pin 33          //pH meter Analog output to Arduino Analog Input 
unsigned long int avgValue;  //Store the average value of the sensor feedback
float b;
int buf[10],temp;

//FLOAT SENSOR 
int fl_Sensor1=34;
int fval1=0;
int Redled=5;

int fl_Sensor2=35;
int fval2=0;

int fl_Sensor3=25;
int fval3=0;

int fl_Sensor4=26;
int fval4=0;

//BlynkTimer timer;
int f;  // for float value to string converstion
float val; // also works with double. 
char buff2[10];
double valueString;
double PH_Val; 

int DSPIN = 14; // Dallas Temperature Sensor
int TDS_Sensor = 32;
float Aref = 2.3;

float ec_Val = 0;
unsigned int tds_value = 0;
float ecCal = 1;

//WidgetLED ledglow(V5); // add virtual LED to V5

void float_Data1()
{
// WATER LEVEL
 fval1 = digitalRead(fl_Sensor1);  
 if (fval1 == LOW) 
  { 
    digitalWrite(Redled, HIGH);
    //ledglow.on();
    Serial.println( "WATER LEVEL - HIGH"); 
  } 
  else 
  { 
    digitalWrite(Redled, LOW);
    //ledglow.off();
    Serial.println( "WATER LEVEL - LOW" );

    Blynk.virtualWrite(V5, fval1);

    if(fval1 = 1)
    {
      Blynk.logEvent("water_float","WATER Level High!");
    }
  }
}

void float_Data2()
{
// NUTRIENTS
  fval2 = digitalRead(fl_Sensor2);  
 if (fval2 == LOW) 
  { 
    digitalWrite(Redled, HIGH);
    //ledglow.on();
    Serial.println( "NUTRIENT LEVEL - HIGH"); 
  } 
  else 
  { 
    digitalWrite(Redled, LOW);
    //ledglow.off();
    Serial.println( "NUTRIENT LEVEL - LOW" ); 
  }

    Blynk.virtualWrite(V6, fval2);

    if(fval2 = 0)
    {
      Blynk.logEvent("nutrient_float","NUTRIENT Level Low!");
    }  
}

void float_Data3()
{
// ACID
fval3 = digitalRead(fl_Sensor3);  
 if (fval3 == LOW) 
  { 
    digitalWrite(Redled, HIGH);
    //ledglow.on();
    Serial.println( "PH ACID LEVEL - HIGH"); 
  } 
  else 
  { 
    digitalWrite(Redled, LOW);
    //ledglow.off();
    Serial.println( "PH ACID LEVEL - LOW" ); 
  }

    Blynk.virtualWrite(V2, fval3);

    if(fval3 = 0)
    {
      Blynk.logEvent("phacid_float","PH ACID Level Low!");
    }
}

void float_Data4()
{
// BASE
fval4 = digitalRead(fl_Sensor4);  
 if (fval4 == LOW) 
  { 
    digitalWrite(Redled, HIGH);
    //ledglow.on();
    Serial.println( "PH BASE LEVEL - HIGH"); 
  } 
  else 
  { 
    digitalWrite(Redled, LOW);
    //ledglow.off();
    Serial.println( "PH BASE LEVEL - LOW" ); 
  }

    Blynk.virtualWrite(V1, fval4);

    if(fval4 = 0)
    {
      Blynk.logEvent("phbase_float","PH BASE Level Low!");
    }  
}

void TDS_Data()
{
  // double wTemp = TempRead()* 0.0625;  // conversion accuracy is 0.0625 / LSB
  double wTemp= 27;
  float V_level= Aref / 3500.0;
  float rawEc = analogRead(TDS_Sensor) * V_level;  // Raw  data of EC
  float T_Cof = 1.0 + 0.02 * (wTemp - 25.0);  // Temperature Coefficient
  
  ec_Val = (rawEc / T_Cof) * ecCal;// temperature and calibration compensation
  tds_value = (133.42 * pow(ec_Val, 3) - 255.86 * ec_Val * ec_Val + 857.39 * ec_Val) * 0.5; 
  double Far= (((wTemp *9)/5) + 32); // Temp in Far*
  
  Serial.print("TDS:"); Serial.println(tds_value);
  Serial.print("EC:"); Serial.println(ec_Val, 2);
  Serial.print("Temperature (oC):"); Serial.println(wTemp,2);   
  Serial.print("Temperature (oF):"); Serial.println(Far,2);
  Serial.print("");

  if(tds_value < 150)
    {
      Blynk.logEvent("nutrient_warning","Low Nutrients!");
    }  
   
  //Blynk.virtualWrite(V1, wTemp);
  //Blynk.virtualWrite(V2, Far);
  Blynk.virtualWrite(V3, tds_value);
  Blynk.virtualWrite(V4, ec_Val);

}

void PH_Data()
{
  for(int i=0;i<10;i++)       //Get 10 sample value from the sensor for smooth the value
  { 
    buf[i]=analogRead(PH_Pin);
    delay(10);
  }
  for(int i=0;i<9;i++)        //sort the analog from small to large
  {
    for(int j=i+1;j<10;j++)
    {
      if(buf[i]>buf[j])
      {
        temp=buf[i];
        buf[i]=buf[j];
        buf[j]=temp;
      }
    }
  }
  avgValue=0;
  for(int i=2;i<8;i++)                      //take the average value of 6 center sample
  avgValue+=buf[i];
  float phValue=(float)avgValue*3.0/1024/14; //convert the analog into millivolt
  PH_Val=4.5*phValue;                      //convert the millivolt into pH value
  
  //PH_Val =  dtostrf(phValue, 4, 2, buff2);  //4 is mininum width, 6 is precision
  Serial.print(PH_Val);
  valueString;
  //delay(1000);
  
  
  if(PH_Val < 4.5)
    {
      Blynk.logEvent("ph_warning","PH reading low level!");
    }  
  

  Blynk.virtualWrite(V0, PH_Val);
}


void setup()
{
  Serial.begin(9600);
  delay(100);
  pinMode(fl_Sensor1, INPUT_PULLUP); // Float Sensor
  pinMode(fl_Sensor2, INPUT_PULLUP); // Float Sensor2
  pinMode(fl_Sensor3, INPUT_PULLUP); // Float Sensor3
  pinMode(fl_Sensor4, INPUT_PULLUP); // Float Sensor4
  pinMode(Redled, OUTPUT); // Red LED
  timer.setInterval(1000L, PH_Data); //timer will run every sec 
  timer.setInterval(2000L, TDS_Data); //timer will run every sec 
  timer.setInterval(3000L, float_Data1); //timer will run every sec
  timer.setInterval(4000L, float_Data2); //timer will run every sec
  timer.setInterval(5000L, float_Data3); //timer will run every sec
  timer.setInterval(6000L, float_Data4); //timer will run every sec
  BlynkEdgent.begin();
}

void loop() {
  BlynkEdgent.run();
  timer.run();        // run timer every second
}

The float_Data2, float_Data3 and float_Data4 is working but the float_Data1 is not. I connected them to their respective pins but it is not working. I also change the float sensor and still nothing. Only pins 35, 26, and 25 are just working

Update on the project. It works now.

I misplaced this bracket. It should be in below of

this line of code.

Thanks for helping pete

I have a problem about the notification. For example, when my tds sensor detects that the tds of the solution is below 150 (this is what I put in the sketch) it will notify the user which is good. Then I will put the tds sensor to different solution with high tds so that I can test the readings of the sensor. After 5-10minutes, when I put back the sensor on the previous solution, it doesn’t notify me.

On the events tab on my blynk dashboard, I set the limit to 1 message will trigger the event, then event will be sent to user only once per 1 minute.

Same with the ph sensor and float sensor

I think you mean that the NOTIFICATION will be sent to the user once per minute.
Events will be logged every 2 seconds while tds_value < 150 exceeding your 100 events per 24 hour limit in 200 seconds (3 minutes 20 seconds).
This is because you didn’t implement a flag variable to prevent this occurring, as I explained in my tutorial that I linked to in post #28

Pete.

bool ph_alert_sent = false;   // Flag to track if an alert has been sent for an over-temp event
float ph_threshold = 4.500;  // We will send an alert if the temperature exceeds this value

if(PH_Val < ph_threshold && ph_alert_sent == false)
  {
    Blynk.logEvent("ph_warning","PH reading low level!"); // trigger the notification
    ph_alert_sent = true;
  }
  else if (PH_Val >= ph_threshold)
  {
    ph_alert_sent = false;
  }

Is this right?

And this is for float sensor

int fl_Sensor1=27;
int fval1=0;
bool waterfloat_alert_sent = false;
float waterfloat_threshold = 1;

int fl_Sensor2=35;
int fval2=1;
bool nutfloat_alert_sent = false;
float nutfloat_threshold = 0;

int fl_Sensor3=25;
int fval3=1;
bool acidfloat_alert_sent = false;
float acidfloat_threshold = 0;

int fl_Sensor4=26;
int fval4=1;
bool basefloat_alert_sent = false;
float basefloat_threshold = 0;

void float_Data1()
{
// WATER LEVEL
 fval1 = digitalRead(fl_Sensor1);  
 if (fval1 == LOW) 
  { 
    digitalWrite(Redled, HIGH);
    //ledglow.on();
    Serial.println( "WATER LEVEL - HIGH"); 
  } 
  else 
  { 
    digitalWrite(Redled, LOW);
    //ledglow.off();
    Serial.println( "WATER LEVEL - LOW" );
  }

    Blynk.virtualWrite(V5, fval1);

    if(fval1 = waterfloat_threshold && waterfloat_alert_sent == false)
    {
      Blynk.logEvent("water_float","WATER Level High!"); // trigger the notification
      waterfloat_alert_sent = true;
    }
    else if (fval1 < waterfloat_threshold)
    {
      waterfloat_alert_sent = false;
    }
}

void float_Data2()
{
// NUTRIENTS
  fval2 = digitalRead(fl_Sensor2);  
 if (fval2 == LOW) 
  { 
    digitalWrite(Redled, HIGH);
    //ledglow.on();
    Serial.println( "NUTRIENT LEVEL - HIGH"); 
  } 
  else 
  { 
    digitalWrite(Redled, LOW);
    //ledglow.off();
    Serial.println( "NUTRIENT LEVEL - LOW" ); 
  }

    Blynk.virtualWrite(V6, fval2);

    if(fval2 = nutfloat_threshold && nutfloat_alert_sent == false)
    {
      Blynk.logEvent("nutrient_float","NUTRIENT Level Low!"); // trigger the notification
      nutfloat_alert_sent = true;
    }
    else if (fval2 > nutfloat_threshold)
    {
      nutfloat_alert_sent = false;
    }  
}

void float_Data3()
{
// ACID
fval3 = digitalRead(fl_Sensor3);  
 if (fval3 == LOW) 
  { 
    digitalWrite(Redled, HIGH);
    //ledglow.on();
    Serial.println( "PH ACID LEVEL - HIGH"); 
  } 
  else 
  { 
    digitalWrite(Redled, LOW);
    //ledglow.off();
    Serial.println( "PH ACID LEVEL - LOW" ); 
  }

    Blynk.virtualWrite(V2, fval3);

    if(fval3 = acidfloat_threshold && acidfloat_alert_sent == false)
    {
      Blynk.logEvent("phacid_float","PH ACID Level Low!"); // trigger the notification
      acidfloat_alert_sent = true;
    }
    else if (fval3 > acidfloat_threshold)
    {
      acidfloat_alert_sent = false;
    }  
}

void float_Data4()
{
// BASE
fval4 = digitalRead(fl_Sensor4);  
 if (fval4 == LOW) 
  { 
    digitalWrite(Redled, HIGH);
    //ledglow.on();
    Serial.println( "PH BASE LEVEL - HIGH"); 
  } 
  else 
  { 
    digitalWrite(Redled, LOW);
    //ledglow.off();
    Serial.println( "PH BASE LEVEL - LOW" ); 
  }

    Blynk.virtualWrite(V1, fval4);

    if(fval4 = 0)
    {
      Blynk.logEvent("phbase_float","PH BASE Level Low!");
    }
    if(fval4 = basefloat_threshold && basefloat_alert_sent == false)
    {
      Blynk.logEvent("phbase_float","PH BASE Level Low!"); // trigger the notification
      basefloat_alert_sent = true;
    }
    else if (fval4 > basefloat_threshold)
    {
      basefloat_alert_sent = false;
    }
      
}


Difficult to say based on poorly presented code snippets, but this looks odd…

Pete.

#define BLYNK_TEMPLATE_ID "TMPL7li3j7BK"
#define BLYNK_DEVICE_NAME "PH TDS and FLOAT sensor"

#define BLYNK_FIRMWARE_VERSION        "0.1.0"

#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG

#define APP_DEBUG

// Uncomment your board, or configure a custom board in Settings.h
#define USE_WROVER_BOARD
//#define USE_TTGO_T7
//#define USE_ESP32C3_DEV_MODULE
//#define USE_ESP32S2_DEV_KIT

#include "BlynkEdgent.h"

BlynkTimer timer; // Announcing the timer
//PH SENSOR
#define PH_Pin 33          //pH meter Analog output to Arduino Analog Input 
unsigned long int avgValue;  //Store the average value of the sensor feedback
float b;
int buf[10],temp;
int f;  // for float value to string converstion
float val; // also works with double. 
char buff2[10];
double valueString;
double PH_Val; 
bool ph_alert_sent = false;   // Flag to track if an alert has been sent for an over-temp event
float ph_threshold = 4.500;  // We will send an alert if the temperature exceeds this value

//FLOAT SENSOR 
int fl_Sensor1=27;
int fval1=0;
int Redled=5;
bool waterfloat_alert_sent = false;
float waterfloat_threshold = 1;

int fl_Sensor2=35;
int fval2=1;
bool nutfloat_alert_sent = false;
float nutfloat_threshold = 0;

int fl_Sensor3=25;
int fval3=1;
bool acidfloat_alert_sent = false;
float acidfloat_threshold = 0;

int fl_Sensor4=26;
int fval4=1;
bool basefloat_alert_sent = false;
float basefloat_threshold = 0;

//TDS SENSOR
int DSPIN = 14; // Dallas Temperature Sensor
int TDS_Sensor = 32;
float Aref = 2.3;

float ec_Val = 0;
unsigned int tds_value = 0;
float ecCal = 1;
bool tds_alert_sent = false; // Flag to track if an alert has been sent for an over-temp event
float tds_threshold = 150.00;     // We will send an alert if the temperature exceeds this value

//WidgetLED ledglow(V5); // add virtual LED to V5

void float_Data1()
{
// WATER LEVEL
 fval1 = digitalRead(fl_Sensor1);  
 if (fval1 == LOW) 
  { 
    digitalWrite(Redled, HIGH);
    //ledglow.on();
    Serial.println( "WATER LEVEL - HIGH"); 
  } 
  else 
  { 
    digitalWrite(Redled, LOW);
    //ledglow.off();
    Serial.println( "WATER LEVEL - LOW" );
  }

    Blynk.virtualWrite(V5, fval1);

    if(fval1 = waterfloat_threshold && waterfloat_alert_sent == false)
    {
      Blynk.logEvent("water_float","WATER Level High!"); // trigger the notification
      waterfloat_alert_sent = true;
    }
    else if (fval1 < waterfloat_threshold)
    {
      waterfloat_alert_sent = false;
    }
}

void float_Data2()
{
// NUTRIENTS
  fval2 = digitalRead(fl_Sensor2);  
 if (fval2 == LOW) 
  { 
    digitalWrite(Redled, HIGH);
    //ledglow.on();
    Serial.println( "NUTRIENT LEVEL - HIGH"); 
  } 
  else 
  { 
    digitalWrite(Redled, LOW);
    //ledglow.off();
    Serial.println( "NUTRIENT LEVEL - LOW" ); 
  }

    Blynk.virtualWrite(V6, fval2);

    if(fval2 = nutfloat_threshold && nutfloat_alert_sent == false)
    {
      Blynk.logEvent("nutrient_float","NUTRIENT Level Low!"); // trigger the notification
      nutfloat_alert_sent = true;
    }
    else if (fval2 > nutfloat_threshold)
    {
      nutfloat_alert_sent = false;
    }  
}

void float_Data3()
{
// ACID
fval3 = digitalRead(fl_Sensor3);  
 if (fval3 == LOW) 
  { 
    digitalWrite(Redled, HIGH);
    //ledglow.on();
    Serial.println( "PH ACID LEVEL - HIGH"); 
  } 
  else 
  { 
    digitalWrite(Redled, LOW);
    //ledglow.off();
    Serial.println( "PH ACID LEVEL - LOW" ); 
  }

    Blynk.virtualWrite(V2, fval3);

    if(fval3 = acidfloat_threshold && acidfloat_alert_sent == false)
    {
      Blynk.logEvent("phacid_float","PH ACID Level Low!"); // trigger the notification
      acidfloat_alert_sent = true;
    }
    else if (fval3 > acidfloat_threshold)
    {
      acidfloat_alert_sent = false;
    }  
}

void float_Data4()
{
// BASE
fval4 = digitalRead(fl_Sensor4);  
 if (fval4 == LOW) 
  { 
    digitalWrite(Redled, HIGH);
    //ledglow.on();
    Serial.println( "PH BASE LEVEL - HIGH"); 
  } 
  else 
  { 
    digitalWrite(Redled, LOW);
    //ledglow.off();
    Serial.println( "PH BASE LEVEL - LOW" ); 
  }

    Blynk.virtualWrite(V1, fval4);

    if(fval4 = 0)
    {
      Blynk.logEvent("phbase_float","PH BASE Level Low!");
    }
    if(fval4 = basefloat_threshold && basefloat_alert_sent == false)
    {
      Blynk.logEvent("phbase_float","PH BASE Level Low!"); // trigger the notification
      basefloat_alert_sent = true;
    }
    else if (fval4 > basefloat_threshold)
    {
      basefloat_alert_sent = false;
    }
      
}

void TDS_Data()
{
  // double wTemp = TempRead()* 0.0625;  // conversion accuracy is 0.0625 / LSB
  double wTemp= 27;
  float V_level= Aref / 3500.0;
  float rawEc = analogRead(TDS_Sensor) * V_level;  // Raw  data of EC
  float T_Cof = 1.0 + 0.02 * (wTemp - 25.0);  // Temperature Coefficient
  
  ec_Val = (rawEc / T_Cof) * ecCal;// temperature and calibration compensation
  tds_value = (133.42 * pow(ec_Val, 3) - 255.86 * ec_Val * ec_Val + 857.39 * ec_Val) * 0.5; 
  double Far= (((wTemp *9)/5) + 32); // Temp in Far*
  
  Serial.print("TDS:"); Serial.println(tds_value);
  Serial.print("EC:"); Serial.println(ec_Val, 2);
  Serial.print("Temperature (oC):"); Serial.println(wTemp,2);   
  Serial.print("Temperature (oF):"); Serial.println(Far,2);
  Serial.print("");  
   
  //Blynk.virtualWrite(V1, wTemp);
  //Blynk.virtualWrite(V2, Far);
  Blynk.virtualWrite(V3, tds_value);
  Blynk.virtualWrite(V4, ec_Val);

  if(tds_value < tds_threshold && tds_alert_sent == false)
    {
      Blynk.logEvent("nutrient_warning","Low Nutrients!"); // trigger the notification
      tds_alert_sent = true;
    }
    else if (tds_value >= tds_threshold)
    {
      tds_alert_sent = false;
    }
}

void PH_Data()
{
  for(int i=0;i<10;i++)       //Get 10 sample value from the sensor for smooth the value
  { 
    buf[i]=analogRead(PH_Pin);
    delay(10);
  }
  for(int i=0;i<9;i++)        //sort the analog from small to large
  {
    for(int j=i+1;j<10;j++)
    {
      if(buf[i]>buf[j])
      {
        temp=buf[i];
        buf[i]=buf[j];
        buf[j]=temp;
      }
    }
  }
  avgValue=0;
  for(int i=2;i<8;i++)                      //take the average value of 6 center sample
  avgValue+=buf[i];
  float phValue=(float)avgValue*3.0/1024/14; //convert the analog into millivolt
  PH_Val=4.5*phValue;                      //convert the millivolt into pH value
  
  //PH_Val =  dtostrf(phValue, 4, 2, buff2);  //4 is mininum width, 6 is precision
  Serial.print(PH_Val);
  valueString;
  //delay(1000);
  
  Blynk.virtualWrite(V0, PH_Val);
 
    
  if(PH_Val < ph_threshold && ph_alert_sent == false)
  {
    Blynk.logEvent("ph_warning","PH reading low level!"); // trigger the notification
    ph_alert_sent = true;
  }
  else if (PH_Val >= ph_threshold)
  {
    ph_alert_sent = false;
  }
}


void setup()
{
  Serial.begin(9600);
  delay(100);
  pinMode(fl_Sensor1, INPUT_PULLUP); // Float Sensor1
  pinMode(fl_Sensor2, INPUT_PULLUP); // Float Sensor2
  pinMode(fl_Sensor3, INPUT_PULLUP); // Float Sensor3
  pinMode(fl_Sensor4, INPUT_PULLUP); // Float Sensor4
  pinMode(Redled, OUTPUT); // Red LED
  timer.setInterval(6000L, PH_Data); //timer will run every sec 
  timer.setInterval(5000L, TDS_Data); //timer will run every sec 
  timer.setInterval(2000L, float_Data1); //timer will run every sec
  timer.setInterval(1000L, float_Data2); //timer will run every sec
  timer.setInterval(3000L, float_Data3); //timer will run every sec
  timer.setInterval(4000L, float_Data4); //timer will run every sec
  BlynkEdgent.begin();
}

void loop() {
  BlynkEdgent.run();
  timer.run();        // run timer every second
}