Water Sensors 

Water Turbidity Sensor

After refreshing our minds on electronics we started work on the Water Turbidity Sensor. We learned the sensor has a threshold voltage, and then the sensor alters the voltage giving us the reading. This measures the density of turbid water and the concentration of extraneous matter using refraction of wavelength between a photo transistor and diode. The light from the source determines turbidity. Using this link  we learned more about the function and connections. We had to connect it to an analog pin, then reference that pin in the code. Then using an Xiao RP2040, which we coded using C++ on the Arduino App to display the readings on the monitor.  The Xiao has only one analog pins the rest are other pinouts. The lower the displayed voltage, the higher the turbidity of the water. 

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);

}


Temperature Sensor 

We used the one wire temperature sensor which includes the DS18B20 chip inside. The sensor has a waterproof probe, the opperating voltage is 3-5v. The sensor works by measuring voltage over a thermistor. The IC on the sensor converts the resistance from the thermistor into a temperature reading. We used this link for more about the sensor, like connections, voltage, and sample code. 

Working code:


// 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");

  }

}


TDS Sensor 

#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);

}