Posted on

Network aquarium temperature monitoring with raspberry Pi

aquarium temperature monitor

Monitoring aquarium conditions is an essential part of keeping Neocaridina shrimp, they are sensitive to changes in conditions like temperature, excess nitrites (and other pollutants) or too much or too little hardness.

From hardness to pH and from nitrites to temperature, there’s a lot to monitor and in smaller tanks, they can change quite rapidly. So we thought we’d take a break from articles about things like shrimp food and share details of an aquarium & digital technology project we’ve found both rewarding and useful.

We’ve often wished for an easier way to take and record all these readings, it’d be nice if sensors measured parameters and logged them for us to view on our various devices. We searched around but we’ve yet to find a device that can simply ‘do it all’ and being quite modern folk we want our data in a digital format so we can easily access it and visualise it properly. So after some googling we realised that having all our parameters checked by a digital probe is an unrealistic goal. Chemical testing with strips or fluids are essential for measuring most parameters which makes an automatic tester device way too complex an idea for our small shrimp tanks.

Despite there being no perfect solution, we still wanted to make aquarium managing easier so we decided to start with temperature. Temperature is much easier to measure and log so it should be possible for us to find a way to solve this problem for ourselves.

Aquarium temperature monitor in shrimp tank
Here you see one of our tanks with the Pi and probe.

Raspberry Pi project to make aquarium temperature sensors

After some reading around we formed a plan based around the Raspberry Pi micro computer, a waterproof temperature probe and an open source linux application that connects to sensors and logs the data.

We picked out some cases and made some changes to them to suit our needs. In this article we thought we’d share how to build your own temperature sensor system like ours and how the whole thing turned out for us.

Equipment list

  • Raspberry Pi Zero W
  • Good quality Pi power supply
  • Decent Micro SD card at least 4GB in size (8GB or bigger is probably best)
  • Waterproof DS18B20 temperature probes with wiring board
  • Female to female terminal connection wires
  • Small Pi heatsinks
  • UniPiCase (Tall size)
  • 2 x ‘Top Hat’ Tattoo Machine Grommets per probe (we’ll explain later)
  • You might need a UPS battery backup for a reliable result, the temperature sensors have proven sensitive to power variation even with a good charger

Getting started – Getting the Pi working as a computer

First thing to tackle is setting up the Pi. If you are experienced, this is a doddle, if not there may be much to learn. Pi OS Lite is a ‘command line only’ operating system, if you aren’t sure what this means be ready to get your learn-on. In short, there’s no mouse or graphical display to use the computer, it’s all text. So moving, editing and viewing files is all done by keyboard commands only, as is everything else. If you’re used to clicking on things with a cursor, this can be quite difficult because little you might have learned about using Windows or MacOS prepares you for how things are done on the command line.

What you’re looking to achieve

  • Install Raspberry Pi OS Lite on your Micro SD card
  • Configure the Pi to connect it to your WiFi
  • Be able to SSH onto the Pi
  • Add a level of security you feel is reasonable

There are many guides online about how to do the basic setup of a Pi, we feel it’s best we don’t try to explain all the steps, they can change and there’s a huge community all about Pi basics online. If it’s your first time, we suggest you google these steps, spend some time online, watch some YouTube tutorials and have a play until you are happy. If it’s your first time on the command line, it may take some time to get the measure of everything.

Our tips in getting the Pi set up

  • We use PiBakery to image the OS to the SD card and set up much of our initial configuration
  • Security can mean many things, we recommend caution. You can read about lots of steps to improve security here: raspberrytips.com/security-tips-raspberry-pi

When you’ve got a Pi running on your WiFi that you can SSH to and are happy with your basic security steps, it’s time to move on to getting the hardware connected.

Temperature probe wires linked to a raspberry pi
We bought our probes with these handy terminals included. It makes it easy to screw down the wires into the correct slots and plug the jump wires onto the terminal.

Connecting the probe

The waterproof DS18B20 temperature probe is a simple, cheap but quite elegant piece of kit. It has a large temperature tolerance (-55°C to +125°C), can be very accurate (±0.5°C Accuracy from -10°C to +85°C) and has several operating modes making it versatile in a number of applications. On one end you have a metal probe sealed into a rubber wire coating and, on the other end, the rubber coating comes to an end to reveal 3 connection wires.

