This is a quick project I put together to control an 8 channel power relay connected to a Raspberry Pi that control various aquarium equipment. It then ballooned into an ever-growing monitoring platform. Currently you can toggle and get the status of outlets, view temperatures and trends, view cooling status, view a live feed, and monitor your ATO (Auto Top Off) reservoir level. I plan to add support for ph probes, salinity probes, light timers, and more.
You will need a Raspberry Pi, an appropriate relay, wiring, and sensors. You can view pictures of my build here.
Here are the parts used in my build.
- Raspberry Pi B+: Link
- 8 channel power relay: Link
- DS18B20 Sensor: Link
- HC-SR04 Ultrasonic Sensor: Link
- HD Pro Webcam C920: Link
Here are some links I used to help get my build completed.
- Wiring a DS18B20 sensor: Link
- Wiring for multiple DS18B20 sensors: Link
- GPIO pin reference: Link
- HC-SR04 wiring: Link
This app is written in Python and uses Flask with a few other modules that should be pre-installed. You will need to install the below modules.
pip install flask
pip install DS18B20
pip install numpy
sudo apt-get install libopencv-dev python-opencv
This application relies on Supervisor to ensure processes are running and autostart with the OS. Install supervisor by running:
sudo apt-get install supervisor
systemctl enable supervisor.service
Once installed ensure Supervisor is configured to run the application and its scripts. You can find my supervisord.conf here.
Once your build is complete we need to tell the application what pins are connected to each sensor or relay. The configuration files can be found under config.
outlets.json contains information that the application needs to control the relay. This relay switches power on and off to the outlets.
[{
"name": "Outlet 1", ##Friendly name of outlet.
"desc": "Protein Skimmer", ##Description of what is plugged into the outlet.
"status": "", ##Will be used in the app to display the outlets status.
"pin": "13", ##GPIO pin the outlet/relay is connected to.
"feed": "" ##Determines if outlet is used for feeding.
}]
temperaturesensors.json contains information that the application needs to sense temperature and trigger cooling if configured. Currently the application only supports 2 temperature sensors. Once your sensors are setup you can find their addresses by running:
ls /sys/bus/w1/devices/
[{
"type": "temperature", ##The type of sensor.
"name": "Overflow", ##Friendly name of the sensor.
"address": "0417207e4eff", ##I²C sensor address. See above for command to locate this.
"temperature": "", ##This will be populated in the application.
"temperatureaverage": "", ##This will be populated in the application.
"csvid": "2", ##The index used when reading from the CSV to get the average temperature.
"temperaturecorrection": 1.04, ##Temperature correction amount.
"temperaturethreshold": 77, ##Threshold at which we turn on cooling.
"pin": 21, ##Pin we toggle with we reach the threshold above.
"pinstatus": "" ####This will be populated in the application. Tells us if coolling is on or off.
}]
processes.json contains information that the application needs to track the status of processes. The app does not start or stop services it only tells you their status.
[{
"type": "Python", ##The type of process.
"name": "tempcontroller.py", ##The name of the process.
"command": "python tempcontroller.py", ##The command used to invoke the process.
"pid": "", ##The PID of the process. Populated by the application.
"status": "" ##The status of the process. Populated by the app.
}]
ato.json contains information that the application needs to sense the level of the ATO reservoir.
[{
"type": "ultrasonic", ##The type of sensor.
"name": "ATO Reservoir", ##Friendly name of the sensor.
"triggerpin": 18, ##The pin used to send pulses.
"echopin": 24, ##The pin used to listen for pulses.
"capacity": 39.5, ##Measured empty "capacity" of the reservoir. Measurements are in CM.
"uppercorrection": 6.5, ##Correction to account for the distace between the sensor and the level of the water at 100% capacity.
"percentfull": "" ####This will be populated in the application.
}]
I am running the application via Supervisor. To get up and running quickly, you can run:
python app.py
This will start the application in debug mode on 0.0.0.0:5001.
- As stated before I am using Supervisor to run Flask. My
supervisord.conffile is included under misc. - I am using amazon-dash for an IoT Amazon dash button to control outlet groups. This config is also included in misc.
- In the even of a power failure all outlets default to an on status. I am using
systemdfor this. The unit file and script to power on the outlets is once again, included in misc.
- Flask - Flask is a microframework for Python based on Werkzeug, Jinja 2 and good intentions.
- ds18b20 - This little pure python module provides a single class to get the temperature of a DS18B20 sensor.
- SB Admin 2 - A Bootstrap admin theme, dashboard, or web app UI featuring powerful jQuery plugins for extended functionality.
- dygraphs - dygraphs is a fast, flexible open source JavaScript charting library.