Arduino Salinity Sensor Calibration

Arduino Salinity Sensor Calibration

Calibrating Atlas Scientific's EZO salinity/conductivity K1.0 sensor using Arduino Uno.

  • 253 views
  • 0 comments
  • 1 respect

Components and supplies

Apps and online services

About this project

Calibration Theory

The most important part of calibration is watching the readings during the calibration process. It is easiest to calibrate the device in its default state (UART mode, with continuous readings enabled). Switching the device to I2C mode after calibration will not affect the stored calibration. If the device must be calibrated in I2C mode, be sure to continuously request readings so you can see the output from the probe. In this tutorial, the calibration will be done in UART mode.

Single point or Two point calibration

The Atlas EZO conductivity circuit has a flexible calibration protocol, allowing for single-point or two-point calibration.

Single point calibration will provide a narrow range of accuracy.

Two-point calibration will provide a wide range of accuracy.

Assemble Hardware

The kit includes 1 EZO EC circuit, 1 K1.0 conductivity probe, 1 female BNC connector, 4oz calibration solutions: 12880µS and 80000µS, 1 optional inline voltage isolator.

Ensure that the conductivity circuit is in UART mode. For instructions on switching between protocols, refer to the following LINK.

Use the breadboard to mount the circuit and BNC connector. Wire the conductivity circuit to the Arduino Uno as shown in the schematic above and connect the probe to the BNC connector.

Load Program Onto Arduino Uno

a) Download the sample code from this LINK. It will be in a folder titled "arduino_UNO_EC_sample_code".

b) Connect the Arduino to your computer.

c) Open the code downloaded from step a, in your Arduino IDE. If you do not have the IDE you can download it from HERE.

d) Compile and upload the code to Arduino.

e) Open the serial monitor. For access go to Tools -> Serial Monitor or press Ctrl+Shift+M on your keyboard. Set the baud rate to 9600 and select "Carriage return". You should now be able to communicate with the conductivity circuit. As a test, enter the command i which will return the device information.

Enable Continuous Reading And Set Probe Type

a) Ensure that the probe's cap is removed and that it is dry. With the probe in air, send the command c, 1 which will enable continuous readings once per second.

b) If your probe is not K1.0 (default), then set the probe type using the command k, n where n is the k value of your probe. In this tutorial, we will be using a K1.0 probe. The probe type can be confirmed with command k, ?

Dry Calibration

Ensure that the probe is dry. With the probe in the air send the command cal,dry

Even though you may see readings of 0.00 before issuing the command, it is still necessary to do a dry calibration.

Two Point Calibration - low point

a) Pour some of the 12880µS calibration solution into a cup. Ensure that there is enough solution to cover the sensing area of the probe.

b) Place the probe into the cup and stir it around to remove trapped air. Let the probe sit in the solution. Readings maybe off by +/- 40% from the stated value of the calibration solution.

c) Wait for readings to stabilize (small movement from one reading to the next is normal) and send the command cal, low, 12880

Note: The readings will not change after this command is entered.

Two Point Calibration - high point

a) Rinse off the probe before calibrating to the high point.

b) Pour some of the 80000µS calibration solution into a cup. Ensure that there is enough solution to cover the sensing area of the probe.

c) Place the probe into the cup and stir it around to remove trapped air. Let the probe sit in the solution. Readings maybe off by +/- 40% from the stated value of the calibration solution.

d) Wait for readings to stabilize (small movement from one reading to the next is normal) and send the command cal, high, 80000

Note: The readings will change after this command is entered. Calibration is now complete.

Single Point Calibration

a) Pour some calibration solution into a cup (μS value of your choice). Ensure that there is enough solution to cover the sensing area of the probe.

b) Place the probe into the cup and stir it around to remove trapped air. Let the probe sit in the solution. Readings maybe off by +/- 40% from the stated value of the calibration solution.

c) Wait for readings to stabilize (small movement from one reading to the next is normal) and send the command cal, n where n is the value of the calibration solution.

Note: Readings will change after the command is entered. Calibration is now complete.

Temperature Compensation During Calibration

Temperature has a significant effect on conductivity/salinity readings. The EZO conductivity circuit has its temperature set to 25 ̊ C as the default.

At no point should you change the default temperature compensation during calibration.

Code

ec sensor calibration codeC/C++
//This code was written to be easy to understand.
									 
//Modify this code as you see fit.
//This code will output data to the Arduino serial monitor.
//Type commands into the Arduino serial monitor to control the EC circuit.
//This code was written in the Arduino 1.8.9 IDE
//An Arduino UNO was used to test this code.
//This code was last tested 6/2019


