Wen-Liang Lin
Published © GPL3+

Simple Water Quality Analysis

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

BeginnerShowcase (no instructions)1 hour27,782
Simple Water Quality Analysis

Things used in this project

Hardware components

Arduino MKR1000
Arduino MKR1000
×1
Jumper wires (generic)
Jumper wires (generic)
×5
Resistor 4.75k ohm
Resistor 4.75k ohm
×2
Gold-Plated Pin
×7
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

TDS

Here yellow and black wire are test port.
Need a fixed distance.

TDS

Fzz file
Here yellow and black wire are test port.
Need a fixed distance.

Code

TDS

Arduino
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();
}

TDSWiFiWebServer

Arduino
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");
}

Credits

Wen-Liang Lin

Wen-Liang Lin

29 projects • 35 followers
Hi, I am momososo

Comments