Introduction
Measure Electrical Conductivity in Siemens, Total Dissolved Solids in PPM, Salinity in PSU and PPT.
Monitor hydroponic nutrient levels, salinity levels in aquariums or the ocean, saltwater pools, soil salinity, water quality etc.
It uses the standard Arduino Wire library to interface with the device. It’s operating principle is based on sending a very short-duration DC pulse from one probe pin and measuring the conductivity on the other pin. The conductivity is then converted to a temperature compensated Siemen. Salinity is also derived from the measure and is in PSU, PPT, and PPM.
Characteristics
- EC range: ~1.0 - ~200mS
- Salinity range: 2 - 42
- Temperature range: -2 - 35C
- Interface: I2C
- Current use: ~10mA peak, low idle current ~1mA
- Voltage range: 2.7 - 5.5V
Connections
I2C Connections
Making the connections to the device is as follows:
EC Salinity Probe | Master device |
---|---|
GND | GND |
SCL | SCL |
SDA | SDA |
VCC | 2.7 - 5V |
Temperature Probe Connections
The temperature probe should be connected as follows:
EC Salinity Probe | Temperature Probe |
---|---|
+ | VCC |
D | Data |
- | GND |
EC Probe Connections
The EC probe has two pins and can be connected either way.
Probe Selection
Any 2-electrode probe can be attached to the device.
Calibration
#include <ECSalinity.h>
EC_Salinity ec;
float calibrationSolution_mS = 2.77;
ec.setK(10.0);
ec.calibrateProbe(calibrationSolution_mS, ec.tempCoefEC);
When the device is powered for the first time, it will be uncalibrated. There are two calibration options: single and dual or double point. Single point determines a percent difference between actual readings and expected readings, then uses it to adjust the readings. Double point uses two points, a high and low, to determine the adjustment to make. The choice of single or double depends on the expected use. A small range might be better measured by single point calibration whereas a large range may be more accurate with double point.
Before any measurements can be made, to include measurements to calibrate the probe, the cell constant (K) must be specified. This number is typically 0.1, 1.0, or 10.0. The exact value may be found on the probe itself (9.988 for example). After K has been set, you can expect to see values being returned. It will not be accurate and must be calibrated.
To begin the single point calibration process, place the thermometer and probe in a calibration solution then call the calibrateProbe
function.
For best results, the probe should be cleaned with distilled water and then placed in the solution for 5-10 minutes before the probe is used. It shouldn’t be placed on the bottom or side of the solution container. Note that any turbidity, air bubbles, large particles, etc will effect readings. An unstable temperature will decrease accuracy as well.
When calibrating the probe, it is important to consider the expected temperature range. EC measurements are very temperature dependent, effecting the results by approximately 2% per degree C. The probe should be calibrated at the median expected temperature.
Likewise, the probe should be calibrated in the median expected EC range. For example, if you are planning to measure the salinity of an aquarium, you might expect readings ±5 from 35PPT (equivalent to 53mS). So a 53mS solution for calibration would be appropriate, whereas a hydroponic calibration might be 2.77mS or lower.
Another consideration is the placement of the probe. When the probe sends out a pulse of electricity, it leaves the probe in 360 degrees. If it is near a metal surface, you will experience fringing effects. The probe should be calibrated in an environment as similar as possible to the location it will be deployed in.
Single Point
float solutionEC = 53.0;
ec.calibrationProbe(solutionEC, ec.tempCoefSalinity);
After K has been set, you can calibrate the probe using a single point. For this method of calibrating, submerge the probe and wait for the readings to stabilize. Then call calibrateProbe
. The calibration information will be stored in EEPROM and is the percent difference from the measured value and the expected value.
Dual Point
Two calibration solutions are required, the low and high values you expect to measure between.
float readingLow = 51.0;
float readingHigh = 60.2;
ec.setDualPointCalibration(50.0, 58.0, readingLow, readingHigh);
ec.useDualPoint(true);
- Determine the lowest and highest measurement you expect in mS. For example, to
measure salinity in an aquarium, the lowest level you would expect to measaure might
be 30 PPT and the highest might be 38 PPT. These points are referred to as
referenceLow
andreferenceHigh
- Using the calibrated probe and a calibration solution at
referenceLow
, callmeasureEC
and see what the actual reading is. Do the same for referenceHigh. These readings are referred to asreadingLow
andreadingHigh
. As an example, thereadingLow
might be 27 andreadingHigh
might be 40. - Call
setDualPointCalibration
to save the values to the device, then enable dual point calibration. By default, the device does not use dual point. A call touseDualPoint
must be made to enable it each time the device is powered.
float solutionECLow = 53.0;
float solutionECHigh = 58.0;
ec.calibrateProbeLow(solutionECLow, ec.tempCoefSalinity);
ec.calibrateProbeHigh(solutionECHigh, ec.tempCoefSalinity);
calibrateProbeLow
and calibrateProbeHigh
can be used
to programatically determine the values.
getCalibrateHigh
and getCalibrateLow
can be used
to get the currently set reference values.
Each call to measureEC
will use the calibration to adjust
the reading. It can be disabled by ec.useDualPoint(false);
Use
float tempC = ec.measureTemp();
Once the probe has been calibrated, a reading can be taken. The device will use
the most recent temperature measurement obtained from measureTemp
if temperature
compensation is enabled.The probe should be placed in the solution to be measured and measureEC
called to start a measurement.
After the measurement is taken, the following class variables are updated:
uS
mS
S
PPM_500
PPM_640
PPM_700
salinityPSU
salinityPPT
salinityPPM
tempC
tempF
Temperature Coefficients
float pureWaterCompensation = 0.0455;
ec.measureEC(pureWaterCompensation);
ec.measureEC();
ec.measureSalinity();
If the solution to be measured is saltwater, use measureSalinity()
,
if it is freshwater, use measureEC()
. A custom temperature
coefficient can be used by passing it to measureEC()
.
Temperature Compensation
byte tempConstant = 25;
ec.setTempConstant(tempConstant);
ec.setTempConstant(0xFF);
To set the temperature used for compensation, call
setTempConstant()
and pass the temperature to use. To use the
actual temperature, pass 0xFF.
Accuracy
ec.setAccuracy(21);
The accuracy of the device can be adjusted by modifying setAccuracy
.
By default, 9 measurements are taken. A running median sort is applied and
the middle third of the nine measurements are averaged together to provide the
final result. Any number of measurements can be taken as long as it is evenly
divisible by 3. The least number of measures possible is 3.
Measurement Time
Each individual EC measurement takes 10ms. If the default accuracy is set to 9,
a call to measureEC
will return in about 90ms. A temperature measurement
takes 750ms.
Summary
Members | Descriptions |
---|---|
define EC_SALINITY |
EC Salinity probe I2C address |
define EC_MEASURE_EC |
Command to start an EC measure |
define EC_MEASURE_TEMP |
Command to measure temperature |
define EC_CALIBRATE_PROBE |
Command to calibrate the probe |
define EC_CALIBRATE_LOW |
Command to calibrate the low point of the probe |
define EC_CALIBRATE_HIGH |
Command to calibrate the high point of the probe |
define EC_VERSION_REGISTER |
version register |
define EC_MS_REGISTER |
mS register |
define EC_TEMP_REGISTER |
temperature in C register |
define EC_K_REGISTER |
cell constant register |
define EC_SOLUTION_REGISTER |
calibration solution register |
define EC_TEMPCOEF_REGISTER |
temperatue coefficient register |
define EC_CALIBRATE_REFHIGH_REGISTER |
reference low register |
define EC_CALIBRATE_REFLOW_REGISTER |
reference high register |
define EC_CALIBRATE_READHIGH_REGISTER |
reading low register |
define EC_CALIBRATE_READLOW_REGISTER |
reading high register |
define EC_CALIBRATE_OFFSET_REGISTER |
caliration offset |
define EC_SALINITY_PSU |
Salinity register |
define EC_TEMP_COMPENSATION_REGISTER |
temperature compensation register |
define EC_ACCURACY_REGISTER |
accuracy register |
define EC_CONFIG_REGISTER |
config register |
define EC_TASK_REGISTER |
task register |
define EC_EC_MEASURMENT_TIME |
delay between EC measurements |
define EC_TEMP_MEASURE_TIME |
delay for temperature measurement |
define EC_CALIBRATE_DELAY |
delay between EC calibration measurements |
define EC_DUALPOINT_CONFIG_BIT |
dual point config bit |
define EC_TEMP_COMPENSATION_CONFIG_BIT |
temperature compensation config bit |
define PSU_TO_PPT_CONVERSION |
conversion factor for PSU to PPT |
class EC_Salinity |
EC Salinity Class |
Members
define
EC_SALINITY
EC Salinity probe I2C address
define
EC_MEASURE_EC
Command to start an EC measure
define
EC_MEASURE_TEMP
Command to measure temperature
define
EC_CALIBRATE_PROBE
Command to calibrate the probe
define
EC_CALIBRATE_LOW
Command to calibrate the low point of the probe
define
EC_CALIBRATE_HIGH
Command to calibrate the high point of the probe
define
EC_VERSION_REGISTER
version register
define
EC_MS_REGISTER
mS register
define
EC_TEMP_REGISTER
temperature in C register
define
EC_K_REGISTER
cell constant register
define
EC_SOLUTION_REGISTER
calibration solution register
define
EC_TEMPCOEF_REGISTER
temperatue coefficient register
define
EC_CALIBRATE_REFHIGH_REGISTER
reference low register
define
EC_CALIBRATE_REFLOW_REGISTER
reference high register
define
EC_CALIBRATE_READHIGH_REGISTER
reading low register
define
EC_CALIBRATE_READLOW_REGISTER
reading high register
define
EC_CALIBRATE_OFFSET_REGISTER
caliration offset
define
EC_SALINITY_PSU
Salinity register
define
EC_TEMP_COMPENSATION_REGISTER
temperature compensation register
define
EC_ACCURACY_REGISTER
accuracy register
define
EC_CONFIG_REGISTER
config register
define
EC_TASK_REGISTER
task register
define
EC_EC_MEASURMENT_TIME
delay between EC measurements
define
EC_TEMP_MEASURE_TIME
delay for temperature measurement
define
EC_CALIBRATE_DELAY
delay between EC calibration measurements
define
EC_DUALPOINT_CONFIG_BIT
dual point config bit
define
EC_TEMP_COMPENSATION_CONFIG_BIT
temperature compensation config bit
define
PSU_TO_PPT_CONVERSION
conversion factor for PSU to PPT
class EC_Salinity
Members
S
public float
S
EC in Siemens
mS
public float
mS
EC in milli-Siemens
uS
public float
uS
EC in micro-Siemens
PPM_500
public long
PPM_500
Parts per million using 500 as a multiplier
PPM_640
public long
PPM_640
Parts per million using 640 as a multiplier
PPM_700
public long
PPM_700
Parts per million using 700 as a multiplier
salinityPSU
public float
salinityPSU
Salinity measured practical salinity units
salinityPPT
public float
salinityPPT
Salinity measured parts per thousand
salinityPPM
public float
salinityPPM
Salinity measured parts per million
tempC
public float
tempC
Temperature in C
tempF
public float
tempF
Temperature in F
EC_Salinity
public
EC_Salinity
()
Class constructor.
~EC_Salinity
public
~EC_Salinity
()
Class destructor.
measureEC
public float
measureEC
(float tempCoefficient)
Starts an EC measurement.
The device starst an EC measurement. The accuracy can be specified in EC_Salinity::setAccuracy.
Parameter | Description |
---|---|
tempCoefficient |
the coefficient used to compensate for temperature. |
uS, mS, S, tempC, tempF, PPM_500, PPM_640, PPM_700, salinityPPM, salinityPPT, and salinityPSU are updated
PPM is not valid if salinity is being measured
Returns: milli-Siemens
measureEC
public float
measureEC
()
Convenience function.
Calls EC_Salinity::measureEC(EC_Salinity::tempCoefEC) Returns: salinity in PSU
measureSalinity
public float
measureSalinity
()
Convenience function.
Calls EC_Salinity::measureEC(EC_Salinity::tempCoefSalinity) Returns: salinity in PSU
measureTemp
public float
measureTemp
()
Starts a temperature measurement.
A value of -127 means the device is not connected.
Returns: temperature in C
calibrateProbe
public void
calibrateProbe
(float solutionEC,float tempCoef)
Calibrates the connected probe and saves the result in EEPROM.
Parameter | Description |
---|---|
solutionEC |
the EC of the calibration solution in mS |
tempCoef
| the coefficient used to calibrate the probe
cell constant will be saved in the device’s EEPROM and used automatically thereafter
calibrateProbeLow
public void
calibrateProbeLow
(float solutionEC,float tempCoef)
Calibrates the dual-point values for the low reading and saves them in the devices’s EEPROM.
Parameter | Description |
---|---|
solutionEC |
the EC of the calibration solution in mS |
tempCoef
| the coefficient used to calibrate the probe
calibrateProbeHigh
public void
calibrateProbeHigh
(float solutionEC,float tempCoef)
Calibrates the dual-point values for the high reading and saves them in the devices’s EEPROM.
Parameter | Description |
---|---|
solutionEC |
the EC of the calibration solution in mS |
tempCoef
| the coefficient used to calibrate the probe
setDualPointCalibration
public void
setDualPointCalibration
(float refLow,float refHigh,float readLow,float readHigh)
Sets all the values for dual point calibration and saves them in the devices’s EEPROM.
Parameter | Description |
---|---|
refLow |
the reference low point |
refHigh
| the reference high point
readLow
| the measured low point in mS
readHigh
| the measured high point in mS
setK
public void
setK
(float k)
Updates the device with a new cell constant and saves it in EEPROM.
Parameter | Description |
---|---|
k |
the new cell constant |
getK
public float
getK
()
Retrieves the cell constant from the device.
Returns: the new cell constant
setAccuracy
public void
setAccuracy
(byte b)
Configures the accuracy of the device.
The device maintains a running median of values. It throws out the top and bottom third of values, then averages the middle third together to return a single value. The accuracy incrases with a high number. It must be evenly divisible by 3.
Parameter | Description |
---|---|
b |
accuracy of the device |
getAccuracy
public byte
getAccuracy
()
Retrieves the accuracy configuration of the device.
Returns: accuracy
reset
public void
reset
()
Resets all the stored calibration information.
setTempConstant
public void
setTempConstant
(byte b)
Configures device to use the provided temperature constant.
By default, the temperature constant is set to 0xFF which instructs the actual temperature to be used for temperature compensation, however any number can be specified. To use the actual temperature, restore the value to 0xFF.
Parameter | Description |
---|---|
b |
the temperature to use for compensation |
getTempConstant
public byte
getTempConstant
()
Retrieves the temperature constant.
Returns: the temperature to used for compensation
useTemperatureCompensation
public void
useTemperatureCompensation
(bool b)
Configures device to use temperature compensation or not.
Parameter | Description |
---|---|
b |
true for compensation, false to not use it |
usingTemperatureCompensation
public bool
usingTemperatureCompensation
()
Determines if temperature compensation is being used.
Returns: true if using compensation, false otherwise
useDualPoint
public void
useDualPoint
(bool b)
Configures device to use dual-point calibration.
Parameter | Description |
---|---|
b |
true for yes, false for no |
usingDualPoint
public bool
usingDualPoint
()
Determines if dual point calibration is being used.
Returns: true if using compensation, false otherwise
getCalibrateHigh
public float
getCalibrateHigh
()
Retrieves the dual-point calibration high value.
Returns: the dual-point calibration high value
getCalibrateLow
public float
getCalibrateLow
()
Retrieves the dual-point calibration low value.
Returns: the dual-point calibration low value
getCalibrateHighReading
public float
getCalibrateHighReading
()
Retrieves the dual-point calibration reading high value.
Returns: the dual-point calibration high value
getCalibrateLowReading
public float
getCalibrateLowReading
()
Retrieves the dual-point calibration reading low value.
Returns: the dual-point calibration low value
setCalibrateOffset
public void
setCalibrateOffset
(float offset)
Sets the single point offset value.
Parameter | Description |
---|---|
offset |
single point offset value |
getCalibrateOffset
public float
getCalibrateOffset
()
Retrieves the single point offset value.
Returns: single point offset value
getVersion
public byte
getVersion
()
Retrieves the firmware version of the device.
Returns: version of firmware
Generated by Moxygen