Raspberry Pi Doorbell

Status

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:

  1. I didn’t want the doorbell to use Bluetooth
  2. I didn’t want to have to drill any additional holes in the walls
  3. 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:

  1. Raspberry Pi 3
  2. 8 GB microSD class 10 Memory for Raspberry Pi
  3. Step Down Power Supply
  4. USB Cord
  5. Speakers (USB or Mini-jack)
  6. 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).

Doorbell transformer in the garage, feeding 24vac to the doorbell.

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.

Front door outlet from the transformer

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.

Here’s a circuit diagram of how the various bits and pieces go together.

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:

https://www.raspberrypi.org/learning/burping-jelly-baby/worksheet/

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.

Raspberry Pi 3 with the jumper installed on the GPIOs and power from the step down.

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:

Sample code for detecting a doorbell press.

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.

Full code for ringing the doorbell and playing the mp3 file.

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.

Door Bell Enclosure

The old doorbell ringer was replaced with a Raspberry Pi processor that plays a mp3 tune when the front door bell button is pressed. See Zeek’s Raspberry Pi Doorbell post for the details of the electronics and code. Here is the completed upstairs enclosure made from redwood, pine, and mahogany scraps. The redwood came from siding retrieved from Grandpa Jake’s old house on the ranch.

This shelf was installed in the space occupied by the original door chime. The wires coming from the 24 volt a/c transformer and the line which runs to the outside door bell switch were located here. The transformer was just three foot above the original hole in the wall in the attic. Since I had just a 3 foot run to the outlet powering the transformer, I elected to run an AC line from the attic to the shelf to power the raspberry Pi and the Speakers. The other option was to buy a 24 vac to 5 vdc converter. They can be found on Amazon for about $12.

Here is the shelf with all the bits and pieces in place. Note the french cleat fastened to the top of the shelf back that is screwed to the wall. The enclosure will mate with it to hang on the wall. The raspberry Pi was also mounted to the back with two small screws that run through empty holes in the processor board.

After building a hollow box of redwood to cover the electronic components, I added pine strips along the inside of the face to act as a stop for the grill which would be placed against it from the inside.

I cut dodos in the face frame pieces using a pull saw and a square to keep the kerfs square. The waste was removed with a chisel.

Horizontal grill accents were inserted into the dados and glued in place. The dados were cut before assembly.

Vertical grill accents made from mahagony were glued into the dodos cut in the vertical pieces. They stand proud about 3/8 inch for a 3D effect.

The inside of the enclosure with the grill in place. I used a scrap of pegboard to wrap the fabric around. Fabric is glued. Note the two friction fit slats on either side of the grill that hold it in place.

The downstairs speaker for the Raspberry Pi doorbell project is supported by a simple platform make from a 5mm plywood back, two triangular side pieces that have dado for a 5mm base and a french cleat installed at the top of the back. The hole in the back is for the speaker wire. The platform is attached to the wall with drywall anchors.

The cover for the speaker was made from a simple box assembled with glue and nails. additional facade pieces were glued around the inside perimeter of the opening, and you can see the horizontal grill pieces being glued in space here.

Here the vertical grill pieces are added. They are wider than the horizontal pieces and set up proud of the face.

This is a view from the back side of the enclosure after inserting a face made from 5mm plywood and covered with a piece of fabric glued to the back side of the faceplate. You can also see the mating french cleat for the cover.

The cover was finished with Watco natural oil and simply slipped over the platform. The french cleats hold the two pieces together with no fasteners required.