You're on our GB site browsing in US. Switch over to browse in your local language.

Project

Home Automation For Your Critters

Scroll down

For most of my life I have kept reptiles and fish, and I have also enjoyed computers and tech projects. With this project I was finally able to combine my passions. I initially set out to write my own software that would run on a single board computer like a Raspberry Pi or a BeagleBone. I started prototyping the design, laying out the features I wanted and how I wanted to implement them, all the things you do when starting a new project. This specific project was intended to control the environment for my Veiled Chameleon (Chamaeleo calyptratus). They have fairly specific needs; a temperature gradient, a humidity window of 70-90%, a day/night cycle, and the biggest thing is they need to be misted multiple times a day because they do not drink from standing water. So with that the project had the needs outlined. I needed to be able to:

  • Monitor temperatures in multiple locations and turn the heat and UV lights on and off to create a consistent day/night cycle
  • Monitor Humidity and adjust as needed
  • Control a misting system of some sort

And the stretch goal –

  • Pull weather data from a location in the world and recreate it.

So with those goals in mind I went to the internet to find any open source projects I could potentially utilize to make some of those goals easier, and found my project done for me already in the form of TerrariumPi – https://github.com/theyosh/TerrariumPI

TerrariumPI is an opensource GPLv3 licensed habitat control system that checked all my boxes and more, even the weather one. It’s actively maintained and at 3 years old has a nice mature stability about it. The author has added support for many different types of sensors and also IOT switches and outlets to make your setup relatively easy. For my setup everything is ran through the Pi using basic relays and sensors.

Setup Your Pi

Below I’ll describe the process of building the control electronics and setting up the server so you can access your animals habitat from anywhere. We’ll start with the electronics, you will need a Raspberry pi (Zero, 2, 3, or 3B+) and your MicroSD card. TerriariumPI is made to work with the Raspbian Stretch Lite distro so make sure you get the right ISO at: https://www.raspberrypi.org/downloads/raspbian/

Then use a tool like https://www.balena.io/etcher/ to flash your SD card with the Lite image.

Once the image is flashed, eject the MicroSD and then plug it back into your PC so that it mounts and we can setup SSH and Wifi if you plan to use wifi with your habitat.

Open the BOOT partition of the MicroSD. This will be the only partition readable if you are on windows.

To enable SSH create a new empty file in the root directory called “ssh” with no extension. This will let the Pi know to enable SSH on first Boot.

To enable wifi create a file called wpa_supplicant.conf and add the following code inside it:

country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
   ssid="your_wifi_ssid"
   scan_ssid=1
   psk="your_password"
   key_mgmt=WPA-PSK
}

Change “your_wifi_ssid” and “your_password” to the real values for your network and save the file. You can eject the MicroSD from your PC and plug it into the Pi and power it up now.

Once powered up we need to find the IP address our router assigned to the Pi. You can log into your router and find the “raspberrypi” entry or I like to use an app called “Fing” on my phone that will show all the connected devices on a wifi network and their IP Address.

Once we have the IP we can SSH into the pi to do our installation of TerrariumPi using for favorite SSH client like Putty for windows or the terminal for Ubuntu or OSX:

ssh pi@Your.pi’s.IP.Address

Remember the default password for the Pi is “raspberryand you need to change that immediately. Once you’re logged into the pi change the password with:

pi@raspberrypi:~ $ passwd

Changing password for pi.

(current) UNIX password:

Enter new UNIX password:

Retype new UNIX password:

Pick a good non-dictionary password as this will be connected to your network.

From there I like to immediately update my install with:

sudo apt-get update

sudo apt-get upgrade

Next we’ll start the TerrariumPi install by installing “git”

sudo apt -y install git

Then use git to clone down the latest TerrariumPi Directory

git clone --recursive --depth 1 https://github.com/theyosh/TerrariumPI.git

Enter the new TerrariumPI folder
cd TerrariumPI

Run the installer script and wait (first install takes about 45 minutes and has a couple prompts)
sudo ./install.sh

Reboot Raspberry PI to get all the needed modules loaded
sudo reboot

Go to the web interface at http://[raspberry_ip]:8090

I also found this repo useful for troubleshooting my DS18b20 temperature sensors: https://github.com/timofurrer/w1thermsensor

Case Build

Now to build the physical hardware. You will need an enclosure to hold all of your electronics and protect them and you. For the enclosure it can really be anything that will safely house the electronics. I used a great website called boxes.py, specifically the electronics box, to create laser-cuttable box with finger joints to put my electronics in. These are the settings I used for my box because I wanted a lot of room for future expansion.

Once you get your settings the way you want click generate and it will open a new tab with the SVG. There are other export options like DXF but I had issues opening those files, so I stuck with SVG. Next Bring it into your laser software of choice. I use LightBurn for my lasers.

Once I brought this in, I also brought in another SVG I drew in Inkscape to add mounting holes for my Din rail and other components and added that in.. I also repositioned the large rectangle at the top out of the cut area and to an uncut layer as I wanted to cut that from PET-G sheet later so you could see into the box, and I repositioned a couple of the parts for more efficient material usage.

In the above drawing it is set so only the black vectors will be cut, the red and magenta are turned off for the current operation.

After cutting glue up the box and clamp the box

From here I screwed down the DIN rail and snapped in the Pi and Relay Board boards, and screwed down the 12v power supply and start wiring.

