Intro: Raspberry Pi Pet Monitor
This Instructable will guide you through the setup of a (mostly) headless Raspberry Pi based pet monitor. This pet monitor will alert you whenever your pet becomes noisy by sending a Pushbullet notification. Also, if you would like, you can speak to the pet by using Mumble (VoIP Service).
Step 1: Materials
- Raspberry Pi B+ (Raspbian Wheezy 12.24.2014)
- 3.5mm Speakers
- Sparkfun Sound Detector
- 100kOhm Potentiometer (optional)
- Breakaway header pins
- Soldering iron and solder
- Jumper wires
Step 2: Prepare the Sound Detector
The sound detector has three outputs: gate, envelope, and audio. Currently this project only utilizes the binary gate output. In the future, the audio output may be used as well to allow the user to listen to the pet using Mumble. But before we can get that far the header pins must be soldered to the board.
The sound detector allows the user the adjust the sensitivity for the gate output by attaching a resistor across the two pins on the lower back half of the board. I connected right angle headers to these pins so that I could attach a potentiometer to adjust the sensitivity on the fly.
Step 3: Building the Circuit
The circuit for this system is fairly simple. The sound detector is grounded to a ground pin on the Pi and VCC is supplied by a 5V pin. I connected the gate pin to GPIO 0, however you can use whichever GPIO pin you like. If you use GPIO 0 there will be less code that you will need to modify later.
Optional: If you choose to connect a potentiometer across the gain pins, do so now.
Step 4: Setting Up the Environment
- Ensure that git is installed.
- If it is not, run the following
- dpkg - - get-selections | grep git
- If it is not, run the following
- Download the Wiring Pi library
- git clone git://git.drogon.net/wiringPi
- cd to the "wiringPi" directory and run the build script (./build)
- Verify that the library has been setup by running "gpio readall"
- If the library is correctly set up a table should appear showing the state of all GPIO pins.
- Create a directory that will contain the pet monitor. I will use ~/monitor in this example.
Step 5: Setting Up Pushbullet
- Create a Pushbullet account and log in.
- Create a channel. Make sure that you remember the tag that you choose. This tag will allow you to send alerts to multiple people at once. This can be useful if you would like to notify an entire family or multiple roommates, etc.
- Go to Pushbullet account settings and make a note of your access token. We will use this later.
Step 6: Compiling the Source Code
- Place the above source files in the directory created in the last step (~/monitor)
- If you decided to use a GPIO pin other than pin 0 then all references to pin 0 must be changed in listen.c.
- Change the path in line 35 to reflect your file structure
- ex: int fd = open ("/home/pi/monitor/events.log", O_APPEND | O_WRONLY | O_CREAT, 0666);
- Compile listen.c by running the following
gcc –Wall –o listen listen.c –lwiringPi
- Compile javac monitor.java
- chmod 777 petpush.sh
Step 7: Setting Up Mumble Server and Client
- Install the server
- sudo apt-get install mumble-server
- Configure the server
sudo dpkg-reconfigure mumble-server
I would suggest having the server autostart with high priority to keep the audio quality high.
sudo nano /etc/mumble-server.ini
Feel free to edit as much as you would like in this file, but I would suggest editing "serverpassword" at a minimum.
sudo /etc/init.d/mumble-server restart
The server can now be joined by any device running a Mumble client.
- sudo apt-get install mumble
Step 8: Running the Monitor
- There are two ways to do this:
- Run the monitor automatically when the Pi boots
- Run it on demand
But first, there are a few configuration options you should be aware of to prevent you from receiving Pushbullet spam. With this system you are able to define how often the sound detector can detect noise before alerting you. To do this, you have to specify both the number of times and the time window. These values will be used in the next steps.
- Automatic execution at boot
- Edit /etc/rc.local (sudo nano /etc/rc.local)
- Under the comment, add the following
sudo -u pi touch /home/pi/monitor/events.log
sudo /home/pi/monitor/listen & cd /home/pi/monitor/
sudo java monitor [YourPetsName] [NumberOfEvents] [TimePeriodInMin] [PushbulletAPIKey] [YourPushbulletTag] &
- Run the following
sudo ./listen &
java monitor [YourPetsName] [NumberOfEvents] [TimePeriodInMin] [PushbulletAPIKey] [YourPushbulletTag] &
Step 9: Connecting to the Mumble Server...from the Server
So this may seem a little odd at first, but it makes sense! If you would like to be able to speak to your pet, you will need to connect to the server FROM the server. At the moment there doesn't seem to be a great way to join a Mumble server using only a CLI so this is the one area where this system isn't 100% headless.
- Connect to the Pi using a remote desktop client or by connecting the Pi to a monitor.
- A guide to configuring a remote desktop connection can be found here.
- Open mumble and follow configuration prompts. At this time, the project can not provide audio input.
- This step will only need to be preformed once.
- When prompted about audio out, select ALSA and sysdefault:CARD=ALSA...
- Connect to the Mumble server
- A guide can be found here.
Step 10: Finished!
That's it! You should now receive notifications from the system when your pet is being noisy. Feel free to open mumble and talk to them whenever you want! Feel free to email me with any questions or suggestions.