Glen PowellTim Osterhoudt
Published

MEGR 3171 Spring 2023 Group 11: Pool Sensor

This pool sensor is designed to take measurements of water temperature and pH level using a thermistor, pH sensor, and two Particle Argons.

BeginnerWork in progress12 hours18
MEGR 3171 Spring 2023 Group 11: Pool Sensor

Things used in this project

Hardware components

Adafruit Thermistor
×1
Argon
Particle Argon
×2
Jumper wires (generic)
Jumper wires (generic)
×8
pH Sensor
×1
Adafruit Thermistor
×1
Resistor 1k ohm
Resistor 1k ohm
×1
Resistor 330 ohm
Resistor 330 ohm
×1
LED (generic)
LED (generic)
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
ThingSpeak API
ThingSpeak API

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

Pool Monitor Box Lid

Lid used to cover the top of the pool monitor's box body.

Pool Monitor Box Body

Box used to house circuits to prevent water from getting on them.

Schematics

Particle Communications Diagram

The two Argons communicate using Particle Publish and Subscribe functions. When Argon 1 is active and reading the pH sensor the pH reading is sent to Argon 2 to light an LED is the pH level is out of the acceptable range. When Argon 2 is active and reading the thermistor the temperature data is sent to Argon 1 to adjust the pH level to account for the effects of the temperature.

pH Sensor Schematic

Schematic displaying the circuitry used for the pH sensor and the Particle Argon.

Thermistor Sensor Schematic

Schematic displaying the circuitry used for the thermistor.

Code

Temperature Sensor Code

C/C++
// This #include statement was automatically added by the Particle IDE.
#include <ThingSpeak.h>
#include <math.h>
#include <Particle.h>

int ThermistorPin = A3;
int rPin=A2; //Red LED light for pH Level
int Vo; //Thermistor Voltage
int pH; //pH measurement from Tim's Argon
float pHr=0.0;
double R1 = 11010; //Thermistor Value 
double logR, R2, T, Tt; 
double c1 = 0.001061048, c2 = 0.00024125, c3= 0.0000000876741; //Calibration Constants 

TCPClient client; //Thingspeak Channel Information
unsigned long chanelID= 2110325; 
const char *myWriteAPIKey= "MY1552UHPFGPH62M";

void setup() {
    pinMode (ThermistorPin, INPUT);
    pinMode(rPin,OUTPUT);
  Particle.subscribe("pH", myHandler);//pull pH data from Tim's Argon 
 
}

void loop() {
  // Gets data from the Thermistor and converts it into usable temperature data
  Vo = analogRead(ThermistorPin);
  R2 = R1/(2000.0/((double)Vo-1));
  logR = log(R2);
  T = (1.0 / (c1 + (c2 * logR) + c3 *( logR * logR * logR)));
  Tt = T - 273.15; //Conv. to Celsius 
  pHr = pH;
 //ThingSpeak Live Data
 ThingSpeak.begin(client);
 int temperature=Tt;

ThingSpeak.setField(1,temperature);

ThingSpeak.writeField(chanelID, 1, temperature, myWriteAPIKey);
delay(20000); //delay 20 seconds
 
 //Publish To Cloud
 Particle.publish("temperature_C", String(Tt));
  // Wait 10 seconds
  delay(5000);

}

SerialLogHandler logHandler; //LED Warning Light turns on when pH is out of tollerance

void myHandler(const char *event, const char *data)
{

  pH = atoi(data);
  if (pH >= 0 && pH < 7) {
    digitalWrite(rPin, HIGH); // Green LED
  } else if (pH >= 7 && pH < 7.2) {
    digitalWrite(rPin, HIGH); // Green LED
    delay(500); // delay for 0.5 second
    digitalWrite(rPin, LOW); // turn off LED
    delay(500); // delay for 0.5 second
  } else if (pH >= 7.2 && pH < 7.4) {
    digitalWrite(rPin, HIGH); // Green LED
    delay(250); // delay for 0.25 second
    digitalWrite(rPin, LOW); // turn off LED
    delay(250); // delay for 0.25 second
  } else if (pH >= 7.4 && pH <= 7.6) {
    digitalWrite(rPin, LOW); // green LED
  } else if (pH > 7.6 && pH <= 8) {
    digitalWrite(rPin, HIGH); // Green LED
    delay(250); // delay for 0.25 second
    digitalWrite(rPin, LOW); // turn off LED
    delay(250); // delay for 0.25 second
  } else if (pH > 8 && pH <= 9) {
    digitalWrite(rPin, HIGH); // Green LED
    delay(500); // delay for 0.5 second
    digitalWrite(rPin, LOW); // turn off LED
    delay(500); // delay for 0.5 second
  } else if (pH > 9) {
    digitalWrite(rPin, HIGH); // Green LED
  }
}

pH Sensor Code

C/C++
// This #include statement was automatically added by the Particle IDE.
#include <ThingSpeak.h>
#include <math.h>
#include <Particle.h>

int V = A0; // set V to the analog pin connected to the pH sensor
float V2;
float pH;
float pH_conv;
float temperature_C;

TCPClient client; 
unsigned long chanelID= 2110325; 
const char *myWriteAPIKey= "MY1552UHPFGPH62M";


void setup() 
{ 
  Serial.begin(9600);
  pinMode(V, INPUT); 
  Particle.subscribe("temperature_C", updateTemperature, MY_DEVICES); // read data from GlenArgon
} 

void loop() 
{ 
  pH_conv = temperature_C * 0.0133; // conversion for effect of temperature on pH level

  V2 = analogRead(V) * (13.0 / 1024.0 / 6); // voltage conversion from sensor to pH

  pH = V2 - pH_conv; // conversion for final pH with temperature accounted for

  Serial.println(pH); // print pH level 
  delay(10000); 
  Particle.publish("pH", String(pH)); // publish pH level to GlenArgon to light LED if working
  
   //ThingSpeak Communication
 ThingSpeak.begin(client);
 int pHread=pH;

 ThingSpeak.setField(2,pH);

ThingSpeak.writeField(chanelID, 2, pHread, myWriteAPIKey); 
delay(20000); //Delay of 20 seconds
  
  
}

void updateTemperature(const char *event, const char *data) {
  temperature_C = atof(data); // convert the temperature value from string to float
}

Credits

Glen Powell

Glen Powell

0 projects • 1 follower
Tim Osterhoudt

Tim Osterhoudt

0 projects • 1 follower

Comments

Add projectSign up / Login