Water Quality Sensors

Turbidity Sensor

To get the turbidity sensor to work, we plugged the sensor into the digital port of the XIAO Seeed studio rp2040 expansion board, and tried to use the code provided from the website. This did not work, so we had to try some different code, we found the other code, and then were able to make the sensor work. This senses how clear the water is, and how far the light can travel without being diffused. 

IMG_0193.MOV

Temperature Sensor

This sensor was quite easy to use and is used to measure the temperature of the water. To use it plug it into the digital port of the expansion board, and place the silver end of the probe into the water to begin reading values. We found some simple code online, and it worked quite well. The values outputted are in Celsius so be wary of that. 

IMG_0194.MOV

TDS Sensor

To use this sensor, we again plugged it into the digital port of the expansion board. We found code online, and it worked first try. When testing the sensor we found that the sensor maxed out at around 155 ppm, discovering this by adding lots of salt after the initially salt we added. The value of normal charlotte tap water was around 85 ppm. 

IMG_0197.MOV

Water Quality Values

sensor collection

Sensor Code

To explain the code I asked chat GPT the prompt "Explain this code to a 6th grader" and it gave the following for each section of code

Water Turbidity Sensor:

Analog Signal Output, the output value will decrease when in liquids with a high turbidity

Working Code:

void setup() {

  Serial.begin(9600);

 

}

void loop() {

  int sensorValue = analogRead(A0);

  float voltage = sensorValue * (3.3 / 1024.0);

 

  Serial.println ("Sensor Output (V):");

  Serial.println (voltage);

  Serial.println();

  delay(1000);

}


Explanation:



This prints the voltage that changes depending on the turbidity. This technically measures the changes in turbidity, but I’m not sure if this is the reading water turbidity. Connects to analog pin



Temperature Sensor:

https://wiki.seeedstudio.com/One-Wire-Temperature-Sensor-DS18B20/


NOTE: YOU HAVE TO DOWNLOAD THIS LIBRARY AND THIS LIBRARY THEN DO SKETCH > INCLUDE LIBRARY > ADD ZIP LIBRARY —--- and add each of the two


Working Code(Connect to any digital pin):


// Include the libraries we need

#include <OneWire.h>

#include <DallasTemperature.h>

#define ONE_WIRE_BUS 26

OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.

DallasTemperature sensors(&oneWire);

void setup(void)

{

  Serial.begin(9600);

  Serial.println("Dallas Temperature IC Control Library Demo");

  sensors.begin();

}

void loop(void)

{

  Serial.print("Requesting temperatures...");

  sensors.requestTemperatures(); // Send the command to get temperatures

  Serial.println("DONE");

  float tempC = sensors.getTempCByIndex(0);

  if(tempC != DEVICE_DISCONNECTED_C)

  {

    Serial.print("Temperature for the device 1 (index 0) is: ");

    Serial.println(tempC);

  }

  else

  {

    Serial.println("Error: Could not read temperature data");

  }

}


Explanation:

In simpler terms, this code is a conversation between a computer and a temperature sensor. The computer is regularly asking the sensor, "Hey, what's the temperature?" and then letting us know what it finds out. It's like a continuous check on the current temperature.



TDS sensor:


Working code(any analog pin):


#define SERIAL Serial

#define sensorPin A0


int sensorValue = 0;

float tdsValue = 0;

float Voltage = 0;


void setup() {

   SERIAL.begin(9600);

}

void loop() {

   sensorValue = analogRead(sensorPin);

   Voltage = sensorValue*5/1024.0; //Convert analog reading to Voltage

   tdsValue=(133.42/Voltage*Voltage*Voltage - 255.86*Voltage*Voltage + 857.39*Voltage)*0.5; //Convert voltage value to TDS value

   SERIAL.print("TDS Value = ");

   SERIAL.print(tdsValue);

   SERIAL.println(" ppm");

   delay(1000);

}


Explanation:

Gathering the water image gallery