#include <SoftwareSerial.h>                           //we have to include the SoftwareSerial library, or else we can't use it
#define rx 2                                          //define what pin rx is going to be
#define tx 3                                          //define what pin tx is going to be

SoftwareSerial myserial(rx, tx);                      //define how the soft serial port is going to work


String inputstring = "";                              //a string to hold incoming data from the PC
String sensorstring = "";                             //a string to hold the data from the Atlas Scientific product
boolean input_string_complete = false;                //have we received all the data from the PC
boolean sensor_string_complete = false;               //have we received all the data from the Atlas Scientific product




void setup() {                                        //set up the hardware
  Serial.begin(9600);                                 //set baud rate for the hardware serial port_0 to 9600
  myserial.begin(9600);                               //set baud rate for the software serial port to 9600
  inputstring.reserve(10);                            //set aside some bytes for receiving data from the PC
  sensorstring.reserve(30);                           //set aside some bytes for receiving data from Atlas Scientific product
}


void serialEvent() {                                  //if the hardware serial port_0 receives a char
  inputstring = Serial.readStringUntil(13);           //read the string until we see a <CR>
  input_string_complete = true;                       //set the flag used to tell if we have received a completed string from the PC
}


void loop() {                                         //here we go...

  if (input_string_complete == true) {                //if a string from the PC has been received in its entirety
    myserial.print(inputstring);                      //send that string to the Atlas Scientific product
    myserial.print('\r');                             //add a <CR> to the end of the string
    inputstring = "";                                 //clear the string
    input_string_complete = false;                    //reset the flag used to tell if we have received a completed string from the PC
  }

  if (myserial.available() > 0) {                     //if we see that the Atlas Scientific product has sent a character
    char inchar = (char)myserial.read();              //get the char we just received
    sensorstring += inchar;                           //add the char to the var called sensorstring
    if (inchar == '\r') {                             //if the incoming character is a <CR>
      sensor_string_complete = true;                  //set the flag
    }
  }


  if (sensor_string_complete == true) {               //if a string from the Atlas Scientific product has been received in its entirety
    if (isdigit(sensorstring[0]) == false) {          //if the first character in the string is a digit
      Serial.println(sensorstring);                   //send that string to the PC's serial monitor
    }
    else                                              //if the first character in the string is NOT a digit
    {
      print_EC_data();                                //then call this function 
    }
    sensorstring = "";                                //clear the string
    sensor_string_complete = false;                   //reset the flag used to tell if we have received a completed string from the Atlas Scientific product
  }
}



void print_EC_data(void) {                            //this function will pars the string  

  char sensorstring_array[30];                        //we make a char array
  char *EC;                                           //char pointer used in string parsing
  char *TDS;                                          //char pointer used in string parsing
  char *SAL;                                          //char pointer used in string parsing
  char *GRAV;                                         //char pointer used in string parsing
  float f_ec;                                         //used to hold a floating point number that is the EC
  
  sensorstring.toCharArray(sensorstring_array, 30);   //convert the string to a char array 
  EC = strtok(sensorstring_array, ",");               //let's pars the array at each comma
  TDS = strtok(NULL, ",");                            //let's pars the array at each comma
  SAL = strtok(NULL, ",");                            //let's pars the array at each comma
  GRAV = strtok(NULL, ",");                           //let's pars the array at each comma

  Serial.print("EC:");                                //we now print each value we parsed separately
  Serial.println(EC);                                 //this is the EC value

  Serial.print("TDS:");                               //we now print each value we parsed separately
  Serial.println(TDS);                                //this is the TDS value

  Serial.print("SAL:");                               //we now print each value we parsed separately
  Serial.println(SAL);                                //this is the salinity value

  Serial.print("GRAV:");                              //we now print each value we parsed separately
  Serial.println(GRAV);                               //this is the specific gravity
  Serial.println();                                   //this just makes the output easier to read
  
//f_ec= atof(EC);                                     //uncomment this line to convert the char to a float
}

Schematics

ec sensor calibration wiring diagram
Ec probe calibration wiring diagram nhku3dhrgv

Comments

Similar projects you might like

Arduino pH Sensor Calibration

by Atlas Scientific

  • 815 views
  • 2 comments
  • 4 respects

DIY pH Dosing Pump

by Atlas Scientific

  • 2,041 views
  • 2 comments
  • 16 respects
Add projectSign up / Login