Error : Why my TDS Sensor get 0 ppm when I put the blynk code?

Hello this is my code for my project

#define BLYNK_TEMPLATE_ID “-----”
#define BLYNK_DEVICE_NAME “-----”
#define BLYNK_AUTH_TOKEN “------”
#define BLYNK_PRINT Serial

//#define BLYNK_DEBUG
//#define APP_DEBUG
#include <EEPROM.h>
#include “GravityTDS.h”
#include <DHT.h>
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
#include <SimpleTimer.h>

char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = “------”;
char pass[] = "----";

#define TdsSensorPin 14 
#define EEPROM_SIZE 512
#define RELAY_PIN 27 
#define DHT_SENSOR_PIN 32 
#define DHT_SENSOR_TYPE DHT11

GravityTDS gravityTds;

DHT dht_sensor(DHT_SENSOR_PIN, DHT_SENSOR_TYPE);

SimpleTimer timer;
float temperature = 25, tdsValue;
float a;
void setup()
{
Serial.begin(9600);

Blynk.begin(auth, ssid, pass);

EEPROM.begin(EEPROM_SIZE);       

gravityTds.setPin(TdsSensorPin);
gravityTds.setAref(3.3);          
gravityTds.setAdcRange(4096);     
gravityTds.begin();              

dht_sensor.begin();             

pinMode(TdsSensorPin,INPUT);
pinMode(25,OUTPUT); 
digitalWrite(25, HIGH);
}

void loop()
{
    //temperature = readTemperature();       
    gravityTds.setTemperature(temperature);   
    gravityTds.update();                    
    tdsValue = gravityTds.getTdsValue();     

     Serial.print("TDS Value:");
     Serial.print(tdsValue,0);
     Serial.println("ppm");
  
    if(tdsValue < 500)  
{
  Serial.println("Low PPM, Pump Run");
  digitalWrite(RELAY_PIN,HIGH); 
  delay(500);
}
  else if (tdsValue>500&&tdsValue<600)  
{
  Serial.println("Enough PPM, Pump Dead");
  digitalWrite(RELAY_PIN,LOW);
}
  else if(tdsValue > 600)
{
  Serial.println("Enough PPM, Pump Dead");
  digitalWrite(RELAY_PIN,LOW); 
}
 
   delay(1000); 

   
  float humid  = dht_sensor.readHumidity();

  float tempC = dht_sensor.readTemperature();    
  
  float tempF = dht_sensor.readTemperature(true); 

  Serial.print("Temp C:");
  Serial.print(tempC);
  Serial.print(",");
  Serial.print("humid:");
  Serial.print(humid);
  Serial.print("\n");

  Blynk.virtualWrite(V0, tempC);
  Blynk.virtualWrite(V1, humid);
  Blynk.virtualWrite(V14, tdsValue);
  Blynk.run();
  timer.run();
  }
 

That’s my code, can someone tell me what’s wrong? because when I only use sensor code without Blynk code it can run and read sensor well.

