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);
}
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);
}
}
}