Project showcase

Simple Water Quality Analysis © GPL3+

An easy-to-build and low-cost water quality monitor.

  • 10,624 views
  • 5 comments
  • 16 respects

Components and supplies

Apps and online services

About this project

After I saw TDS measure circuit I am thinking if it possible use few parts to complete measure.

Here I try as below.

Hardware

  • Arduino MKR1000 * 1
  • 4.7k ohm resistor * 2
  • Dupont Line * 3
  • 2P 2.54mm connector Line * 1
  • 2.54mm gold plated pin 2P * 2

Connection

See pictures and caption below.

Software

  • Program with Arduino IDE and modify form example "Analog Input"
void loop() {
 // start
 digitalWrite(ledPin, HIGH);
 //port LL
 digitalWrite(port1, LOW);
 digitalWrite(port2, LOW);
 sensorValue1 = analogRead(sensorPin);
 delay(delaytime);
 //port LH
 digitalWrite(port1, LOW);
 digitalWrite(port2, HIGH);
 sensorValue2 = analogRead(sensorPin);
 delay(delaytime);
 digitalWrite(ledPin, LOW);
 //port HH
 digitalWrite(port1, HIGH);
 digitalWrite(port2, HIGH);
 sensorValue3 = analogRead(sensorPin);
 delay(delaytime);
 //port HL
 digitalWrite(port1, HIGH);
 digitalWrite(port2, LOW);
 sensorValue4 = analogRead(sensorPin);   
 delay(delaytime);
 Serial.print(sensorValue1);
 Serial.print(",");
 Serial.print(sensorValue2);
 Serial.print(",");
 Serial.print(sensorValue3);
 Serial.print(",");
 Serial.print(sensorValue4);
 Serial.println();
}

Result

Here I have one bottle clean water and one bottle non-pure water.

I collected three different data comparisons

1. Gold plated pin is out of water

2. Pin in clean water

3. Pin in non-pure water

Analysis

When pin in clean water, data is

"159, 434, 874, 601"

"163, 433, 873, 600"

"165, 436, 871, 598"

When pin in non-pure water data is

"159, 462, 876, 566"

"159, 465, 878, 564"

"158, 463, 878, 565"

Here the 1st and 3rd are close at each sample, 2nd and 4th have 25~30 count gap.

It is exactly what I want "can be used to distinguish water quality."

Next step I need a TDS meter as standard reference.

=================================================================

update 2018/5/13

Today I increase the number of ADC sampling and use my home's 4 different water test again.

Bottle 1 is RO water.

Bottle 2 is groundwater.

Bottle 3 is tap water.

Bottle 4 is water outdoor.

Test video as below

it seems that RO water ADC value have very different with other.

I also add WiFi-web-server function to show data on explorer.

Here the sensorValue number mean

sensorValue0 port voltage is Low Low

sensorValue1 port voltage is Low High

sensorValue2 port voltage is High High

sensorValue3 port voltage is High Low

But since I change the pin the value order ( 2nd and 4th ) are not the same with first time test.

Code

TDSArduino
try to use arduino analog input measure TDS ( Total dissolved solids )
and print it for analyze
/*
  TDS 
  
  change from
  
  Analog Input
  created by David Cuartielles
  modified 30 Aug 2011
  By Tom Igoe
  This example code is in the public domain.
  http://www.arduino.cc/en/Tutorial/AnalogInput
*/

int sensorPin = A0;    // select the input pin for the potentiometer
int ledPin = 13;      // select the pin for the LED
int sensorValue1,sensorValue2,sensorValue3,sensorValue4;  // variable to store the value coming from the sensor

int port1 = 2;      // TDS port1
int port2 = 3;      // TDS port2

const int delaytime = 500; //delaytime for discharge
void setup() {
  // initialize serial:
  Serial.begin(115200);
  // declare the ledPin as an OUTPUT:
  pinMode(ledPin, OUTPUT);
  pinMode(port1, OUTPUT);
  pinMode(port2, OUTPUT);
}

