Introduction
The goal of our group project is to set up a smart CSO water purification system with a combination of four different types of water quality sensors, a simplified aeration installation, and active carbon. In this tutorial, we will use a turbidity sensor to monitor the quality of water (click here to know more about turbidity and here to know about the sensor we use), and a DC motor to represent the aeration system (a real aeration system is usually too costly, and one of the core parts is a vent which is driven by a motor). The motor will automatically be triggered once the water quality hit the standard line.
Contents
- Part list
- Set up and wiring
- Run the code
- Test video
Part List
- Gravity: Analog Turbidity Sensor For Arduino x1
- Arduino UNO x1
- Breadboard x1
- DC Motor x1
- 9V Battery with Clip x1
- Transistor x1
- 330Ω Resistor x1
- Diode x1
- Jumpwire x6
Set up and wiring
Looking back at the tutorial for motors, we know that the dc motor in the Arduino Kit performs best with a voltage no less than 5V. However, the Arduino can only output a voltage a little bit below 5V, and that is why we will add an external 9V battery to ensure the power source.
The turbidity sensor module should be connected to Arduino only using three pins: 5V, GND and A0. Be careful when you are connecting the sensor to the adaptor — the cable would only work when it is connected in the following way:
Pictures below are a wiring photo and a Fritzing diagram shows how the circuit is wired.
Wiring
Circuit Diagram
Run the Code
There is an “analog-digital” switch on the turbidity sensor adaptor which switches between analog mode and digital mode. According to the official guide, when in analog mode, the output value decreases at high turbidity. When in digital mode, the output pin goes high when the turbidity reaches a threshold value, set by the onboard potentiometer. In this tutorial, we want to know the NTU of the water, so we will use the analog mode.
The same official guide gave this graph with an equation that relates the voltage from the sensor to turbidity:
Note that this equation is only applicable when the sensor gives out around 4.2 (±0.3)volts at no turbidity. If your sensor does not give the right reading, pry open the sensor and carefully turn the trimmer until you could get a 4.2V output when the sensor is in clean water.
(I did not pry open my sensor, because it worked well. The photo above is from this website.)
Upload the following code to 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 |
/* Tutorial for Smart Water Aeration System * Shuchang Dong * The code is based on the following codes: * https://media.digikey.com/pdf/Data%20Sheets/DFRobot%20PDFs/SEN0189_Web.pdf * https://www.teachmemicro.com/arduino-turbidity-sensor/ */ const int motorPin = 9; int sensorPin = A0; float volt; float ntu; void setup() { pinMode(motorPin, OUTPUT); Serial.begin(9600); // We will use the Serial Monitor to read the NTU of the water } void loop() { int Speed1 = 100; //Set the speed of the DC motor volt = 0; for(int i=0; i<800; i++) //The voltage from the sensor is quite noisy { //so I take 800 samples and then average those samples int sensorvalue = analogRead(A0); volt += sensorvalue * (5.0 / 1024.0); //Convert the analog reading (0~1023) to a voltage (0 ~ 5V) } volt = volt/800; volt = round_to_dp(volt,1); //Round the volt number to 1 decimal place if(volt < 2.5){ //The equation only works between 2.5V ~ 4.2V, ntu = 3000; //so set any readings below 2.5V with 3000NTU }else{ ntu = -1120.4*square(volt)+5742.3*volt-4352.9; // Calculate the current NTU } if(ntu <0){ ntu = 0; //If the NTU turns out to be under 0, set it to 0. } if(ntu > 150){ //When NTU goes above 150, which is the standard line I set for analogWrite(motorPin, Speed1); //natural water in Philly according to the recent river water } //quality report, turn on the motor and spin at speed1. else{ digitalWrite(motorPin, LOW); //Else, turn off the motor } Serial.print(volt); //Show the voltage and the NTU on the screen Serial.print(" V"); Serial.print("\n"); Serial.print(ntu); Serial.print(" NTU"); Serial.print("\n"); delay(2000); } float round_to_dp( float in_value, int decimal_place ) { float multiplier = powf( 10.0f, decimal_place ); in_value = roundf( in_value * multiplier ) / multiplier; return in_value; } |
Your serial monitor will be delivering the reading like this (when the sensor is not dipped into the water) :
Test Video
Here’s the Smart Water Aeration System in action:
2 replies on “Prototype of Smart Water Aeration System: Using an Arduino Turbidity Sensor and a DC Motor”
square was not declare
can you send me fritzing part of that turbiditysensor