Introduction: Smart-Enough Outdoor Cat House
Not quite satisfied with cutting a hole in a Rubbermaid container and filling it with straw for your cat? If this doesn't get you where you're going, it'll at least help along.
This Instructable will focus on getting a Raspberry Pi set up to read a temperature, and use that information to control a heating pad inside the cat house. It will also stream a live camera feed to other devices on the local network.
Materials & Parts You'll Need:
Raspberry Pi (2B used here)
Raspberry Pi Camera (NoIR) - https://www.amazon.com/gp/product/B00KX3HS4K/ref=o...
IR LEDs (https://www.amazon.com/gp/product/B01BVGIZGC/ref=o...
Male USB plug (to power the IR LEDs)
USB Wireless Adapter - https://www.amazon.com/gp/product/B003MTTJOY/ref=o...
DS18B20 Temperature Sensor - https://www.amazon.com/gp/product/B008HODWBU/ref=o...
~4.7KOhm Resistor (Temp sensor pull-up resistor)
~39Ohm 1/8W Resistor (To set the IR LED current)
Solid State Relay (I used a way over-sized Crydom 2410-10 I had lying around, although a traditional AC relay with a 3V coil would work as well - http://www.mouser.com/ProductDetail/Crydom/D2410-...
5V 2.5A Power Supply for the Pi- https://www.amazon.com/gp/product/B00MARDJZ4/ref=o...
Heating Pad - https://www.amazon.com/gp/product/B00075M1T6/ref=o...
Electronics Enclosure - https://www.amazon.com/gp/product/B01M6YRA2N/ref=o...
SD card for the Pi (at least 8 GB; 16GB used here) - https://www.amazon.com/gp/product/B00IVPU7KE/ref=o...
M-F Jumper wire (something like https://www.amazon.com/PeleusTech%C2%AE-Multicolo...
Heat shrink tubing (preferred), or electrical tape to cover solder joints
5 Wire nuts
Scrap plywood
Scrap styrofoam sheet insulation
Cat door (something like https://www.amazon.com/OxGord-Flap-Doors-Lock-Ent...
Silicone
Tools I Used:
Saw to cut wood - I used a table saw and jigsaw
Soldering Iron
Razor blade to cut foam insulation
Electric drill & driver (a drill press is also nice but not necessary)
Wood chisel & mallet
----------------------------------------------------------------------
Before this Instructable starts, you'll need to have installed the Raspbian OS onto the SD card for the Raspberry Pi (Raspbian Jessie used here), and you'll need to have already connected it to your wifi network. You'll also want to enable SSH, so you can shut down the cat house Pi remotely if you ever need to unplug it (done through "sudo raspi-config"). There's already a boat-load of information on the internet for getting those things done, so there's no good point in me repeating it all here.
Step 1: Setting Up the Temperature Sensor
May as well dig into the meat and potatoes of how this thing works. The idea is for the raspberry pi to read the temperature from the inside of the cat house, and activate a relay to turn on a heating pad to re-heat the space once the sensor transmits a temperature below a certain threshold. We'll also want to set up a camera feed that can be accessed by anyone else on the local wifi network.
Let's start with the temperature sensor:
1. First, we need to add 1-wire support so we can communicate with the temperature sensor.
in the terminal, type:
sudo nano /boot/config.txt
scroll to the bottom of the file and add a new line:
dtoverlay=w1-gpio
Exit and save the document by typing Ctrl-X, Y, ENTER
2. Next, we need to get a handy 1-wire temp sensor python library via
sudo apt-get install python
sudo apt-get install python-w1thermsensor
3. Third, a python script must be written to read the thermometer, and do with that info what it will. I call that script kittytemp.py.
sudo nano kittytemp.py
import RPi.GPIO as GPIO from w1thermsensor import W1ThermSensor GPIO.setmode(GPIO.BCM) GPIO.setup(18, GPIO.OUT, initial=GPIO.LOW) while True: sensor = W1ThermSensor() temp = sensor.get_temperature(W1ThermSensor.DEGREES_F) if temp <= 72: GPIO.output(18, GPIO.HIGH) else: GPIO.output(18, GPIO.LOW) print tempf
Exit and save the document with Ctrl-X, Y, ENTER
The python script above sets the cat house temperature to at least 72*F. DEGREES_C can be used as an alternative to DEGREES_F
Next, we'll add the camera into the mix and make everything executable.
Step 2: Setting Up the Camera
1. To get the camera up and rolling, we need to make sure the Pi is up to date and has all of the necessary packages installed. Open the terminal and enter these commands:
sudo apt-get update sudo apt-get upgrade sudo apt-get install vlc sudo apt-get install cvlc sudo apt-get install raspivid
2. Next, we need to write a shell script that launches the video feed and the temperature control. I'm calling mine kittycam.sh:
sudo nano kittycam.sh
raspivid -o - -t 0 -hf -w 640 -h 360 -fps 25 | cvlc -vvv stream:///dev/stdin –sout '#rtp{sdp=rtsp://:8554}' :demux=h264 | python kittytemp.py
exit and save the document with Ctrl-X, Y, ENTER
3. Now we need to make another file to call the first script, I called mine kittycam2.sh
sudo nano kittycam2.sh
#!/bin/bash /home/pi/kittycam.sh
exit and save the document with Ctrl-X, Y, ENTER
4. Now we need to make the scripts we just wrote executable
sudo chmod +x kittycam.sh sudo chmod +x kittycam2.sh
5. Now we're going to use Linux Crontab to "schedule" that script execution every time the pi starts up.
crontab -e
at the bottom of the file, add a new line:
@reboot /home/pi/kittycam2.sh &
6. You may need to disable your login/password at startup to get everything running correctly. How you do that depends on which Raspbian installation you have... for Raspbian Jessie, it's done in:
sudo raspi-config
Step 3: Test the Camera Stream on Another Device
To watch the camera stream, you'll need to know the raspberry pi's local IP address and have VLC installed on whatever you're watching from.
1. To get my pi's IP address, I logged into my router and checked the client list, but you can also get it by typing the following into the pi's terminal (either with a monitor & keyboard plugged in or via SSH):
sudo ifconfig
The IP address will be under the "wlan0" section and look like "192.168.X.X"
2. Next, open VLC on whatever device you want to view the stream.
Go to "Media" --> "Open Network Stream..." and type:
rtsp://[IP].[TO].[THE].[PI]:8554
And from there, you should get a video stream with about a 3-ish second lag.
Step 4: Populating the Electronics Enclosure
I highly recommend putting your electronics in a sealed, waterproof enclosure if you want this house to stay smart for long.
In order for the camera to see inside the cat house, you'll need to supply a source of (infrared) light. I'll be using 3 IR LEDs wired in series, powered by a USB port on the Pi. This means the LEDs will be on as long as the Pi is on-- too light of a parasitic load for me to bother coming up with a more elegant solution. As long as the camera isn't motion-activated (it's not here), this method makes the most sense.
Comments in the pictures pretty much explain the rest of this step.
Step 5: Building the Cat House
To Build the house, I used scrap 3/4" plywood, scrap Styrofoam insulation, scrap cardboard, already-opened silicone (to create a seal between the electronics enclosure and the cat house, and around the power plug), and various deck screws I had lying around. Aside from the cat door, the house itself cost me nothing. Not pictured is a taped block of 2 sheets of Styrofoam insulation cut to fit snugly on the top of the insulated box, and the sheet of plywood that covers the entire cat house. I lined up the electronics enclosure with where I wanted to mount it on the back, and sharpie'd the wood exposed by the enclosure hole so I knew how big of a hole to make. From there, I drilled most of the hole out with a drill press, and finished it off with a 1/4" chisel & mallet.
As the main purpose of this Instructable is to focus on the smart side of the smart cat house, I'm going to skip most of the build process here, as there's not much to add to the Internet when it comes to building a wooden box-- I'll let the pictures do the talking. Once you're done, plug it in and you should get a reasonably-smart cat house.
After it's all together, it'd serve you well to sand and finish the exterior of the box for longevity's sake (unless you went a different route and used plastic or something)--- But you'll have to go to someone else's Instructable for a walk-through on that.
Step 6: Sources
Coding isn't a particular strength of mine. Here's a list of websites I used to gather the information necessary to build this project (A lot of the code used here is yoinked verbatim from below):
Adafruit's explanation of W1 thermal sensors - https://cdn-learn.adafruit.com/downloads/pdf/adafr...
Make's tutorial on Raspberry Pi GPIO and Python - http://makezine.com/projects/tutorial-raspberry-pi...
Poking around in this W1 library - https://github.com/timofurrer/w1thermsensor#usage-...