Simply paste your code between ``` If you don’t format your code, your topic can be deleted by moderators.
Read what you posted :joy:

1 Like

Your code is impossible to follow since you didn’t format your code correctly.

Keep your void loop() clean:

okay I’ll make a new one

@Rafli your unformatted code has been removed, because you didn’t follow the simple rules about adding triple backticks at the beginning and end.

Pete.

Yeah, thanks for the reminder I already fixed the wrong format.

First, clean your void loop, it would be like that

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

@Rafli “Need help with my project” is the correct category for this topic.

The “Issues and Errors” category is used for reporting bugs with the Blynk library, and this is a issue caused by coding errors on your part.

Pete.

So if I did that, then the old Void Loop will be in Void Setup?

No, the contents of your old void loop, minus the blocking delay(), will be in a function which is called with a timer.

I’d recommend calling that timer every 5 seconds or more, as the DHT sensors don’t respond well to higher frequency readings.

Also, it’s better to use BlynkTimer rather than SimpleTimer.

Pete.

#include <EEPROM.h>
#include “GravityTDS.h”
#include <DHT.h>
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
#include <SimpleTimer.h>

char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = “------”;
char pass[] = "----";

#define TdsSensorPin 14 
#define EEPROM_SIZE 512
#define RELAY_PIN 27 
#define DHT_SENSOR_PIN 32 
#define DHT_SENSOR_TYPE DHT11

GravityTDS gravityTds;

DHT dht_sensor(DHT_SENSOR_PIN, DHT_SENSOR_TYPE);

SimpleTimer timer;
float temperature = 25, tdsValue;
float a;

void sendSensor()
{
 gravityTds.setTemperature(temperature);   
    gravityTds.update();                    
    tdsValue = gravityTds.getTdsValue();     

     Serial.print("TDS Value:");
     Serial.print(tdsValue,0);
     Serial.println("ppm");
  
    if(tdsValue < 500)  
{
  Serial.println("Low PPM, Pump Run");
  digitalWrite(RELAY_PIN,HIGH); 
  delay(500);

}

  else if (tdsValue>500&&tdsValue<600)  
{
  Serial.println("Enough PPM, Pump Dead");
  digitalWrite(RELAY_PIN,LOW);
}
  else if(tdsValue > 600)
{
  Serial.println("Enough PPM, Pump Dead");
  digitalWrite(RELAY_PIN,LOW); 
}

 
   delay(1000); 

  float humid  = dht_sensor.readHumidity();

  float tempC = dht_sensor.readTemperature();    
  
  float tempF = dht_sensor.readTemperature(true); 

  Serial.print("Temp C:");
  Serial.print(tempC);
  Serial.print(",");
  Serial.print("humid:");
  Serial.print(humid);
  Serial.print("\n");

  Blynk.virtualWrite(V0, tempC);
  Blynk.virtualWrite(V1, humid);
  Blynk.virtualWrite(V14, tdsValue);
}

void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
   
    EEPROM.begin(EEPROM_SIZE);      
    
    gravityTds.setPin(TdsSensorPin);
    gravityTds.setAref(3.3);         
    gravityTds.setAdcRange(4096);   
    gravityTds.begin();              

    dht_sensor.begin();              \


  timer.setInterval(1000L, sendSensor);
}

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

Is it like this then?

I’m guessing that you aren’t a “detail person” then?

Pete.

1 Like
#include <EEPROM.h>
#include “GravityTDS.h”
#include <DHT.h>
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>


char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = “------”;
char pass[] = "----";

#define TdsSensorPin 14 
#define EEPROM_SIZE 512
#define RELAY_PIN 27 
#define DHT_SENSOR_PIN 32 
#define DHT_SENSOR_TYPE DHT11

GravityTDS gravityTds;

DHT dht_sensor(DHT_SENSOR_PIN, DHT_SENSOR_TYPE);

BlynkTimer timer;
float temperature = 25, tdsValue;
float a;

void sendSensor()
{
gravityTds.setTemperature(temperature);   
   gravityTds.update();                    
   tdsValue = gravityTds.getTdsValue();     

    Serial.print("TDS Value:");
    Serial.print(tdsValue,0);
    Serial.println("ppm");
 
   if(tdsValue < 500)  
{
 Serial.println("Low PPM, Pump Run");
 digitalWrite(RELAY_PIN,HIGH); 
 

}

 else if (tdsValue>500&&tdsValue<600)  
{
 Serial.println("Enough PPM, Pump Dead");
 digitalWrite(RELAY_PIN,LOW);
}
 else if(tdsValue > 600)
{
 Serial.println("Enough PPM, Pump Dead");
 digitalWrite(RELAY_PIN,LOW); 
}




 float humid  = dht_sensor.readHumidity();

 float tempC = dht_sensor.readTemperature();    
 
 float tempF = dht_sensor.readTemperature(true); 

 Serial.print("Temp C:");
 Serial.print(tempC);
 Serial.print(",");
 Serial.print("humid:");
 Serial.print(humid);
 Serial.print("\n");

 Blynk.virtualWrite(V0, tempC);
 Blynk.virtualWrite(V1, humid);
 Blynk.virtualWrite(V14, tdsValue);
}

void setup()
{
 // Debug console
 Serial.begin(9600);

 Blynk.begin(auth, ssid, pass);
  
   EEPROM.begin(EEPROM_SIZE);      
   
   gravityTds.setPin(TdsSensorPin);
   gravityTds.setAref(3.3);         
   gravityTds.setAdcRange(4096);   
   gravityTds.begin();              

   dht_sensor.begin();              \


 timer.setInterval(5000L, sendSensor);
}

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

I’ve done that, but the TDS sensor still cant read anything but when I delete the code Blynk.begin(auth, ssid, pass); and become offline then my sensor works again.

Is there could be some code that can be in the same void setup as Blynk.begin(auth, ssid, pass)?

These need to be the first lines of your sketch.

I’d also put these lines of code…

after #include <BlynkSimpleEsp32.h>

Pete.