Temperature Compensating Atlas's Salinity Sensor

Temperature Compensating Atlas's Salinity Sensor © CC BY-NC

How to temperature compensate the Atlas salinity sensor automatically.

  • 500 views
  • 0 comments
  • 2 respects

Components and supplies

Apps and online services

About this project

In this project, we will be automatically temperature compensating the salinity sensor from Atlas Scientific. Temperature changes have an impact on the conductivity/total dissolved solids/salinity of fluids and by compensating for it, we are ensuring that our reading is what it actually is at that specific temperature. Atlas's temperature sensor is used.

The temperature readings are passed to the salinity sensor after which the compensated salinity readings are outputted. Operation is via I2C protocol and readings are displayed on the Arduino serial plotter or monitor.

Advantages

  • The temperature is automatically accounted for, enabling accurate conductivity readings.
  • Real-time conductivity and temperature output.
  • Can be expanded to include more EZO sensors such as the pH and dissolved oxygen

Step 1: Pre-assembly Requirements

a) Calibrate the sensors: Each sensor has a unique calibration process. Refer to the following: salinity calibration,temperature calibration. If you are using other sensors refer to their respective datasheet which can be found on the Atlas Scientific website.

b) Set sensors' protocol to I2C and each sensor needs a unique I2C address. In accordance with the sample code for this project, the following addresses are used: salinity sensor address is 100 and temperature sensor address is 102. For information on how to change between protocols, refer to this LINK.

The calibration and the switch to I2C MUST be done before implementing the sensors into this project.

Step 2: Assemble Hardware

Connect the hardware as shown in the schematic.

You can use either an Arduino UNO or a STEMTera board. The STEMTera board was used in this project for its compact design where the Arduino is combined with the breadboard.

Datasheets: EZO EC, EZO RTD

Step 3: Load Program Onto Arduino

The code for this project makes use of a customized library and header file for the EZO circuits in I2C mode. You will have to add them to your Arduino IDE in order to use the code. The steps below include the process of making this addition to the IDE.

a) Download Ezo_I2c_lib, a zip folder from GitHub onto your computer.

b) On your computer, open the Arduino IDE (You can download the IDE from HERE if you do not have it). If you would like to use the serial plotter be sure to download the most recent version of the IDE.

c) In the IDE, go to Sketch -> Include Library -> Add.ZIP LIbrary -> Select the Ezo_I2c_lib folder you just downloaded. The appropriate files are now included.

There are two sample codes which will work for this project. You can choose either.

d) Copy the code from temp_comp_example or temp_comp_rt_example onto your IDE work panel. You can also access them from the Ezo_I2c_lib zip folder downloaded above.

The "temp_comp_example" code works by setting the temperature in the EC sensor and then take a reading. As for the "temp_comp_rt_example" code, the temperature is set and a reading is taken in one shot. Both will give the same result.

e) Compile and upload temp_comp_example or temp_comp_rt_example to your Arduino Uno or STEMTera board.

f) In your IDE, go to Tools -> Serial Plotter or press Ctrl+Shift+L on your keyboard. The plotter window will open. Set the baud rate to 9600. The real-time graphing should now begin.

h) To use the serial monitor, go to Tools -> Serial Monitor or press Ctrl+Shift+M on your keyboard. The monitor will open. Set the baud rate to 9600 and select "Carriage return". The EC and temperature readings should display.

Demonstration

Part 1: No temperature compensation

Initially, the water is at a temperature of about 30°C. It is then heated to about 65°C while the conductivity (green graph) and temperature (red graph) readings are observed on the serial plotter. (For Arduino sample code that permits the reading of multiple circuits without automatic temperature compensation refer to this LINK).

Part 2: Temperature compensation

The Arduino code that accounts for automatic temperature compensation is uploaded to the board. See this LINK for the code. Once more, the starting point of the water is around 30°C. It is gradually raised to about 65°C while the conductivity (green graph) and temperature (red graph) readings are observed on the serial plotter.

Code

Temp_comp_example codeC/C++
#include <Ezo_i2c.h> //include the EZO I2C library from https://github.com/Atlas-Scientific/Ezo_I2c_lib
#include <Wire.h>    //include arduinos i2c library

Ezo_board EC = Ezo_board(100, "EC");       //create a EC circuit object, who's address is 100 and name is "EC"
Ezo_board RTD = Ezo_board(102, "RTD");      //create an RTD circuit object who's address is 102 and name is "RTD"

enum polling_phase {SEND_TEMP, REQUEST, RESPONSE };
enum polling_phase reading_phase = SEND_TEMP;        //selects our phase

uint32_t next_poll_time = 0;              //holds the next time we receive a response, in milliseconds
const unsigned int response_delay = 1000; //how long we wait to receive a response, in milliseconds
const unsigned int temp_delay = 300;

float ec;         //used to hold floating point number that is ec
float temp;       //used to hold floating point number that is temperature

void setup() {
  Wire.begin();                           //start the I2C
  Serial.begin(9600);                     //start the serial communication to the computer
}

void receive_reading(Ezo_board &Sensor) {               // function to decode the reading after the read command was issued

  Serial.print(Sensor.get_name()); Serial.print(": ");  // print the name of the circuit getting the reading

  Sensor.receive_read();              //get the response data and put it into the [Sensor].reading variable if successful

  switch (Sensor.get_error()) {             //switch case based on what the response code is.
    case Ezo_board::SUCCESS:
      /*                                                            //uncomment this section for access to sensor readings
      if (Sensor.get_name()=="EC"){ec = Sensor.get_reading();}      //the EC readings are now stored in a float
      if (Sensor.get_name()=="RTD"){temp = Sensor.get_reading();}   //the temperature readings are now stored in a float
      */
      Serial.print(Sensor.get_reading(), 3);  //the command was successful, print the reading
      break;

    case Ezo_board::FAIL:
      Serial.print("Failed ");        //means the command has failed.
      break;

    case Ezo_board::NOT_READY:
      Serial.print("Pending ");       //the command has not yet been finished calculating.
      break;

    case Ezo_board::NO_DATA:
      Serial.print("No Data ");       //the sensor has no data to send.
      break;
  }
}

