aman_a_shastry
Published © GPL3+

IoT -based water quality sensor

Build your own IoT-based water quality monitoring system WITHOUT any TDS/pH meter !!

IntermediateFull instructions provided30,466
IoT -based water quality sensor

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
HC-05 Bluetooth Module
HC-05 Bluetooth Module
×1
RGB Diffused Common Cathode
RGB Diffused Common Cathode
×1
Resistor 330 ohm
Resistor 330 ohm
×3
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1
Alphanumeric LCD, 16 x 2
Alphanumeric LCD, 16 x 2
×1
Resistor 1k ohm
Resistor 1k ohm
×1

Software apps and online services

Arduino IDE
Arduino IDE
Ardutooth

Hand tools and fabrication machines

Wire Stripper & Cutter, 26-14 AWG Solid & Stranded Wires
Wire Stripper & Cutter, 26-14 AWG Solid & Stranded Wires

Story

Read more

Custom parts and enclosures

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.

Schematics

Circuit

Code

Water quality monitoring code

Arduino
//include libraries
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>

//for bluetooth - create an object called BTserial, with RX pin at 3 and TX pin at 2
SoftwareSerial BTserial(3,2); // RX | TX

//decraration of all our variables

float reads;
int pin = A0;

float vOut = 0 ;//voltage drop across 2 points
float vIn = 5;
float R1 = 1000;
float R2 = 0;
float buffer = 0;
float TDS;

float R = 0;//resistance between the 2 wires
float r = 0;//resistivity 
float L = 0.06;//distance between the wires in m
double A = 0.000154;//area of cross section of wire in m^2

float C = 0;//conductivity in S/m
float Cm = 0;//conductivity in mS/cm

int rPin = 9;
int bPin = 5;
int gPin = 6;
int rVal = 255;
int bVal = 255;
int gVal = 255;

//we will use this formula to get the resistivity after using ohm's law -> R = r L/A => r = R A/L

//creating lcd object from Liquid Crystal library
LiquidCrystal lcd(7,8,10,11,12,13);

void setup() {
  //initialise BT serial and   serial monitor
  Serial.begin(9600);
  BTserial.begin(9600);

  //initialise lcd
  lcd.begin(16, 2);

  //set rgb led pins (all to be pwm pins on Arduino) as output
  pinMode(rPin,OUTPUT);
  pinMode(bPin,OUTPUT);
  pinMode(gPin,OUTPUT);
  pinMode(pin,INPUT);
  //Print stagnant message to LCD
  lcd.print("Conductivity: ");
}

void loop() {
    reads = analogRead(A0);
  
  vOut = reads*5/1023;
  Serial.println(reads);
//  Serial.println(vOut);
  buffer = (vIn/vOut)-1;
  R2 = R1*buffer;
  Serial.println(R2);
  delay(500);
    //convert voltage to resistance
    //Apply formula mentioned above
      r = R2*A/L;//R=rL/A
    //convert resistivity to condictivity
    C = 1/r;
    Cm = C*10;
    //convert conductivity in mS/cm to TDS
    TDS = Cm *700;
    //Set cursor of LCD to next row
    lcd.setCursor(0,1);
    lcd.println(C);

    //display corresponding colours on rgb led according to the analog read
     if( reads < 600 )
  {
      if (reads <= 300){
        setColor( 255, 0, 255 ) ;
      }
      if (reads > 200){
        setColor( 200, 0, 255 ) ;
      }
  }
  else{
    if( reads <= 900 )
    {
      setColor( 0, 0, 255 ) ;
    }
    if( reads > 700 )
  {
    setColor( 0, 255, 255 ) ;
  }
    }

//send data to Ardutooth app on mobile phone through bluetooth
BTserial.print(C);
BTserial.print(",");
BTserial.print(TDS);
BTserial.print(";");
delay(500);
}


void setColor(int red, int green, int blue)
{
  analogWrite( rPin, 255 - red ) ;
  analogWrite( gPin, 255 - green ) ;
  analogWrite( bPin, 255 - blue ) ;  
}

Credits

aman_a_shastry

aman_a_shastry

5 projects • 6 followers

Comments