Node.js + raspberry pi + aquarium = awesome!

Melissa and I recently bought a new aquarium. The tank is set up now and is currently cycling. We plan to get about 3 or 4 fish, with a German Blue Ram as the centerpiece fish. One of the things I really like about our tank is that it has a separate day/night LED lighting system in it. Power is reduced and night-time lighting is a little more realistic, but there is a major downside: there is no automation on the lights. There is a physical switch that you throw to switch between the lights and off, meaning we can't throw it on a standard electrical timer.

Being the enterprising yet lazy programmer that I am, I couldn't just allow this situation to stand. I already have a Raspberry Pi that was just lying around (I originally intended to use for a sleep project but I got sidetracked with other projects). So I decided to get to work.

Using a Raspberry Pi just to turn lights on and off at a preset schedule isn't a very good use of the hardware though, so I started brainstorming other cool things I could do with it, and I've settled on the following features for v1:

  • Lights will be switched automatically each day by querying an internet service for sunrise sunset times.
  • Delays/offsets from sunrise/sunset can be configured so that lights can mimic daylight breaking, which tends to be a little off from actual sunrise times
  • Switch to manual control
  • Have a web server running on the Raspberry Pi that clients can connect to to set the configuration options

That's a much better use of the hardware :)

So far I have implemented a few odds and ends in node.js and have designed the interface circuit. On the software side, I implemented a new logging library for node.js called transport-logger that is inspired by winston (you can install it via "npm install transport-logger"). The schematic for the interface circuit is shown below

Aquarium Schamtic

The circuit is pretty simple. Starting at the connector for the Raspberry Pi, we go into a Texas Instruments CD40109B level shifter that converts the 3.3v signals from the Raspberry Pi to 5v levels (and provides a little protection in the process). The level shifter is powered by an ON-semi LM2574N 5v switching regulator. The 5v output signal from the level shifter controls the coils on two relays that are connected to the day and night LED setups. The relays are given power from the switch, which is in turn powered from the main aquarium supply. The switch allows me to either turn off the sytem entirely, or bypass the raspberry pi in case I need to remove it but don't want the lights to turn off. Below is a photo of some testing I was doing on a breadboard where I tested powering the relays from the switching regulator.

Breadboard Testing

All of the project is being hosted on GitHub and all software, schematics, layouts, etc are released under the GPLv3 license.

UPDATE: Some people have been curious how I installed node.js on my Raspberry Pi. It has to be done manually, but it's really easy. Download node.js from their website by browsing all release files at http://nodejs.org/dist/. As of this writing, the latest version that has an arm build is 0.10.6 at http://nodejs.org/dist/v0.10.6/node-v0.10.6-linux-arm-pi.tar.gz. For some reason, 0.10.7-0.10.9 doesn't have builds...hopefully they will start building for the Raspberry PI again. Once you've got the file, unzip it on your raspberry pi and add the bin folder to your PATH and you're up and running!

UPDATE 2: Looks like there are ARM builds of node.js again. The latest version as of this update with Raspberry Pi support is 0.10.13: http://nodejs.org/dist/v0.10.13/node-v0.10.13-linux-arm-pi.tar.gz

UPDATE 3: The project is finished! To see the details on the final product, checkout Anatomy of a nodebot powered aquarium part 1: overview