In this tutorial, you will build a device that detects the conductivity of water and use it to control the brightness of an LED light. The conductivity of pure water is very low, but it increases when substances are dissolved in it (Check out this page from the USGS for more on the science behind this). For example, salt water is more conductive than fresh water. By using water to complete a circuit between two wires we can measure how much resistance (the reciprocal of conductivity) there is on the circuit, and by extension how conductive the water is.
It builds on the conductivity sensor in Environmental Monitoring with Arduino by Emily Gertz and Patrick Di Justo and uses concepts and from the Vilros Ultimate Starter Kit Guide.
You will need the parts listed below to build the device.
Parts List
- Arduino Uno
- Breadboard
- Red LED
- One (1) 10K Ohm Resistor
- One (1) 330 Ohm Resistor
- Jumper cables
- Insulated wire
- Chassis-Mount Dual Female Binding Post
Put Together the Sensor
Cut two lengths of wire about 10cm long and strip one end 3cm and the other 1cm.
Loosen the nuts on the narrow posts and the nobs of the binding post.
Wrap the longer stripped ends around the narrow posts of the Binding Post and tighten the nuts down to hold the wires in place.
Place a long jumper cable through the holes in each of the knobs on the Binding Post and tighten down to hold them firmly in place. It took me a couple of tries to get them into a position that would stay, so you may need to reset them a few times.
You want the ends of the wires to be 1cm apart for the readings to be most accurate.
Connect the Hardware
Connect the Ground pin GND (red wire) and the power pin 5V (black wire) pins on the Arduino to the columns on one side of the breadboard with jumper cables.
Place the 10K Resistor so that it connects the Ground column with a row on the Breadboard.
Place one long jumper cable (green wire) in the same row as the 10K Resistor. This will be part of the conductivity sensor. Leave at least one empty space in between them.
Place a jumper cable (orange wire) into the space between the 10K Resistor and the wire from the conductivity sensor and connect it to the Analog In 0 pin on the Arduino.
Connect another long jumper cable (yellow wire) to the power column. This is the other part of the conductivity sensor.
Place on the LED on the breadboard with the long and short legs on different rows.
Use the 330 Resistor to connect the row with the LED’s short leg to the Ground column.
Connect the row with the LED’s long leg to the PWM 3 pin on the Arduino with a jumper cable (blue wire).
Code
Load the following code onto your Arduino:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
/* * Water Conductivity Sensor * * This sketch controlls the brightness of an LED with a water conductivity sensor * * This sketch draws from the * Water Conductivity Sketch by Emily Gertz at https://github.com/ejgertz/EMWA/tree/master/chapter-5 * & * the Example Sketch 06: Photo Resistor by Sparkfun Electronics * * Written by John Michael LaSalle, 2018 * This code is in the public domain. * */ const float ArduinoVoltage = 5.00; // CHANGE THIS FOR 3.3v Arduinos const float ArduinoResolution = ArduinoVoltage / 1024; // the Arduino will read the current, which ranges from 0-5 Volts on a scale of 0-1024 const float resistorValue = 10000.0; // the resistance of the 10K Resistor in the voltage divider float returnVoltage = 0.0; // variable for the voltage of the reading from the conductivity sensor float resistance = 0.0; // variable for the resistance of the water double Siemens = 0.0; // variable float TDS = 0.0; int inputPin = A0; // pin from voltage divider float outputPin = 3; // pin for LED int reading; // variable for conductivity reading on scale from 0-1024 int lightLevel; // valiable for LED brightness on scale from 0-255 void setup() { Serial.begin(9600); //set baud rate for the serial monitor pinMode(outputPin, OUTPUT); // set the LED pin mode pinMode(inputPin, INPUT); // Set the conductivity sensor pin mode } void loop() { reading = analogRead(inputPin); // take conductivity reading Serial.print("Raw conductivity reading: "); Serial.println(reading); // print raw reading to the serial monitor lightLevel = map(reading, 0, 1024, 0, 255); // convert the conductivity reading to to the light level scale Serial.print("Light Level: "); Serial.println(lightLevel); // print light level analogWrite(outputPin, lightLevel); //send light level to the LED // conductivity reading in Volts Serial.print("Return voltage = "); returnVoltage = reading *ArduinoResolution; // convert the raw conductivity reading to volts Serial.print(returnVoltage); Serial.println(" volts"); // convert voltage to resistance. This is the resistance of the water. Serial.print("That works out to a resistance of "); resistance = ((5.00 * resistorValue) / returnVoltage) - resistorValue; // convert voltage to ohms Serial.print(resistance); Serial.println(" Ohms."); // convert resistance to conductivity Serial.print("Which works out to a conductivity of "); Siemens = 1.0/(resistance/1000000); // convert ohms to siemens Serial.print(Siemens); Serial.println(" microSiemens."); delay(1000); // wait 1 second before taking a reading again } |
Using the Sensor
Simply place the ends of the wires into the water and see the readings pour in. The US Environmental Protection Agency has some advice on how to take readings and what different measurements mean. On that page they refer to micromhos which is another name for microSiemens. MicroSiemens is the standard name and but micromhos is somethimes used in the United States.