We had some good fun last night with the neighbourhood kids making use of our Doorbell of Dooooooooommmmmmmm.
I’ve had a bigger doorbell project planned for quite a while but 2 weeks ago decided we should do a simpler Halloween one. Using various bits bought from Sparkfun and Maplin along with a great tutorial from Adafruit (more below), I finally got something we were happy with, working late last week. Then yesterday evening I put it in place on the door. Unfortunately, with all the pulling, taping and general movement, one of the five buttons stopped working. But the other 4 were fine.
The sounds used were pulled from various online sources. Sibéal came up with the Mr Burns idea and Oisín thought of the Home Alone one. I used Audacity to clip some of them and ffmpeg to convert some of the YouTube videos to audio. The cheques are in the post
Originally I was going to use Arduino for this but considering a Waveshield for playing audio costs more than a Raspberry Pi, I changed direction. I then thought I’d use the Arduino for the button detection and communicate over USB to the RPi but I finally realised I should just use the GPIO pins directly on the RPi itself. My worry about killing it accidentally were unfounded.
The first version was done on a breadboard to make sure I made no mistakes. It worked well. But it was never going to work stuck to a doorframe so I moved to a strip of veroboard and soldered it together. This had a few, ahem, glitches, which took a while to sort out due to my soldering incompetence.
The final setup was really simple:
- One button per sound
- Each button connected to a GPIO pin on the RPi along with connection to 3.3V and GND on the RPi (pull up resistors there too but apparently not necessary?)
- An old 40-core IDE cable from a dead PC used to safely connect the wires from the buttons to the pins on the RPi.
- Extremely simple Python code running in a loop on the RPi which checked to see if any of the connected pins were pulled low by the button being pressed.
- If so, it made an external call to mplayer to play one of our selected audio clips
The only real change from the Adafruit tutorial was to use mplayer instead of mpg123. This allowed me to use any audio format including WAV, rather than just MP3s. Also some of the instructions are a little redundant with the latest version of Debian on RPi, but they do no harm.
This is the trivial script to set the volume and call the Python script:
amixer cset numid=3 1
nohup ./raspi-audio-button.py > /dev/null 2>&1 &
This is the code, it uses the RPi.GPIO library (the latest version works fine):
from time import sleep
import RPi.GPIO as GPIO
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(25, GPIO.IN, pull_up_down=GPIO.PUD_UP)
if ( GPIO.input(22) == False ):
os.system('mplayer /home/pi/haunted_sounds/Howl.mp3 &')
# if ( GPIO.input(17) == False ):
# os.system('mplayer /home/pi/haunted_sounds/HomeAloneCountOf10.mp3 &')
if ( GPIO.input(23) == False ):
os.system('mplayer /home/pi/haunted_sounds/ReleaseTheHounds.wav &')
if ( GPIO.input(24) == False ):
os.system('mplayer /home/pi/haunted_sounds/Scream.wav &')
if ( GPIO.input(25) == False ):
os.system('mplayer /home/pi/haunted_sounds/CastleThunder.wav &')
This diagram of the RPi pin-out was invaluable:
Once everything was setup at the door yesterday, we then found that the volume on the Lidl iPod Dock was far too low. I had to put a tiny battery powered speaker outside, taped to the postbox. But even that wasn’t great so I added a Fiio amplifier. Of course then we couldn’t hear it inside, so I split the audio and used one audio device inside and one outside.
I didn’t have time to setup wireless on the RPi so I used a wired network connection. This enabled me to SSH to the RPi from my PC and start the Python program. It also allowed me to remotely change the Home Alone clip to the howl from An American Werewolf in London after it got a bit tiresome, 2 hours later.
I made a video of it all in action but the bloody version of CM10 on my phone corrupted it. To give you a taste of what it was like, I extracted the audio from it. Enjoy:
Changes? Instead of externally calling mplayer, it’d be better to use some sort of audio library that would allow a follow-on button-press to interrupt whatever is playing. Also, approx 75% of kids pressed the top button so the next time we’ll randomise what is played.
Next steps? Well that’d be our Social-Enabled Doorbell. It’ll probably be Christmas before I finish it tho.