Greyson LedfordPj O'BrienMaiah Randall
Published © GPL3+

MEGR 3171 Fish Tank Monitoring System

This system monitors the water quality of a fish tank and sends alerts when action is needed directly to the users phone.

IntermediateShowcase (no instructions)203
MEGR 3171 Fish Tank Monitoring System

Things used in this project

Hardware components

Argon
Particle Argon
×3
Gravity™ Analog pH Sensor
Atlas Scientific Gravity™ Analog pH Sensor
×1
Adafruit Waterproof DS18B20 Digital temperature sensor
Adafruit Waterproof DS18B20 Digital temperature sensor
×1
1PC Rain Water Liquid Level Sensor Module Depth of Detection
×1
Jumper wires (generic)
Jumper wires (generic)
×9
Breadboard (generic)
Breadboard (generic)
×3
Resistor, 4.7 kohm
Resistor, 4.7 kohm
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
ThingSpeak API
ThingSpeak API
Maker service
IFTTT Maker service

Story

Read more

Schematics

Water Temperature Sensor Circuit Diagram

The particle on Fritzing does not have a USB pin, on our circuit the Vin is connected to USB

pH Sensor Circuit Diagram

Water Level Sensor Circuit Diagram

Code

Water Level Sensor Code

C/C++
int waterSens = A0; //define water sensor
int led = D7;//define led to pin 9
int waterVal; //define the water sensor value



void setup() {
pinMode(led, OUTPUT); //set led as an output
pinMode(waterSens, INPUT);//set water sensor as an input

}

void loop() {


  waterVal = analogRead(waterSens); //read the water sensor
 delay(3000);

String data = String(waterVal);
  Particle.publish("level", data, PRIVATE); //publishes data to cloud, allows thingspeak to access data
  delay(3000);
  
  if (waterVal<=900){
    Particle.publish("fish_tank_level_low", "LOW",PRIVATE); //acceptable range for water level, if value read by sesnor is less than 900 it will trigger the webhook for IFTTT
    delay(1000);
    
}

else if (waterVal>=2000){
    Particle.publish("fish_tank_level_high", "HIGH",PRIVATE); //acceptable range for water level, if value read by sesnor is more than 2000 it will trigger the webhook for IFTTT
    delay(1000);

} 
}

Water Temperature Sensor Code

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

#include <math.h>

const int      MAXRETRY          = 16;
const uint32_t msSAMPLE_INTERVAL = 30000;
const uint32_t msMETRIC_PUBLISH  = 30000;

const int16_t dsVCC  = D2;
const int16_t dsData = D3;
const int16_t dsGND  = D4;

// Sets Pin D3 as data pin and the only sensor on bus
DS18B20  ds18b20(dsData, true); 

char     szInfo[64];
double   celsius;
double   fahrenheit;
uint32_t msLastMetric;
uint32_t msLastSample;

void setup() {
  Serial.begin(115200); //begins serial communication
  
  pinMode(dsGND, OUTPUT); //sets up pin as output   
  digitalWrite(dsGND, LOW);  // sets up pin as ground
  pinMode(dsVCC, OUTPUT); //sets up pin as output
  digitalWrite(dsVCC, HIGH); //sets up pin with 5 volts

  delay(1000);
}

void loop() {
  if (millis() - msLastSample >= msSAMPLE_INTERVAL){
    getTemp();
  }

  if (millis() - msLastMetric >= msMETRIC_PUBLISH){
    Serial.println("Publishing now.");
    publishData(); //starts publishing data from sensor
  }
}

void publishData(){
  sprintf(szInfo, "%2.2f", fahrenheit); //converts data to fahrenheit 
  Particle.publish("dsTmp", szInfo, PRIVATE); //this publishes the data to the particle cloud and allows thingspeak to access the data
  msLastMetric = millis();
}

void getTemp(){
  float _temp;
  int   i = 0;

  do {
    _temp = ds18b20.getTemperature();
  } while (!ds18b20.crcCheck() && MAXRETRY > i++);

  if (i < MAXRETRY) {
    celsius = _temp;
    fahrenheit = ds18b20.convertToFahrenheit(_temp); //Converts temperature to fahrenheit if correct conditions are met
    Serial.println(fahrenheit); //prints temperature value
  }
  else {
    celsius = fahrenheit = NAN; //if celsuis and fahrentheit are equal after converted then it will be printed "Not A Number"
    Serial.println("Invalid reading"); //This is an invalid reading
  }
  msLastSample = millis();
  
   if (fahrenheit<=74){
    Particle.publish("fish_tank_water_cold", "COLD",PRIVATE); //establishes the acceptable range for the temperature, if the temperature if less than or equal to 74 then the IFTTT will be triggered
    delay(1000);
    
}

else if (fahrenheit>=81){
    Particle.publish("fish_tank_water_hot", "HOT",PRIVATE); // establishes the acceptable range for the temperature, if the temperature is greater than or equal to 81 then the IFTTT will be triggered
    delay(1000);
}
}

pH Sensor Code

C/C++
/*
 * file DFRobot_PH.ino
 * @ https://github.com/DFRobot/DFRobot_PH
 *
 * This is the sample code for Gravity: Analog pH Sensor / Meter Kit V2, SKU:SEN0161-V2
 * In order to guarantee precision, a temperature sensor such as DS18B20 is needed, to execute automatic temperature compensation.
 * You can send commands in the serial monitor to execute the calibration.
 * Serial Commands:
 *   enterph -> enter the calibration mode
 *   calph   -> calibrate with the standard buffer solution, two buffer solutions(4.0 and 7.0) will be automaticlly recognized
 *   exitph  -> save the calibrated parameters and exit from calibration mode
 *
 * Copyright   [DFRobot](http://www.dfrobot.com), 2018
 * Copyright   GNU Lesser General Public License
 *
 * version  V1.0
 * date  2018-04
 */

#include "DFRobot_PH.h"
//#include <EEPROM.h>

#define PH_PIN A1
float voltage,phValue,temperature = 25;
DFRobot_PH ph;

void setup()
{
    Serial.begin(115200);  
    ph.begin();
}

void loop()
{
    static unsigned long timepoint = millis();
    if(millis()-timepoint>3000U){                  //time interval: 3s
        timepoint = millis();
        //temperature = readTemperature();         // read your temperature sensor to execute temperature compensation
        voltage = analogRead(PH_PIN)/1024.0*5000;  // read the voltage
        phValue = ph.readPH(voltage,temperature);  // convert voltage to pH with temperature compensation
        Serial.print("temperature:");
        Serial.print(temperature,1);
        Serial.print("^C  pH:");
        Serial.println(phValue,2);
    }
    ph.calibration(voltage,temperature);           // calibration process by Serail CMD
    
    Particle.publish("phValue", String("phValue"));
    
}

Credits

Greyson Ledford

Greyson Ledford

1 project • 0 followers
Pj O'Brien

Pj O'Brien

1 project • 0 followers
Maiah Randall

Maiah Randall

1 project • 0 followers

Comments