Introduction
SEN0189 – Gravity: Analog Turbidity Sensor for Arduino
This tutorial covers how to use Gravity: Analog Turbidity Sensor for Arduino, whose type is SEN0189 on the basis of . Turbidity is an essential matric that measures the clearity of the water, which is one characteristic of water quality. There are plenty of particles in rivers or lake in real life, like clay, silt, soil, tiny inorganic and organic matter, algae, dissolved colored organic compounds, plankton and other microscopic organismsand so on.
The work logic of the sensor is to measure the amount of light that is scattered by material in the water. When a light is shined through the water the sensor pluged in, the light would be scattered through particles inside. The higher the intensity of scattered light, the higher the turbidity. The turbidity will be measured in nephelometric turbidity units (NTUs). In real life of the river, during periods of low flow, most rivers shows the color of green with lower turbidity, usually less than 10 NTUs. During rainstorm, particles from the surrounding land are washed into the river, blending the river in muddy conditon, and has much higher NTUs output.
Overview of the sensor
In this case,the turbidity sensor can detect suspended particles in water by measuring transmittance and scattering rate which changes with the amount of total suspended solids(TSS) in water. This type of sensor have both analog and digital signal output modes. You can fine more reference on the sensor on its datasheet.
The sensor kit is composed of :
- 1x – Turbidity sensor adapter
- 1x – Turbidity sensor probe
- 1x – Turbidity sensor cable
- 1x – Gravity analog sensor cable
Other required components are :
- Arduino Elegoo Uno R3
- LCD1602 Module
- Potentiometer(10k)
- x 830 tie-pointsBreadboard
- x M-M wires (Male to Male jumperwires)
- SEN0189 – Gravity: Analog Turbidity Sensor
With both analog output mode and digital output mode, there are two key notes when using the turbidity sensor:
D/A Output signal switch
First, the “D/A” output signal switch. Here A refers to Analog Signal Output, the higher the turbidity water is, the lower output value it will be. And D refers to Digital Signal Output, which can output either high or low levels based on the threshold adjusted by potentiometer. Considering the both output method, the corresponding code has a little bit different. If we only want to sense the turbidity and output the value in serial monitor, we can simply wire the sensor to Arduino, like the connection diagram as below. As we can see, there are overall three pins extends from the signal connector Board (the middle element that connects two parts), where black pin connects to the GND, red pin connects to 5V, and blue pin connects to A0, remeber it and we will use that in following steps.
Output Display on LCD module
In order to make the value of turbidity more intuitive, instead of serial monitor, we can also display the value on the LCD screen. The LCD display needs six Arduino pins which are set to be outputs, and also need 5V and GND connection, that’s why we need broad band, since we need to connect LCD with turbidity sensor at the same time. Here’s the diagram of LCD module with broadband, we will have to combine the two diagram in the following steps.
Wiring diagram
We now, with the help of braodband, have to combine the two diagram together, since both the LCD module and turbidity needs 5V pin but there is only one 5V pin in Elego Uno R3, we will connect it with breadboard. And here is the supposed diagram and the picture of wiring.
Code
The code for turbidity sensor has two version, one focus on analog output, the other uses Digital output mode.
Example 1- Analog output
1 2 3 4 5 6 7 8 9 |
void setup() { Serial.begin(9600); //Baud rate: 9600 } void loop() { int sensorValue = analogRead(A0);// read the input on analog pin 0: float voltage = sensorValue * (5.0 / 1024.0); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V): Serial.println(voltage); // print out the value you read: delay(500); } |
Example 2 – Digital output
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
int ledPin = 13; // Connect an LED on pin 13, or use the onboard one int sensor_in = 2; // Connect turbidity sensor to Digital Pin 2 void setup(){ pinMode(ledPin, OUTPUT); // Set ledPin to output mode pinMode(sensor_in, INPUT); //Set the turbidity sensor pin to input mode } void loop(){ if(digitalRead(sensor_in)==LOW){ //read sensor signal digitalWrite(ledPin, HIGH); // if sensor is LOW, then turn on } else{ digitalWrite(ledPin, LOW); // if sensor is HIGH, then turn off the led } } |
The code for LCD module is as below,with which we will use the library called “LiquidCrystal.h”.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
// include the library code: #include <LiquidCrystal.h> // initialize the library with the numbers of the interface pins LiquidCrystal lcd(7, 8, 9, 10, 11, 12); void setup() { // set up the LCD's number of columns and rows: lcd.begin(16, 2); // Print a message to the LCD. lcd.print("Hello, World!"); } void loop() { // set the cursor to column 0, line 1 // (note: line 1 is the second row, since counting begins with 0): lcd.setCursor(0, 1); // print the number of seconds since reset: lcd.print(millis() / 1000); } |
Now we can combine the two sensor together, to reach the final code:
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 |
//www.elegoo.com //2016.12.9 #include <LiquidCrystal.h> int tempPin = 0; // BS E D4 D5 D6 D7 LiquidCrystal lcd(7, 8, 9, 10, 11, 12); void setup() { lcd.begin(16, 2); Serial.begin(9600); } void loop() { int tempReading = analogRead(tempPin); int sensorValue = analogRead(A0); float voltage = sensorValue * (5.0 / 1024.0); lcd.setCursor(0, 0); lcd.print("Turbi Ntu "); lcd.setCursor(6, 0); lcd.print(voltage); delay(500); } |
From the code we can see that, the LCD uses six pins (7,8,9,10,11,12) as output, while the turbidity sensor with the output from A0.
After we upload the code and finish the wiring shown above, it’s time to try the sensor and measure the clearity of different water sample!
Reference:
- Elegoo Arduino tutorial lesson 15.
- https://wiki.dfrobot.com/Turbidity_sensor_SKU__SEN0189
- https://how2electronics.com/diy-turbidity-meter-using-turbidity-sensor-arduino/