void loop() {
  switch (reading_phase) {          //if were in the phase where we ask for a reading
    case SEND_TEMP:
      if((RTD.get_error() == Ezo_board::SUCCESS) && (RTD.get_reading() > -1000.0)){
        EC.send_cmd_with_num("T,", RTD.get_reading());
      }else{
        EC.send_cmd_with_num("T,", 25.0);
      }
      next_poll_time = millis() + temp_delay; //set when the response will arrive
      reading_phase = REQUEST;       //switch to the receiving phase
      
      break;

    case REQUEST:
      if (millis() >= next_poll_time) {
        EC.send_read();
        RTD.send_read();
        next_poll_time = millis() + response_delay; //set when the response will arrive
        reading_phase = RESPONSE;       //switch to the receiving phase
      }
      break;

    case RESPONSE:                             //if were in the receiving phase
      if (millis() >= next_poll_time) {  //and its time to get the response
        receive_reading(EC);             //get the reading from the PH circuit
        Serial.print("  ");
        receive_reading(RTD);             //get the reading from the RTD circuit
        Serial.println();
        reading_phase = SEND_TEMP;            //switch back to asking for readings
      }
      break;
  }
}
Temp_comp_rt_example codeC/C++
#include <Ezo_i2c.h> //include the EZO I2C library from https://github.com/Atlas-Scientific/Ezo_I2c_lib
#include <Wire.h>    //include arduinos i2c library

Ezo_board EC = Ezo_board(100, "EC");       //create a EC circuit object, who's address is 100 and name is "EC"
Ezo_board RTD = Ezo_board(102, "RTD");      //create an RTD circuit object who's address is 102 and name is "RTD"

bool reading_request_phase = true;        //selects our phase

uint32_t next_poll_time = 0;              //holds the next time we receive a response, in milliseconds
const unsigned int response_delay = 1000; //how long we wait to receive a response, in milliseconds

float ec;         //used to hold floating point number that is ec
float temp;       //used to hold floating point number that is temperature

void setup() {
  Wire.begin();                           //start the I2C
  Serial.begin(9600);                   //start the serial communication to the computer
}

void receive_reading(Ezo_board &Sensor) {               // function to decode the reading after the read command was issued

  Serial.print(Sensor.get_name()); Serial.print(": ");  // print the name of the circuit getting the reading

  Sensor.receive_read();              //get the response data and put it into the [Sensor].reading variable if successful

  switch (Sensor.get_error()) {             //switch case based on what the response code is.
    case Ezo_board::SUCCESS:
      /*                                                            //uncomment this section for access to sensor readings
      if (Sensor.get_name()=="EC"){ec = Sensor.get_reading();}      //the EC readings are now stored in a float
      if (Sensor.get_name()=="RTD"){temp = Sensor.get_reading();}   //the temperature readings are now stored in a float
      */
      Serial.print(Sensor.get_reading(), 3);  //the command was successful, print the reading
      break;

    case Ezo_board::FAIL:
      Serial.print("Failed ");        //means the command has failed.
      break;

    case Ezo_board::NOT_READY:
      Serial.print("Pending ");       //the command has not yet been finished calculating.
      break;

    case Ezo_board::NO_DATA:
      Serial.print("No Data ");       //the sensor has no data to send.
      break;
  }
}

void loop() {
  if (reading_request_phase) {           //if were in the phase where we ask for a reading

    //send a read command. we use this command instead of PH.send_cmd("R");
    //to let the library know to parse the reading
    if((RTD.get_error() == Ezo_board::SUCCESS) && (RTD.get_reading() > -1000.0)){
      EC.send_read_with_temp_comp(RTD.get_reading());
    }else{
       EC.send_read_with_temp_comp(25.0);
    }
    RTD.send_read();

    next_poll_time = millis() + response_delay; //set when the response will arrive
    reading_request_phase = false;       //switch to the receiving phase
  }
  else {                               //if were in the receiving phase
    if (millis() >= next_poll_time) {  //and its time to get the response

      receive_reading(EC);             //get the reading from the PH circuit
      Serial.print("  ");
      receive_reading(RTD);             //get the reading from the RTD circuit
      Serial.println();

      reading_request_phase = true;            //switch back to asking for readings
    }
  }
}

Schematics

Salinity sensor temp comp wiring diagram
Ec rtd wiring diagram 33mghcxzfi

Comments

Similar projects you might like

How To Use DS18B20 Water Proof Temperature Sensor

Project showcase by IoTBoys

  • 71,892 views
  • 13 comments
  • 20 respects

Beautifully Finished Humidity and Temperature Sensor

Project tutorial by Wicked Makers

  • 19,356 views
  • 22 comments
  • 143 respects

Ultrasonic Sensor with Alarm, LCD and Temperature

Project tutorial by MichDragstar

  • 8,352 views
  • 7 comments
  • 23 respects

DHT11 /DHT22 Temperature Sensor

Project tutorial by Daniel Porrey

  • 90,487 views
  • 106 comments
  • 140 respects

Room temperature sensor with display on Mobile

Project showcase by Kaustubh Agarwal

  • 27,208 views
  • 8 comments
  • 60 respects

Temperature sensor

Project tutorial by Grant

  • 21,069 views
  • 6 comments
  • 34 respects
Add projectSign up / Login