Example Code for Arduino-Calibrate and Measure TDS Value
Last revision 2026/01/15
The article offers a detailed guide on how to calibrate and measure TDS values using Arduino with the analog TDS sensor. It includes hardware and software setup, wiring instructions, sample code, and step-by-step calibration procedures, ensuring accurate sensor readings and effective temperature compensation.
Hardware Preparation
- SEN0244 Gravity: Analog TDS Sensor x 1
- DFR0216-2 DFRduino UNO R3 with IO Expansion Shield and USB Cable A-B x1
- FIT0897 Gravity: Analog Sensor Cable for Arduino(Included with SEN0244) x1
Software Preparation
Wiring Diagram

Sample Code
/***************************************************
DFRobot Gravity: Analog TDS Sensor/Meter
<https://www.dfrobot.com/wiki/index.php/Gravity:_Analog_TDS_Sensor_/_Meter_For_Arduino_SKU:_SEN0244>
***************************************************
This sample code shows how to read the tds value and calibrate it with the standard buffer solution.
707ppm(1413us/cm)@25^c standard buffer solution is recommended.
Created 2018-1-3
By Jason <[email protected]@dfrobot.com>
GNU Lesser General Public License.
See <http://www.gnu.org/licenses/> for details.
All above must be included in any redistribution.
****************************************************/
/***********Notice and Trouble shooting***************
1. This code is tested on Arduino Uno with Arduino IDE 1.0.5 r2 and 1.8.2.
2. Calibration CMD:
enter -> enter the calibration mode
cal:tds value -> calibrate with the known tds value(25^c). e.g.cal:707
exit -> save the parameters and exit the calibration mode
****************************************************/
#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);
}
Caution
-
The probe can not to be used in water above 55 degrees centigrade.
-
The probe can not be too close to the edge of the container, otherwise it will affect the reading.
-
The head and the cable of the probe are waterproof, but the connector and the signal transmitter board are not waterproof.Please pay attention to use.
Calibration Step
-
Prepare a liquid solution of known electrical conductivity (e.g., 1413us/cm standard buffer solution) or known TDS value (e.g., 707 ppm). If no standard solution is available, measure the TDS value of a liquid using a TDS pen.
-
Uploaded the sample code to your controller board, then open the serial monitor.
-
Clean the TDS probe, then dry it with absorbent paper. Insert the probe into the buffer solution of known electrical conductivity or TDS value, then stir gently and wait for stable readings. If you do not have the standard buffer solution, a TDS pen can also measure the TDS value of the liquid solution.
-
Input command
enterto enter the calibration mode.

-
Input command
cal:tds valueto calibrate the sensor.In this example, I use the 707ppm buffer solution, so I need to input commandcal:707.

-
Input command
exitto save parameters and exit.

Result
After calibration, the sensor will provide more accurate TDS readings.
Additional Information
-
Calibration commands:
enter→ Enter calibration modecal:tds value→ Calibrate with known TDS value (e.g.,cal:707for 707 ppm)exit→ Save parameters and exit
-
Normally, the TDS value is half of the electrical conductivity value, that is: TDS = EC / 2.
Was this article helpful?
