Top Banner
Automating a fishtank with python and IoT sensors Ben Chodroff, CTO - CloudOne
14

IoT Aquarium

Feb 08, 2017

Download

Technology

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: IoT Aquarium

Automating a fishtank with python

and IoT sensorsBen Chodroff, CTO - CloudOne

Page 2: IoT Aquarium

Why?• I accidentally left the RO water running after a water change and the

tank overflowed• Solutions:

• Use a timer while filling my tank or…• Over engineer a solution

Page 3: IoT Aquarium

Over Engineering It• Collect data points on tank:• Water pH• Water Temperature• Water level• Filter flow• Light state (on/off)• Topoff state (on/off)

• Automate dosing• CO2 solenoid• Chemical dosing

Page 4: IoT Aquarium

Platform: Raspberry Pi• Cheap and well supported ($30-$60) • Provides full Linux environment:

https://www.raspberrypi.org/help/noobs-setup/• Easy to interface to most digital hardware sensors via GPIO pins • Provides python environment (easier than TI LaunchPad/Arduino for

generic tasks)• Camera integration via RaspiCam ($23):

http://www.amazon.com/Raspberry-5MP-Camera-Board-Module/dp/B00E1GGE40• Easy to WiFi enable ($8):

http://www.amazon.com/Kootek-Raspberry-Wifi-Dongle-Adapter/dp/B00FWMEFES/ref=sr_1_2?s=pc&ie=UTF8&qid=1439503682&sr=1-2&keywords=raspberry+pi+wifi

Page 5: IoT Aquarium

Sensors – 8 Channel relay control• Control up to AC 250V 10A or DC 30V 10A devices• CO2 solenoid (AC 120V)• Dosing peristaltic pump (DC 12V)• LED’s, Filters, heaters, etc.

• Bought on amazon for $9: http://www.amazon.com/JBtek-Channel-Relay-Arduino-Raspberry/dp/B00KTELP3I/ref=sr_1_2?ie=UTF8&qid=1439503217• Super easy to hook up – connect ground and voltage pins, then

connect GPIO pins to each relay controller• Use Python GPIO library to set each pin to high or low

Page 6: IoT Aquarium

Sample Code – 8 Channel relay control

Page 7: IoT Aquarium

Sensors – Water Level• eTape Liquid Water Level Sensor: buy on adafruit.com ($40-$60)• Similar to a thermistor – resistor that varies based on the water level • Measure the water level by taking a known voltage (3.3v) and detecting how

the sensor alters the voltage [Voltage divider circuit - requires some basic circuit knowledge]• Raspberry Pi has no ADC - use a MCP3008-I/P ($4 on digikey.com)• Guide on using MCP3008 with Raspberry Pi:

https://learn.adafruit.com/reading-a-analog-in-and-controlling-audio-volume-with-the-raspberry-pi/overview• Guide on using a thermistor in a voltage divider circuit with MCP3008:

http://www.paulschow.com/2013/08/monitoring-temperatures-using-raspberry.html

Page 8: IoT Aquarium

Voltage Divider – ExplainedWe measure the voltage by seeing how much it has dropped based on the sensor. If the sensor (THERM) resistance increases, we see less voltage. If the sensor resistance decreases, we see more voltage. We create this voltage path by having ground pull the voltage down through a fixed resistor (R1).This allows us to fix a (more or less) linear model to determine the level of the water. We pass the digital pin to our ADC to convert from an analog voltage to a digital representation

Page 9: IoT Aquarium

Sample Code – Water Level

Page 10: IoT Aquarium

Sensors – pH, Flow meter, and temperature• Atlas Scientific• Crème de la crème – worth every penny (or about $400)

• Reliable, high quality, and best of all - prebuilt serial circuits [no skill required]• Use PWR-ISO module for power isolation: avoid ground loops and other electrical noise!• Serial Expander – Control up to 4 separate serial devices even though your Raspberry Pi

only has one serial connection• Digital Temperature > cheaper analog probes: easier to calibrate, easier to

integrate, high quality• Flow Meter includes filter to prevent “gunk” from ruining meter, “just works”• pH probe is high quality, easy to calibrate, easy to read

Page 11: IoT Aquarium

Sample Code – Atlas Scientific Sensors

Page 12: IoT Aquarium

Video• RaspiCam is incredible – 1080p live video streaming to Youtube• How to make it work• Create a Live stream (free!): https://www.youtube.com/live_dashboard• Create a bash script and enter your server and key • Download optimized ffmpeg for ARM (required!):

https://www.reddit.com/r/raspberry_pi/comments/2ahzp2/raspberry_pi_encoder_live_streaming_to_youtube/

Page 13: IoT Aquarium

IoT Dashboard• Freeboard.io• Great dashboards out of the box• Free hosting and open source• Possible to integrate with MQTT

• MQTT using IBM IoT Foundation• Free• Extremely fast IOT message transport

• Paho MQTT client (javascript):• https://rawgit.com/benjaminchodroff/freeboard-mqtt/paho-mqtt-default/ibm.iotfoundati

on.plugin.js• https://rawgit.com/benjaminchodroff/freeboard-mqtt/paho-mqtt-default/paho.mqtt.plugi

n.js• Integrates to Freeboard plugin through “Developer Console”

Page 14: IoT Aquarium

Next Steps• CO2 sensor coming soon (Atlas Scientific)• Creating an enclosure• Scheduling events (topoffs, dosings)• Monitoring and alarms• Data analytics using hadoop/spark