void loop() {
  // start
  digitalWrite(ledPin, HIGH);
  
  //port LL
  digitalWrite(port1, LOW);
  digitalWrite(port2, LOW);
  sensorValue1 = analogRead(sensorPin);
  delay(delaytime);
  //port LH
  digitalWrite(port1, LOW);
  digitalWrite(port2, HIGH);
  sensorValue2 = analogRead(sensorPin);
  delay(delaytime);
  
  digitalWrite(ledPin, LOW);
  
  //port HH
  digitalWrite(port1, HIGH);
  digitalWrite(port2, HIGH);
  sensorValue3 = analogRead(sensorPin);
  delay(delaytime);
  //port HL
  digitalWrite(port1, HIGH);
  digitalWrite(port2, LOW);
  sensorValue4 = analogRead(sensorPin);   
  delay(delaytime);
  Serial.print(sensorValue1);
  Serial.print(",");
  Serial.print(sensorValue2);
  Serial.print(",");
  Serial.print(sensorValue3);
  Serial.print(",");
  Serial.print(sensorValue4);
  Serial.println();
}
TDSWiFiWebServerArduino
try to use arduino analog input measure TDS ( Total dissolved solids )
and show it on web page to monitor
/*
  WiFi Web Server

 A simple web server that shows the value of the analog input pins.
 using a WiFi shield.

 This example is written for a network using WPA encryption. For
 WEP or WPA, change the WiFi.begin() call accordingly.

 Circuit:
 * WiFi shield attached
 * Analog inputs attached to pins A0 through A5 (optional)

 created 13 July 2010
 by dlf (Metodo2 srl)
 modified 31 May 2012
 by Tom Igoe

 */

#include <SPI.h>
#include <WiFi101.h>


#include "arduino_secrets.h" 
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID;        // your network SSID (name)
char pass[] = SECRET_PASS;    // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0;                 // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;

WiFiServer server(80);



int sensorPin = A0;    // select the input pin for the potentiometer
int ledPin = 13;      // select the pin for the LED
int sensorValue[4];  // variable to store the value coming from the sensor

int port1 = 2;      // TDS port1
int port2 = 3;      // TDS port2

const int delaytime = 50; //delaytime for discharge


void setup() {
  //Initialize serial and wait for port to open:
  // initialize serial:
  Serial.begin(115200);
  // declare the ledPin as an OUTPUT:
  pinMode(ledPin, OUTPUT);
  pinMode(port1, OUTPUT);
  pinMode(port2, OUTPUT);

  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);
  }

  // attempt to connect to WiFi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }
  server.begin();
  // you're connected now, so print out the status:
  printWiFiStatus();
}


void loop() {

  for(int i=0;i<4;i++)
  {
    sensorValue[i]=0;
  }
  for(int sampleCnt=0;sampleCnt<10;sampleCnt++)
  {
    // start
    digitalWrite(ledPin, HIGH);
  
    //port LL
    digitalWrite(port1, LOW);
    digitalWrite(port2, LOW);
    sensorValue[0] += analogRead(sensorPin);
    delay(delaytime);
    //port LH
    digitalWrite(port1, LOW);
    digitalWrite(port2, HIGH);
    sensorValue[1] += analogRead(sensorPin);
    delay(delaytime);
  
    digitalWrite(ledPin, LOW);
  
    //port HH
    digitalWrite(port1, HIGH);
    digitalWrite(port2, HIGH);
    sensorValue[2] += analogRead(sensorPin);
    delay(delaytime);
    //port HL
    digitalWrite(port1, HIGH);
    digitalWrite(port2, LOW);
    sensorValue[3] += analogRead(sensorPin);   
    delay(delaytime);
    
  }
  Serial.print(sensorValue[0]);
  Serial.print(",");
  Serial.print(sensorValue[1]);
  Serial.print(",");
  Serial.print(sensorValue[2]);
  Serial.print(",");
  Serial.print(sensorValue[3]);
  Serial.println();
  
  // listen for incoming clients
  WiFiClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 4; analogChannel++) {
            client.print("sensorValue ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(sensorValue[analogChannel]);
            client.println("<br />");
          }
          client.println("</html>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);

    // close the connection:
    client.stop();
    Serial.println("client disconnected");
  }
}


void printWiFiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

Schematics

Here yellow and black wire are test port.
Need a fixed distance.
Tds lskg7ktdbi
Fzz file
Here yellow and black wire are test port.
Need a fixed distance.
tds_J3R5wzePCK.fzz

Comments

Similar projects you might like

Arduino Bluetooth Basic Tutorial

by Mayoogh Girish

  • 455,448 views
  • 42 comments
  • 239 respects

Home Automation Using Raspberry Pi 2 And Windows 10 IoT

Project tutorial by Anurag S. Vasanwala

  • 289,057 views
  • 96 comments
  • 676 respects

Security Access Using RFID Reader

by Aritro Mukherjee

  • 231,777 views
  • 40 comments
  • 241 respects

OpenCat

Project in progress by Team Petoi

  • 196,624 views
  • 154 comments
  • 1,366 respects
Add projectSign up / Login