Devices & Components
Arduino Uno Rev3
Resistor 330 ohm
Male/Female Jumper Wires
RGB Diffused Common Cathode
Rotary potentiometer (generic)
Alphanumeric LCD, 16 x 2
HC-05 Bluetooth Module
Resistor 1k ohm
Hardware & Tools
Wire Stripper & Cutter, 26-14 AWG Solid & Stranded Wires
Software & Tools
Ardutooth
Arduino IDE
Project description
Code
Water quality monitoring code
arduino
1//include libraries 2#include <SoftwareSerial.h> 3#include <LiquidCrystal.h> 4 5//for bluetooth - create an object called BTserial, with RX pin at 3 and TX pin at 2 6SoftwareSerial BTserial(3,2); // RX | TX 7 8//decraration of all our variables 9 10float reads; 11int pin = A0; 12 13float vOut = 0 ;//voltage drop across 2 points 14float vIn = 5; 15float R1 = 1000; 16float R2 = 0; 17float buffer = 0; 18float TDS; 19 20float R = 0;//resistance between the 2 wires 21float r = 0;//resistivity 22float L = 0.06;//distance between the wires in m 23double A = 0.000154;//area of cross section of wire in m^2 24 25float C = 0;//conductivity in S/m 26float Cm = 0;//conductivity in mS/cm 27 28int rPin = 9; 29int bPin = 5; 30int gPin = 6; 31int rVal = 255; 32int bVal = 255; 33int gVal = 255; 34 35//we will use this formula to get the resistivity after using ohm's law -> R = r L/A => r = R A/L 36 37//creating lcd object from Liquid Crystal library 38LiquidCrystal lcd(7,8,10,11,12,13); 39 40void setup() { 41 //initialise BT serial and serial monitor 42 Serial.begin(9600); 43 BTserial.begin(9600); 44 45 //initialise lcd 46 lcd.begin(16, 2); 47 48 //set rgb led pins (all to be pwm pins on Arduino) as output 49 pinMode(rPin,OUTPUT); 50 pinMode(bPin,OUTPUT); 51 pinMode(gPin,OUTPUT); 52 pinMode(pin,INPUT); 53 //Print stagnant message to LCD 54 lcd.print("Conductivity: "); 55} 56 57void loop() { 58 reads = analogRead(A0); 59 60 vOut = reads*5/1023; 61 Serial.println(reads); 62// Serial.println(vOut); 63 buffer = (vIn/vOut)-1; 64 R2 = R1*buffer; 65 Serial.println(R2); 66 delay(500); 67 //convert voltage to resistance 68 //Apply formula mentioned above 69 r = R2*A/L;//R=rL/A 70 //convert resistivity to condictivity 71 C = 1/r; 72 Cm = C*10; 73 //convert conductivity in mS/cm to TDS 74 TDS = Cm *700; 75 //Set cursor of LCD to next row 76 lcd.setCursor(0,1); 77 lcd.println(C); 78 79 //display corresponding colours on rgb led according to the analog read 80 if( reads < 600 ) 81 { 82 if (reads <= 300){ 83 setColor( 255, 0, 255 ) ; 84 } 85 if (reads > 200){ 86 setColor( 200, 0, 255 ) ; 87 } 88 } 89 else{ 90 if( reads <= 900 ) 91 { 92 setColor( 0, 0, 255 ) ; 93 } 94 if( reads > 700 ) 95 { 96 setColor( 0, 255, 255 ) ; 97 } 98 } 99 100//send data to Ardutooth app on mobile phone through bluetooth 101BTserial.print(C); 102BTserial.print(","); 103BTserial.print(TDS); 104BTserial.print(";"); 105delay(500); 106} 107 108 109void setColor(int red, int green, int blue) 110{ 111 analogWrite( rPin, 255 - red ) ; 112 analogWrite( gPin, 255 - green ) ; 113 analogWrite( bPin, 255 - blue ) ; 114}
Downloadable files
Circuit
Circuit

Documentation
Testing water tube
I used an old test tube I had to make this. I poked holes on either end of the tube and inserted wires from either end. Finally, to hold the wires in place, I attached some putty.
Testing water tube

Comments
Only logged in users can leave comments