These are the wires that hook up to your Pi so the probe can work. You can do this with solder or provided you buy a temperature probe with a connection terminal, you can just use female to female ‘jumper wires’ and snap them on. For some projects solder is essential due to quite complex circuitry and the need for compactness, in this case we’re simply connecting 3 wires so we found jumper wires were easy, quick and so far work 100% fine.

GPIO Pins from Pi
This diagram shows the function of the pins on a Raspberry Pi

The probe has 3 wires

Red – The red wire is VCC or basically power
Yellow – This is the data wire (DAT)
Black – This is the ground wire (GND)

You need to connect your probe wires to GPIO pins on the Pi

Red, VCC goes to GPIO pin 1 (3.3v power)
Yellow, DAT to GPIO pin 7 (data)
Black, GND to GPIO pin 9 (ground)

Bear in mind that your wiring needs to stand up to a bit of wobbling and general bouncing inside the case so ensure they are nicely connected one way or another.

Temperature Machine

temperature data from shrimp aquarium
This is the local page served by the Temperature Machine package. Here we see temperatures from 3 aquariums. The one that varies a lot is in a warm conservatory, temperatures drop at night and rise in the day. Probably quite a lot like in nature, still we worry that it could get too high on very hot days.

Temperature Machine is a fantastic open source project by a guy called Toby Weston, this package makes the whole project possible so hats off to Toby & co. It runs on Debian Linux through Homebrew and will listen to the probe’s temperature readout, log it and then serve it on a local web page. It gives you a live temperature, a daily chart and 3 graphs. Those show temperature over 24hrs, 7 days and 1 month.

Make friends with the project site: temperature-machine.com

The steps to install are best followed from the package website, should we list them and the package changes, we’d end up telling you the wrong thing.

You can find the steps here: install temperature machine

Does it work?

At this point you should have a Pi you can log into safely, a connected probe and the installed Temperature Machine package. You should be able to visit the local page at the IP address of the Pi and the port 1190. For example: 192.168.1.25:1190

When you visit that page, you should see your temperature reading and a graph displaying the temperatures measured so far.

Tip about power

We found this all worked perfectly on the first attempt but then we had a string of confusing issues. After up to a day of working fine, the temperature probe would stop showing up on the readout and would not work again until the Pi was restarted. The weirdest thing of all was that it was only when we moved the Pi to the aquarium that this started happening. A long period of debugging, reading forums and testing things finally revealed that the issue was related to our plug sockets. Despite having few issues with electricity at all, we noticed that when the Pi was plugged into certain multi-plug boards to the mains, we’d see the temperature readout disappear from the graphs despite the Pi itself working fine throughout. These were quality, surge protected multi-plugs and yet the problem occurred.

We eventually solved it by using UPS power rather than direct from the socket. We already have UPS systems in the house, 2 of our Pi’s could plug right in. For the 3rd we bought a cheap one. All the issues ceased for good.

We recommend buying a quality power supply and seeing how you go. If you get these issues (it’s clear not everyone does) at least you can save yourself a lot of trouble by trying out different plug sockets and worst case, picking up a cheap UPS.

Raspberry pi for aquarium temperature in case
A UniPiCase (Tall size) with the probe secured by a tattoo grommet and a heatsink passing through the face plate to the inside.

Making it ready in the case for the aquarium

Apply a suitably sized heatsink to the CPU of the Pi. Helping it stay cool is important.

We wanted our case to be drip proof, thermally helpful and tidy.

We chose the UniPi tall case because there’s space for the probe wiring without having to be really compact and careful, it’s enclosed with no vent on the top (so any drips don’t go inside) and can be easily adapted. We actually set up 3 of these devices, two of our cases came with 2 small holes (intended for AV cables) and the other had just a blank plastic plate.

We wanted to secure the temperature probe cable to the case-plate so yanking the cable would not loosen it from the Pi connectors, we also wanted a good enough seal to prevent a drip of water moving down the probe and into the Pi. We found an unusual and effective solution!

