Hello World! This is my first post on Stretch’s Saw Dust Sessions. I’m the “Zeek” in the title. Recently my father, Stretch, visited me at my home on the East Coast. We typically do a few improvement projects around the house (You can probably pick out a few out from my father’s catalog). I am a geek at heart so I like to dabble in programming / electronics / toys projects whenever my father visits. While we typically do wood projects, I like to try to sneak in a few of my own pet projects now and then.
Recently my doorbell had quit working at the house, which is surprising since it was built within the past 3 years and the doorbell didn’t even last 2. I had been browsing a few sites to replace my doorbell with something more… techy. I found some pretty interesting projects using Bluetooth implementations along with webcams. While those were pretty cool there were a few requirements I desired:
- I didn’t want the doorbell to use Bluetooth
- I didn’t want to have to drill any additional holes in the walls
- I didn’t want to run additional cables
After talking to my father, he suggested we could use the current wiring with a Raspberry Pi to detect a push of the doorbell. So, without any more rambling let’s get into how we did this.
Here is a list of things you need for this project:
- Raspberry Pi 3
- 8 GB microSD class 10 Memory for Raspberry Pi
- Step Down Power Supply
- USB Cord
- Speakers (USB or Mini-jack)
- Jumper Wires
If you want the source code for the test.py and doorbell.py, you can view it here.
The first step was to measure the voltage from the transformer that powered the old doorbell. In my garage, we found the doorbell transformer that ran to the front of the house. Using a multi-meter were found out that it was producing 24 Volts (a/c).
The transformer feed comes out near the front door. Another cable ran to the doorbell so that when the circuit is closed (by pressing the doorbell), it would complete the circuit that powered the ringer. This is where we would stage our setup.
A Raspberry Pi requires 5v dc input voltage to power the device. In order to step down the voltage, I needed to buy a step down rectifying power supply. Conveniently, Amazon has these in stock. The a/c input voltage connections are at the back left (if you’re looking down at the device) and the output connections on the front right. We used a multi-meter to determine which wires came from the transformer, and which ran to the door bell switch. We had 2 separate cables, with 2 wires in each.
After installing the Step Down power supply, we cut the USB cable to leave 8 inches of cable from the micro-USB connector – which will plug into the power connector on the Raspberry Pi. We stripped 1 inch of the micro-USB cable to check the wire coding and connections. I used this diagram to determine that we only needed the red and black wires for the micro-USB to power the Raspberry Pi. We clipped back the green and white wires on the micro-USB cable so that they wouldn’t short anything. We connected the black to the negative output and the red to the positive output on the power supply. We then adjusted the power supply potentiometer control to output 5vdc. It has a convenient LED display to let us know what the output voltage is. (Note: the knob was very sensitive, we ended up hot gluing it in place so it would stay at 5v). Also, the voltage will go down when it is under load. As long as it stays near 5v, you should be fine. Mine dips down to 4.92 volts dc at times.
After we had this setup, we could power the Raspberry Pi. This post won’t go into details about installing an OS onto the Raspberry Pi, however, you can read more about that here. I got mine setup with wireless with a static IP, that way I could secure shell (ssh) into it from my machine.
Next, we want to setup the switch so that when someone hits the doorbell, it will play a song for us. This is the mock up my father came up with (that’s an EE for you) to describe to me how this would work.
In order to get this to work, we need to sense the button push on the Raspberry Pi. On Raspberry Pi’s they have what’s called GPIO (General Purpose Input/Output) which are header pins on the board. These can be used for things like installing LED displays on top of the Raspberry Pi’s, and specifically for us, a simple sensing circuit. You can read more here. I found this tutorial very useful in learning how to use Raspberry Pi’s GPIOs. This picture specifically really helped:
Raspberry Pi’s have two different schemes for identifying the GPIO on the board: Physical Pin Out and GPIO Pin Out. The one we are using is listed in the tutorial (GPIO Pint Out). In order for this to work, we want to connect the 5V (First pin on the right) and the GPIO 23 (8 Pins down on the right). The Raspberry Pi’s have built in pull up/down resistors, so we can use these to help us sense when the doorbell button is pressed. We used the jumper wires we bought to connect the wires running to the outside doorbell switch to the GPIO pins we described above.
Once we have this all setup, we can now begin to test if we are receiving a button push from the doorbell. Here is some sample code I wrote up for debugging to see if we got a button push:
After you detect the button press, you can use this code in order to play an mp3. In order for this to work, you need to install the mpg123 package on Ubuntu (apt-get install mpg123.)
Below is the code for the full doorbell Proof of Concept (POC). I will add here that I had some false positives, even with the pull down resistor set (Raspberry Pi’s have these built in.) In order to stop from getting random doorbell rings (Who wants that happening at 1 AM?) I found this article on stackoverflow for a debounce function.
If you’re using USB speakers, I recommend looking here as I encountered some problems getting my sound to work. I had to change the file /etc/modprobe.d/alsa-base.conf to reflect:
options snd-usb-audio index=0
Then I had to reset the Raspberry Pi in order for this to take affect.
I added this line to my crontab so that the python script would start on boot:
@reboot python /home/pi/doorbell.py &
After you’ve completed this you can now download your favorite mp3 and have it play whenever someone rings your doorbell!
Here is the article my father wrote up on making an enclosure for the speakers, so you don’t have some ugly implementation of wires hanging out of your wall.