Pi Fish Tank Sensor Proving Ground

I have a soft spot for sensors and data, seems I’d much rather work on projects to collect data then anything kinetic (it probably harkens back to my days as a Data Analyst, in the days before they were called “Data Scientists” at the Center for Astrophysics). And so I built a weather station a while ago and I wanted to try out adding some different features or technology to it without breaking or corrupting the data. I had the idea that I could use a spare Raspberry Pi Zero W (this one I accidentally dropped which damaged the mini HDMI port and the smartcard holder so it’s not useful for the workshop anymore) and a Waterproof DS18B20 Digital temperature sensor (https://www.adafruit.com/product/381) to create a simple temperature monitor for my outdoor Koi tank that I could use as  proving ground for adding on features to the existing weather station. 

The setup is very simple a straight forward. The pi was placed in a case and attached to the backside of the filter with double sided tape. 

Mounted & wired Raspberry Pi Zero W, DS18B20, and 4.7kΩ resistor.

The wiring for a 1-wire temperature sensor is pretty easy. It’s just power, ground, and the data line with a 4.7kΩ resistor across the power and data lines. Here’s the wiring:

Pi Zero, DS18B20, and a 4.7kΩ resistor

The software is also pretty simple, I wrote a very straight forward Python script to poll the temperature about every 5 seconds and record it in a very simple Postgres DB (hosted separately). It also uses a config file to specify the pins and the DB connection. Code is pubic in a Github repository.

The plan moving forward is for at least two upgrades. One, I’d like to add MQTT (Message Queuing Telemetry Transport) which is a publish/subscribe messaging system, the reasoning being that the Pi can publish to a channel the temperature reading and then other systems subscribed to that channel can read and use that data, such as Home Assistant (which is the home automation platform I use) which can display and graph it. I can probably find different ways to use that data, and then the weather station data to make some devices/systems “smarter”, such as not watering the lawn when certain conditions are met.

The second planned upgrade is switching to a Time Series Database (TSDB) instead of Postgres. Since this is all time related sensor data using a TSDB makes sense compared to a traditional RDB, and then I think it’ll be easier to graph and do trending on that data then the current setup in Postgres. I also already have a TICK stack (https://www.influxdata.com/time-series-platform/) running in my network and I think it’ll be cool to get some Chronograf dashboards going with this and the weather station data.

So that’s the plan, this setup helps get the ball rolling and an area to safely play before implementing it on my weather station. Hopefully, I should have some posts in the future relating my experiences with getting at least these upgrades implemented.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.