You might have noticed Top Hat Tattoo Machine Grommets in our equipment list. After much searching around we found these little rubber grommets are a perfect tight fit around the probe wire. We used one on the inside and one on the outside of the case and shuffled them tight against it with the wire coming through. This holds the cable to the case and forms such a seal that a droplet would not make it through.

We also enlarged the 2nd hole in the case-plate (or created our own) with a Dremel to fit a 10mm x 10mm heatsink. We used a little thermal tape and foil to secure the heatsink in the hole with the fins on the outside and a foil coat on the inside. The idea is that with a relatively sealed case, the warm air inside needs a little help getting rid of its heat. So because a Pi Zero doesn’t get hot like the larger models, we felt a fan was overkill and an extra case-mounted heatsink would be enough even in hot weather. It’s proven plenty and it’s likely this extra heatsink isn’t even necessary but we like to build safe.

So with this completed you should have a nice sturdy case and a well secured probe wire, ready to be installed and used for real.

Aquarium temperature monitors
Here are 2 of our Pi setups. ‘AquaPi1’ is the server and ‘AquaPi2’ (and 3) are clients.

More than one

The greatest thing about the Temperature Machine package is that is was designed quite elegantly to operate as a little cluster of Pi’s potentially each with multiple probes and display all the data on one local web page.

To do this, one Pi acts as a server and the others as clients reporting to the server. Read about the setup and installation steps of Temperature Machine for full details on this. We set up 3 in total so that’s one that serves the page with all the results (including its own temperature probe) and 2 more that just log the results and report them to the server Pi.

The finished product

Now we have 3 working in separate locations all reporting the temperature, we’ve been able to monitor our tanks temperature with great ease. If a heater breaks or a fuse goes and our tanks get cooler (or too hot), we’ll notice within 8 hours for sure. One of our tanks is in a conservatory that gets quite hot indeed in the summer, this system helps us keep an eye on it to ensure it’s not getting too hot. With a VPN connection into your home, you are able to log in to look at temperatures wherever you are in the world, it adds peace of mind if you’re away from your aquarium for a while.

Since we solved our weird power related bug, we’ve had 100% uptime from all probes at all times, it’s reliable.

So that’s it! You can build your own temperature monitors for your aquariums and take one water conditions monitoring task off the list.

Extra tips

– Be sure to increase the size of the SWAP file to at least 1024 MB, it can help the Pi from running out of RAM in some circumstances

– Don’t buy cheap SD cards, this is your computers hard drive, getting a relatively quick one that’s likely to be reliable is worth the extra cost. We chose SanDisk Max Endurance cards, you can get faster (though the Pi can’t run the fastest cards at full speed) but we found these were the most likely to last.

– Backup your Pi OS. We use the terminal command ‘dd’ to take an image of the entire SD card on the Pi. You can compress as part of the command but we’ve found it’s more reliable to image without compression and compress afterwards. We backup the Pi image to our Mac, compress it and then transfer it to backup storage. The image before compression is the same size as your SD card so just be sure you have enough disk space on your Mac to receive the backups. Compression reduces the backup file to almost the same size as the actual disk usage on the Pi (i.e 16GB comes down to 3GB or so). When taking these backups, it’s a good idea to get a new SD card and test the restore command, swap that SD card into your Pi and make sure your backup gives you a restored and functioning machine. If you wait till your SD card fails to try your first restore, you might find there’s been a problem all along and your system will need totally reinstalling.

– Don’t let it touch the heater. Quite obvious but ensure the probe or its wire is not going to end up touching the aquarium’s heater.

– Keep it out of the bubbles. If you have a bubbler, ensure your temperature probe isn’t in the path of the bubbles, we saw strange readings of minus temperatures occasionally on one of the probes after a water change and found had moved to be in the path of the bubbles. We have no idea why this turns out as a negative temperature but once moved, things went back to normal.

Need a little help?

We are not experts in this technology but we have some decent experience and know linux pretty well. If you’ve followed our steps and are having a problem, we might be able to help so feel free to send any query to us through our contact form.

Shrimp Food

Plants