Example Code for Arduino-Electrical Conductivity Calibration and Measurement

Last revision 2026/01/13

This guide explains how to calibrate and measure electrical conductivity using Arduino, covering hardware setup, software requirements, and detailed calibration steps for precise measurements with two-point calibration using standard buffer solutions.

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.

  • To ensure accuracy, the probe needs to be calibrated for its first use and after not being used for an extended period of time. This tutorial uses two-point calibration and therefore requires standard buffer solutions of 1413us/cm and 12.88ms/cm.

Sample Code

Please download DFRobot_EC Library first,then install it.

/*
 * file DFRobot_EC.ino
 * @ https://github.com/DFRobot/DFRobot_EC
 *
 * This is the sample code for Gravity: Analog Electrical Conductivity Sensor / Meter Kit V2 (K=1.0), SKU: DFR0300.
 * 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, two buffer solutions(1413us/cm and 12.88ms/cm) will be automaticlly recognized
 *   exitec -> save the calibrated parameters and exit from calibration mode
 *
 * Copyright   [DFRobot](http://www.dfrobot.com), 2018
 * Copyright   GNU Lesser General Public License
 *
 * version  V1.0
 * date  2018-03-21
 */

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

#define EC_PIN A1
float voltage,ecValue,temperature = 25;
DFRobot_EC 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
      //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,2);
      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
}

Calibration

To ensure accuracy, the probe needs to be calibrated for its first use and after not being used for an extended period of time.

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

The following tutorial shows how to operate two-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 and call it.

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

  3. After the values are stable, the first point can be calibrated:

    • 1. Input enterec command in the serial monitor to enter the calibration mode.
      DFR0300V2_CAL1.jpg
    • 2. Input calec commands to start the calibration. The program will automatically identify which of the two standard buffer solutions is present: either 1413us/cm and 12.88ms/cm. In this step, the standard buffer solution is 1413us/cm.
      DFR0300V2_CAL2.jpg
    • 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.
        DFR0300V2_CAL3.jpg
    • 4.After the above steps, the first point calibration is completed. The second point calibration will be performed below.
  4. 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.

  5. After the values are stable, the second point can be calibrated:

    • 1. Input enterec command in the serial monitor to enter the calibration mode.
    • 2. Input calec commands to start the calibration. The program will automatically identify which of the two standard buffer solutions is present: either 1413us/cm and 12.88ms/cm. In this step, the standard buffer solution is 12.88ms/cm.
    • 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.
    • 4.After the above steps, the second point calibration is completed.
  6. After completing the above steps, the two-point calibration is completed, and then it can be used for actual measurement. The relevant parameters in the calibration process have been saved to the EEPROM of the main control board.

Result

Once the sample code has been uploaded and two-point calibration is complete, this sensor will be able to accurately measure conductivity.

Additional Information

  • Serial Commands for calibration:

  • enterec -> enter the calibration mode

  • calec -> calibrate with the standard buffer solution, two buffer solutions(1413us/cm and 12.88ms/cm) will be automaticlly recognized\

  • exitec -> save the calibrated parameters and exit from calibration mode

  • Old Version Wiki(V1)

Was this article helpful?

TOP