Salinity Measuring Device

by Markus Opitz in Circuits > Arduino

485 Views, 4 Favorites, 0 Comments

Salinity Measuring Device

SalinityTitel.jpg

I needed a measuring device for another project, for the desalination of seawater. I wanted to be able to determine whether and to what extent the desalination was working. A person's sense of taste is quite misleading.

Seawater has an average salt content of ~ 35g per liter, freshwater about 1g/l.


Water is actually a poor conductor of electricity. However, if salts are added, the conductivity increases. We make use of this when we want to measure the salt content of water.

I found an ESP8266 at home, a water sensor and a small display was also still there.

Here we go.

Supplies

Arduino nano / ESP8266 / ESP32

water sensor

0.96' OLED display (optional)

breadboard and wires

destilled water + salt (for calibration)

Setup

Wiring.jpg

Follow the layout in the illustration:

The sensor is connected to 3.3V and GND on the Arduino/ESP, the data line is connected to A0.

The display also is connected to 3.3V or 5V and GND, SDA --> D1, SCL --> D2

Arduino Sketch

Many good people have already described how to program an Arduino on Instructables. You can find out how to upload a sketch to an Arduino Nano here and here.

// OLED setup
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

// sensor setup
int sensorValue;   //you need to replace this value with Value_1
const int SensorPin = A0;
int salinity = 0;
 
 
void setup() {
  Serial.begin(115200); // open serial port
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3D)) { // Address 0x3C for 128x64
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }
    display.clearDisplay();
    display.display();
    display.setTextSize(2);
    display.setTextColor(WHITE);
        display.setCursor(0,0); display.println("start");
    display.display();
    delay(1000);
}
 
 
void loop() {
 getData();
 delay(1000);  //loop after 1 second
}  


void getData() {

  sensorValue = analogRead(SensorPin);
  salinity = map(sensorValue, 270, 380, 0, 35);  //270 is value for pure water, 380 for 35g/litre salt water

// output serial monitor
  Serial.println(sensorValue);
  Serial.print(salinity);Serial.println(" %");
  Serial.println("");
  delay(10);

// output OLED display
  display.clearDisplay();
  display.setTextColor(WHITE);
  display.setTextSize(2);
  display.setCursor(0, 0);
  display.println(sensorValue);
  display.drawLine(0, 18, 128, 18, WHITE);

  if (sensorValue > 244) {

    display.setCursor(0, 28);
    display.setTextSize(1);
    display.print("Salinity:  ");
    display.setTextSize(2);
    display.setCursor(40, 47);
    display.print(salinity); display.println(" g/l");
   }
  display.display();
}

Downloads

Calibrating

Waters.jpg
35g-l.JPG

The device is already displaying some values. Now we just have to assign them to clear values and calibrate it.

For this we need distilled water. I have prepared two glasses with 100 milliliters (ml) of water each. One remains untreated and I dissolve 35 g of salt in the other, which corresponds to the average salt content of seawater.

Now I immerse the sensor in the test tubes and read the values on the serial monitor or the OLED of the Arduino.

In my experiment, distilled water has a value of 270 and seawater a value of 380. I add these numbers to line 49 of the map command in the sketch. The two values are now translated into 0 g salt per liter and 35 g/l in the running program.

salinity = map(sensorValue, 270, 380, 0, 35);


Not quite scientifically accurate, but it is very helpful to be able to determine the approximate salt content, especially for my desalination project.