Example Code for Arduino-Conductivity Calibration and Measurement

Last revision 2026/01/13

This article offers comprehensive guidance on using Arduino for conductivity calibration and measurement, featuring example code and detailed instructions for hardware and software setup, wiring, calibration steps, and achieving accurate readings with temperature compensation.

Hardware Preparation

Software Preparation

Wiring Diagram

Analog_Conductivity_Sensor_Wiring_Diagram

Caution

  • The probe is a laboratory-grade probe. Do not immerse in liquid for a long time. Otherwise this will shorten the life of the probe.

  • Platinum black layer is attached to the surface of the sheet metal in the probe. It should avoid any object touching it. It can only be washed with distilled water, otherwise, the platinum black layer will be damaged, resulting in the inaccurate measurement.

Other Preparation Work

  • In order to ensure the measurement accuracy, it is strongly recommended to add a temperature sensor to measure the temperature and achieve automatic temperature compensation. DS18B20 waterproof temperature sensor can be used.

  • Before measuring another liquid, be sure to wash the probe and absorb residual water-drops with paper to prevent contamination of the liquid. You can flush the probe with distilled water.

  • An exteranl power supply is recommended for Arduino board to get more accurate and stable reading.

Calibration

To ensure accuracy, the probe used for the first time, or used for a period of time, needs to be calibrated.

This section uses single-point calibration and therefore requires standard buffer solutions of 12.88ms/cm.

The following tutorial shows how to operate single-point calibration.

  1. Upload the sample code to the Arduino board, then open the serial monitor, you can see the temperature and electrical conductivity. If you added a temperature sensor, be sure to write the corresponding function code and call it.

  2. Wash the probe with distilled water, then absorb the residual water-drops with paper. Insert the probe into the 12.88ms/cm standard buffer solution, stir gently, until the values are stable.

  3. After the values are stable, the single-point can be calibrated. Specific steps are as follows:

    1. Input ENTEREC command in the serial monitor to enter the calibration mode.
      Enter_Calibration_Mode
    2. Input CALEC commands to start the calibration. The program will automatically identify the standard buffer solution of 12.88ms/cm.
      One_Ponit_12.88_Calibration
    3. After the calibration, input EXITEC command to save the relevant parameters and exit the calibration mode.
      Note: Only after input EXITEC command in the serial monitor can the relevant parameters be saved.
      Quit_Calibration_Mode
  4. After completing the above steps, the single-point calibration is completed, and then the sensor can be used for actual measurement. The relevant parameters in the calibration process have been saved to the EEPROM of the main control board.

Sample Code

Download and install the DFRobot_EC10 Library.

/*
 * file DFRobot_EC10.ino
 * @ https://github.com/DFRobot/DFRobot_EC10
 *
 * This is the sample code for Gravity: Analog Electrical Conductivity Sensor / Meter Kit(K=10), SKU: DFR0300_H.
 * In order to guarantee precision, a temperature sensor such as DS18B20 is needed, to execute automatic temperature compensation.
 * You can send commands in the serial monitor to execute the calibration.
 * Serial Commands:
 *   enterec -> enter the calibration mode
 *   calec -> calibrate with the standard buffer solution, one buffer solutions(12.88ms/cm) will be automaticlly recognized
 *   exitec -> save the calibrated parameters and exit from calibration mode
 *
 * Copyright   [DFRobot](https://www.dfrobot.com), 2018
 * Copyright   GNU Lesser General Public License
 *
 * version  V1.0
 * date  2018-11
 */

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

#define EC_PIN A1
float voltage,ecValue,temperature = 25;
DFRobot_EC10 ec;

void setup()
{
  Serial.begin(115200);  
  ec.begin();
}

void loop()
{
    static unsigned long timepoint = millis();
    if(millis()-timepoint>1000U)  //time interval: 1s
    {
      timepoint = millis();
      voltage = analogRead(EC_PIN)/1024.0*5000;  // read the voltage
      Serial.print("voltage:");
      Serial.print(voltage);
      //temperature = readTemperature();  // read your temperature sensor to execute temperature compensation
      ecValue =  ec.readEC(voltage,temperature);  // convert voltage to EC with temperature compensation
      Serial.print("  temperature:");
      Serial.print(temperature,1);
      Serial.print("^C  EC:");
      Serial.print(ecValue,1);
      Serial.println("ms/cm");
    }
    ec.calibration(voltage,temperature);  // calibration process by Serail CMD
}

float readTemperature()
{
  //add your code here to get the temperature from your temperature sensor
}

Result

After uploading the sample code and following the calibration steps, you can see the temperature and electrical conductivity values in the serial monitor.

Was this article helpful?

TOP