Setup The Electronics

First let’s wire the solder the sensor cables to an extension to the box.

The DS18b20 temperature sensors can all be soldered together as they transmit on a 1wire protocol. They they need an i/o pin, 5v and ground. So go ahead and match all the colors up ( Red to red, Yellow to yellow , etc) *image*

The AM2303 needs its own i/o pin and it also needs to be on 3.3v rather than 5v. The Ground can run on the same wire as the DS18b20.

Solder these to your multi-conductor cable, taking note of what colors are what if you weren’t able to match colors all the way through.

Next we can move to actually wiring the box up. Here is a basic diagram of how my box is wired.

In my setup I am using a water solenoid hooked to my main plumbing in my house and using the municipal water pressure to run my misters. If you wanted to use a water pump for this purpose you need to look for a diaphragm type pump with a pressure cut off around 70PSI that pumps around 0.5-0.7 GPM. These are the type of pumps that are used in commercial misting systems. The high point of these is they have a limited water supply to draw from, but can be noisy and are expensive.

Configure TerrariumPi

Next we will define the your access and unit preferences in TerrariumPI.

  • With the Pi powered up go to  http://[raspberry_ip]:8090 to get to the web interface for Terrarium PI
  • Go to System -> Settings in the sidebar to change the admin and password names.
    • Default is U: admin P: password
  • Hit submit at the bottom of the screen and enter the OLD username and password in the prompt. This will activate your NEW username and password.
  • Go through and update the units to your preferences.  
  • Hit submit again and wait for confirmation that your changes were saved.

Now let’s add the Temperature and humidity sensors to get your terrarium, fish tank or whatever automated!!.

  • Click Sensors on the side bar and then settings.
  • Click the + in the top right to add a sensor.
  • In Hardware for the DB18b20 sensors select “1wire”.
  • In Type” select “Temperature”.
  • Give it a Name. Make it descriptive, it’s what it will be called everywhere else in the software.
  • Alarm Min/Max define when an alarm is shown on the home screen.
  • Limit Min/Max define the boundaries of the graphs.
  • Max Diff is the max value the sensor can change.
  • Once those are entered click and then Submit at the bottom of the sensor screen. make sure you get confirmation of saving.
    • If you don’t get confirmation check that the sensors are wired properly and register with the “w1thermsensor” repo linked above.
  • Follow the same steps for the AM2302 sensor with the following changes
    • Hardware = AM2302
    • Type = Humidity
    • Address = *physical pin on Pi* Check https://pinout.xyz/ if you are unsure of the physical pin.

Next is the switches. These will flip your relays on and off based on timers, sensors, weather data, and simply clicking on an icon to trigger it. They can control almost anything and you can even add multiple switches to the same I/O port to have it triggered at different times for different periods of time for example.

  • Like the sensor click Switches and Settings and then + to bring up the switch dialog.
  • Pick GPIO and put the *physical pin* number of the output that is triggering that relay.
  • Give it a Name
  • Power Usage in Watts and Water flow in L/m are used for the graphs. If you dont know their values you can just use 0 for now. They have to have values in both.
  • Timer enables or disables the timer for triggering the I/O.
  • Click Add and then Submit after you add each switch and test them
  • Once you add the switches go to the Switch – > Status page and from there you can click on the Power Icon to manually trigger the switch to test it.
    • If they trigger incorrectly (eg: ON when it should be OFF) delete that switch and make a new one with GPIO INVERSE  in the Hardware dropdown.

Add A Webcam

The last thing we’ll add is a webcam. I used a Logitech USB webcam, but TerrariumPi also supports PiCams, and remote cameras. To get the USB camera working, you’ll need to do the following.

  • SSH into the as we did in the initial setup
  • Install fswebcam on the pi
    • $ sudo apt-get install fswebcam
  • Take a picture with the camera to see the cameras address in raspbian
    • fswebcam image.jpg
    • This command will show the following information:

--- Opening /dev/video0...
Trying source module v4l2...
/dev/video0 opened.
No input was specified, using the first.
Adjusting resolution from 384x288 to 352x288.
--- Capturing frame...
Corrupt JPEG data: 2 extraneous bytes before marker 0xd4
Captured frame in 0.00 seconds.
--- Processing captured image...
Writing JPEG image to 'image.jpg'.

  • Go to the Webcam -> Settings menu on the side bar
  • Hit the + to add your camera and fill in the info. For my camera (Logitech C270) it was this
    • Location – /dev/video0
    • Name – *Name of your feed*
    • Resolution – 1280 x960
    • Picture Rotation – 0 degrees
    • Archive – *when it takes the pictures*
    • Archive  Light State – Determines if the camera cares whether the lights are on or off
    • Archive door state – Determines if the camera cares whether the doors are open or closed.
  • Go to the Webcam -> status page to see your webcam feed.
    • If the feed doesn’t show up you may need to reboot for the software to see the camera.

At this point you should have the basics of TerrariumPi functional and your enclosure is automated!! The possibilities with the software are just starting now though. If you go to System -> Environment you can set your lights and mister to come on based on the weather in the part of the world you are trying to recreate, you can set up music to play when your lights come on, you can even get a text message when your webcam sees your lizard move!!

Created by Joe Spanier

Like what you read? Why not show your appreciation by giving some love.

From a quick tap to smashing that love button and show how much you enjoyed this project.