TDS meter not responding

Hi guys, i am still quite new to this and this most likely has a small problem that i am not seing but i have really tried everything on my own and i simply give up at this point..
My tds meter is not responding at all. I went to absolute basics, just connected it to 5V, GND and A1.
I downloaded a sample code just to see if i could see the ppm in the serial monitor and all i get are these question marks. Any ideas why?
I want it to work together with temp sensor but for starters it would be awesome if it responded on its own.
Sensor: LINK

#include <EEPROM.h>
#include "GravityTDS.h"

#define TdsSensorPin A1
GravityTDS gravityTds;

float temperature = 25,tdsValue = 0;

void setup()
{
    Serial.begin(115200);
    gravityTds.setPin(TdsSensorPin);
    gravityTds.setAref(5.0);  //reference voltage on ADC, default 5.0V on Arduino UNO
    gravityTds.setAdcRange(1024);  //1024 for 10bit ADC;4096 for 12bit ADC
    gravityTds.begin();  //initialization
}

void loop()
{
    //temperature = readTemperature();  //add your temperature sensor and read it
    gravityTds.setTemperature(temperature);  // set the temperature and execute temperature compensation
    gravityTds.update();  //sample and calculate
    tdsValue = gravityTds.getTdsValue();  // then get the value
    Serial.print(tdsValue,0);
    Serial.println("ppm");
    delay(1000);
}

Do you have the sense prongs in a test solution of some sort? Which Arduino?

all i get are these question marks.

Did you set the serial Baud rate correctly in the serial monitor?

Please post a close up, focused photo of your setup.

your code uses

Serial.begin(115200);

115200 baud is the modern standard.
Though the arduino-IDE is set to 9600 baud by default.

So maybe adjusting the baudraute to 115200 baud in the Ardiuni-IDE will do it.
If not post the datasheet of your TDS-meter and which exact microcontroller you are using
here is code-version which does the same with non-blocking timing
and a heartbeat-blinker with the onboard-LED
assuming that you are using Arduino Uno or Mega

#include <EEPROM.h>
#include "GravityTDS.h"

#define TdsSensorPin A1
GravityTDS gravityTds;

float temperature = 25,tdsValue = 0;

// declaring a timer-variable for NON-blocking timing
unsigned long MyTestTimer = 0; // Timer-variables MUST be of type unsigned long
unsigned long MyBlinkTimer = 0; // Timer-variables MUST be of type unsigned long
const byte onBoard_LED = 13;


void setup() {
    Serial.begin(115200);
    Serial.println("Setup-Start");
    pinMode(onBoard_LED,OUTPUT);
    gravityTds.setPin(TdsSensorPin);
    gravityTds.setAref(5.0);  //reference voltage on ADC, default 5.0V on Arduino UNO
    gravityTds.setAdcRange(1024);  //1024 for 10bit ADC;4096 for 12bit ADC
    gravityTds.begin();  //initialization
}

void loop() {
  blinkLED() 
  
  // check if 1005 milliseconds have passed by since last time
  if ( TimePeriodIsOver(MyTestTimer,1005) ) {
    // if REALLY 1005 milliseconds have passed by
    //temperature = readTemperature();  //add your temperature sensor and read it
    gravityTds.setTemperature(temperature);  // set the temperature and execute temperature compensation
    gravityTds.update();  //sample and calculate
    tdsValue = gravityTds.getTdsValue();  // then get the value
    Serial.print(tdsValue,0);
    Serial.println(" ppm");
    // delay(1000); no delay needed with TimePeriodIsOver()
}

// easy to use helper-function for non-blocking timing
boolean TimePeriodIsOver (unsigned long &startOfPeriod, unsigned long TimePeriod) {
  unsigned long currentMillis  = millis();
  if ( currentMillis - startOfPeriod >= TimePeriod ) {
    // more time than TimePeriod has elapsed since last time if-condition was true
    startOfPeriod = currentMillis; // a new period starts right here so set new starttime
    return true;
  }
  else return false;            // actual TimePeriod is NOT yet over
}


void blinkLED() {
  // check if 250 milliseconds have passed by since last time
  if ( TimePeriodIsOver(MyBlinkTimer,250) ) {
    // if REALLY 250 milliseconds have passed by
    if (digitalRead(onBoard_LED) == HIGH) ) {
      digitalWrite(onBoard_LED,LOW);       
    }
    else {
      digitalWrite(onBoard_LED,HIGH);             
    }
  }
}

best regards Stefan

1 Like

@gvidmar your provided sketch is the most overcomplicated Analog-to-Serial sketch I have ever seen

1 Like

it is more than just analog to serial. Pure serial would require just this

void setup() {
    Serial.begin(115200);
    Serial.println("Setup-Start");
}

void loop() {
 Serial.println("Hello World");    
 delay(1000); 
}

and would guide newcomers on the path of

  • stuff everything into void loop()
  • use delay() (and get problems later)

my sketch shows:

  • how to structure code into functions where each function does one thing
  • non-blocking timing encapsulted into a function which makes non-blocking timing easier to understand
  • a heartbeat-blinker to indicate code is really running
1 Like

I changed do 9600 and it works now.
Like i said its probably something really simple and stupid :sweat_smile:
Thank you!

sounds like you changed

to

Serial.begin(9600);

The other option is
to change from

to

in the serial monitor

The baudrates in the code and the baudrate of the serial monitor must match

best regards Stefan

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.