Tired of having to remember when to clean your fish tank? Ever wanted to know the water quality and temperature of your fish tank? Well, this is the story of how we created an IOT fish tank monitoring system.
The ProblemKeeping a clean and healthy fish tank is vital to the longevity of fish. Unfortunately, this can become a tedious task to remember when the last time you cleaned your tank was. Maybe you've just been waiting until your tank obviously needs cleaned, probably not the best situation for the fish that live there.
To make your life easier, we have created a fish tank monitoring system using the Particle Photon 2. This device constantly tracks the number of total dissolved solids (TDS) in the water and the temperature. This data is streamed to ThingSpeak, where it is plotted, so that you can analyze your tank over time. The system will also send you alerts through the IFTTT app, once it is time to clean the tank. Previous smart fish tank projects typically focus on feeding the fish. Our approach is novel because we focus on tracking the water quality. Feeding fish is typically not an issue. In fact, most people tend to overfeed their fish, making water quality monitoring even more important.
The Device - Particle Photon 2's and SensorsThis solution makes use of the features of the Particle Cloud, ThingSpeak, and IFTTT. Two Particle Photon 2 devices are used and they utilize bi-directional communication over the Particle Cloud. The first device, name fish_tank, is located near the fish tank and is responsible for collecting data from the sensors. Two sensors are utilized in this project, but more (such as pH or water level) could easily be added to fit your needs. The sensors used in this project are the CQRobot Ocean: TDS Meter and a thermistor.
Both sensors create analog voltage outputs that can easily be read by a Particle Photon 2. fish_tank reads the output of both sensors at a frequency of 1 Hz. Calibration equations are used to convert the measured voltages to the desired units of particles per million (ppm) and temperature. It then averages the readings over a period of 10 minutes and publishes the 10 minute average values to the Particle Cloud. The calibration equations are shown below:
TDS:
TDS = (133.42*compVolt^3 - 255.86*compVolt^2 + 857.39*compVolt) * 0.5
compVolt = measuredVolt/compCoeff
compCoeff = 1.0 + 0.02*(temp - 25.0)
Temperature:
Temp = {[ ( ln(measuredResistance/nominalResistance) / betaCoeff ) + (1 / (nominalTemp + 273.15) ] ^ -1} - 273.15
The
resistance of the thermistor changes with the temperature; however, the Particle Photon 2 only measures voltage. Therefore, a voltage divider was built using a reference resistor of 10kΩ. For this particular project, an NTC 10K/B3950 1% Thermistor was used. It has a nominal resistance of 10kΩ at 25°C and a beta coefficient of 3950 (change these values in the fish_tank code if using a different thermistor).
An additional Particle Photon 2, named HAL_9000, is subscribed to the data published by fish_tank. HAL_9000 calculates the hourly average for both temperature and TDS. If either hourly average falls outside of the desired range, a message is published to the Particle Cloud. fish_tank is subscribed to the event FishTankStatus.
If the status is not good, fish_tank publishes the event clean_tank
. This event is integrated with IFTTT, such that when it is published, a notification is sent to the user's phone, letting them know that the TDS is above the acceptable range and the tank should be cleaned. A nominal TDS value for a fish tank is around 400 ppm. clean_tank
is triggered when the hourly average exceeds 600 ppm (this value can be adjusted to meet your needs).
The data published every 10 minutes by fish_tank is integrated with ThingSpeak using WebHooks. fish_tank publishes a message contain both variables as well as the API key for ThingSpeak. The integration is setup through the Particle Console and sends data through a JSON format.
On the ThingSpeak end, the channel Fish Tank Monitor is configured to accept the two fields of TDS and Temperature:
The following function runs every ten minutes on fish_tank, sending the data to ThingSpeak:
void publishToThingSpeak(float avgTDS, float avgTemperature) {
char msg[256];
snprintf(msg, sizeof(msg), "{\"1\":\"%.2f\", \"2\":\"%.2f\", \"k\":\"%s\"}", avgTDS, avgTemperature, myWriteAPIKey.c_str());
Particle.publish("data", msg);
}
This data is logged and graphed by ThingSpeak. A sample of the live graphing is pictured below. Live data can be found at: Fish Tank Monitor - ThingSpeak IoT.
When the hourly average TDS exceeds 600 ppm, the IFTTT app on the user's phone sends a notification.
This functions through the event clean_tank
which is published by fish_tank. A WebHooks integration is triggered by this event in the Particle Console.
The following IFTTT applet was created. It is triggered by the WebHook and sends a notification.
Comments