Dog Bark Sensor
Intro: Dog Bark Sensor
I recently got a new puppy and I wanted to know if he was barking when I left the house. I rigged this little hack together to send me a text message if he barks.
This is my first instructable so I'd like to apologize for any errors. If you could point them out in the comments I'll do my best to correct them. Thanks!
You'll need:
1) Raspberry Pi 2 I'm running it on Raspbian Jessie (I bet it will work on other models and OSs but I haven't tested it).
2) Breadboard.
3) MCP3008 ADC https://www.adafruit.com/products/856.
4) Electret Microphone Amplifier - MAX4466 with Adjustable Gain https://www.adafruit.com/products/1063 (however, you won't use the adjustable gain).
5) A way to connect the Raspberry Pi to the network (I used an ethernet cable).
6) ~12 wires for the breadboard and GPIO pins.
STEP 1: Update
You'll need to update your Raspberry Pi (RPi). Type into the terminal:
sudo apt-get update sudo apt-get upgrade
STEP 2: Wire MCP3008 and Enable SPI
- Wire the MCP3008 according to the wiring diagram
- Enable SPI on the RPi.
- This is a great tutorial on how to do that. Start on step 2 in the tutorial here: https://www.instructables.com/id/Wiring-up-a-MCP300...
STEP 3: Software
- This code is adapted from http://www.linuxuser.co.uk/news/10-raspberry-pi-up...
- Make the python script by typing into the terminal:
cd ~ mkdir Pupnet cd Pupnet/ nano pupNetDriver.py
- To find out what format to use for the text via email follow this guideline (taken from https://www.raspberrypi.org/forums/viewtopic.php?f...):
- Sprint phonenumber@messaging.sprintpcs.com
- Verizon phonenumber@vtext.com
- T-Mobile phonenumber@tmomail.net
- AT&T phonenumber@txt.att.net
- AIM +1phonenumber
- Then copy and paste the following code (or copy it from here https://raw.githubusercontent.com/thepinkturtle/Pu...) into the pupNetDriver.py file you just created.
- In order to exit and save nano type
- ctrl + x
- y
- enter
#!/usr/bin/python # python program to communicate with an MCP3008
# Import our SpiDe wrapper and out sleep function
import spidev import os
# Establish SPI device on Bus 0, Device 0 spi = spidev.SpiDev() spi.open(0,0)
def getAdc (channel): #check for valid channel if ( (channel > 7) or (channel < 0) ): return -1 # Preform SPI transaction and store returned bits in 'r' r = spi.xfer( [1, (8 + channel) << 4, 0] )
# Filter data bits from returned bits adcOut = ( (r[1] & 3) << 8 ) + r[2] # If adcOut is greater than 700 send a text via email through terminal if (adcOut > 700 ): os.system("echo 'WOOF! WOOF!' | mail your_phone_number@your_carrier_format.com") while True: getAdc(0)
STEP 4: Set Up SMTP
The last step is to setup SMTP.
Follow the simple tutorial from here http://www.raspberry-projects.com/pi/software_util...
To start up the service type into the terminal:
cd ~ cd Pupnet/ cd sudo python pupNetDriver.py
You should have a working bark sensor now. If you need to adjust the sound level higher or lower play with the if statement in the code. If the number is higher than 700 the sound to set it off will need to be louder. If its lower than 700 the sound won't need to be so loud. Let me know if you have problems in the comments below.
if (adcOut > 700 ): ...
STEP 5: Sources
http://www.toptechboy.com/wp-content/uploads/2015/...
http://www.raspberry-projects.com/pi/software_util...
https://www.raspberrypi.org/forums/viewtopic.php?f...
http://www.linuxuser.co.uk/news/10-raspberry-pi-up...
https://www.instructables.com/id/Wiring-up-a-MCP300...
https://www.adafruit.com/products/856
https://www.adafruit.com/products/1063
http://www.rs-online.com/designspark/electronics/e...
https://upload.wikimedia.org/wikipedia/commons/3/3...
9 Comments
dyuen 6 years ago
bash: cd: too many arguments
What did I miss?
nbibin001 6 years ago
Hello, this is a nice post. Thanks for the all the details. I just had a quick question in the code below. How do we say that if the adcOut is greater than 700 it is a dog bark ?
# If adcOut is greater than 700 send a text via email through terminal
if (adcOut > 700 ):
os.system("echo 'WOOF! WOOF!' | mail your_phone_number@your_carrier_format.com")
DevinL16 6 years ago
We don't. My dog's bark, at the time, was the loudest noise anyone ever really made in my house. So, I just set the magic number to 700 because pretty much any noise made in my house was never that loud. Unless, it was my dog barking.
need_to_git_gud 6 years ago
Hey dude, great project! Though i can't seem to see the circuit diagram.
DevinL16 6 years ago
need_to_git_gud 6 years ago
Thank you so much for the update!
My friend and I are playing around with sensor networks and this was one of the only projects we found online that uses the same mic :)
Cheers!
tomatoskins 8 years ago
This is so cool! How often do you receive texts that your puppy is barking?
DevinL9 8 years ago
He's crate trained pretty well, so he only barks when he needs to go poop/potty. It's saved me a messy clean up a few times.
TheThinker 8 years ago