To help us provide you with free impartial advice, we may earn a commission if you buy through links on our site. Learn more

Best Raspberry Pi Projects

Raspberry Pi logo red background

Our pick of the most fun and useful things you can do with your Raspberry Pi

[/vc_column_text]

Make a Raspberry Pi smart doorbell

It might sound silly, but connecting your doorbell to the internet is a great idea. At a basic level, it means that whenever someone presses your doorbell, your smartphone or tablet will chime so you’ll never miss a delivery or visitor, whether you’re down the bottom of the garden or listening to loud music in your study. You’ll also be able to log doorbell presses, so you can prove that the courier you’ve waited for all day really did just stick the “sorry you were out” card through the letterbox without even trying the bell.

To connect your doorbell to your network (and the internet beyond), you’ll need a Raspberry Pi and a Class 4 (or faster) 4GB SD card with the latest version of Raspbian installed. You’ll also need a power supply and an internet connection for the Pi, as well as all the doorbell-specific hardware we’ve listed below.

Adafruit pushbutton

If you don’t want to buy the Adafruit doorbell we list, you can also use any waterproof, momentary-type push button as a doorbell. If you wish to use an alternative pushbutton – perhaps the one currently next to your door, or one that’s a little wider than the slightly skinny 16mm Adafruit button – ensure the button is a momentary button rather than an on/off switch button, and that its contact and insulation resistances are close enough to that of Adafruit’s button. A momentary button only sends a signal when it’s being pressed, while an on/off button switches from one state to another once pressed; use the wrong button and your doorbell will buzz until the next time someone presses the button.

What you need

*Raspberry Pi (plus power supply and 4GB, Class 4 SD card) with internet access
*PC speaker (standard active type with 3.5mm plug)
*Android or Apple smartphone
*Pushover account (see below)
*Adafruit Waterproof Metal Pushbutton with LED Ring
*10k-Ohm resistor
*Multicore cable (at least 4-strand, such as telephone wire)
*Soldering iron and solder
*Wire strippers

When ordering, why not support your local electronics shop? Below is a table of certified UK Adafruit suppliers. You may have to search for ‘momentary pushbutton’ or similar under the Adafruit section on these sites to find the correct button. Many of these suppliers will also be able to provide the resistor, probably as a pack of 20 for around £1, and the multi-core cable (telephone wire costs around 75p per metre).

Certified UK Resellers  
NameLocationWebsite
4TronixSheffieldwww.4tronix.co.uk
Cool ComponentsLondonhttp://coolcomponents.co.uk
ModMyPiLondonwww.modmypi.com
OomloutLeedshttp://oomlout.co.uk
PhenoptixNottinghamwww.phenoptix.com
Pi SupplyCroydonwww.pi-supply.com
PKMCLondonhttp://pkmc.uk.com
Proto-PicKirkcaldyhttp://proto-pic.co.uk
SK Pang electronicsBraintreewww.skpang.co.uk
TandyOxfordwww.tandyonline.co.uk
The Pi HutCambridgehttp://thepihut.com

Once you’ve installed Raspbian on your SD card connect the Pi to your network and power it up, then log in with the default user name of ‘pi’ and password ‘raspberry’. Then expand the file system via the blue configuration screen and reboot. Log in again and type ‘sudo apt-get update’ and hit Enter; once Raspbian has updated, update its applications by typing ‘sudo apt-get –y upgrade’.

Config

Remember to expand the file system, otherwise your Pi won’t be able to access the entire storage capacity of your SD card

Next you need to convert the Pi’s GPIO (General-Purpose Input/Output) connection (the double line of bare pins near the SD card slot) from Serial mode to Software Access mode. To do this you need to edit a boot file. Type ‘sudo nano /boot/cmdline.txt’ and hit Enter. You’ll need to edit the current line:

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

To match this line:

dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

Press Ctrl+X, then Y, then Enter to close, save and overwrite the file with the new changes. Then edit another setup file by typing ‘sudo nano /etc/inittab’ and pressing Enter. Comment out the last line (so that it’s ignored) by inserting a hash at the start of the line, to match the example below, then exit and save the change as before.

#TO:23:respawn:/sbin/getty –L ttyAMA0 115200 vt100

You can now reboot your Pi by typing ‘sudo reboot’.

Install Pushover

The service we’ll use to send doorbell alerts to your smartphone is called Pushover and is available for Apple’s iOS and Google’s Android but not Windows Phone. The Android version has a five-day free trial before asking for $4.99 as an in-app purchase, while the iOS version is £2.99. Pushover can push any kind of alert to your smartphone, so can be used for more than just your doorbell. Install the app, sign up for an account and name the device which you want to receive the notifications. If asked, you’ll obviously want to give permission to Pushover to send you Push Notifications. A welcome message should appear on the Pushover Home screen, telling you that the device can receive messages.

Next, head to https://pushover.net and log in. You’ll be asked to verify your email address, do so and then click Register an Application under the Your Applications section. You’ll be asked to give this new application a name, type, description, URL and icon – see the screenshot for our suggestions. Click Create Application and note the API Token/Key that Pushover generates (it’s a long string of numbers and letters that’s case-sensitive) before pressing Save Changes. Pressing this button will take you to a usage screen with two graphs, but just head home by clicking the Pushover logo at the top-left of the screen. From this main screen, note your user key (the top-most of the two long strings of letters and numbers) and log out.

Pushover

Create a New Application in Pushover for your doorbell

Back on your Pi, install the audio player mpg321 by typing ‘sudo apt-get install –y mpg321’ and pressing Enter. You’ll then need to save an MP3 audio file to your Pi that will act as your doorbell chime. We chose one from Soundjay, a royalty-free site with a choice of seven sounds. To download an MP3 (we chose file 1, for example) from this site directly to your Pi, type ‘wget http://www.soundjay.com/door/doorbell-1.mp3’ and the download should start. You’ll also need to install the GPIO add-on for the Python programming language, by first installing the Python development toolkit, and then the GPIO add-on:

sudo apt-get install –y python-dev

sudo apt-get install –y python-rpi.gpio

The code

The code that drives your WiFi Doorbell, using the Python programming language

Create a new Python script by typing ‘sudo nano doorbell.py’ and then copy the Python doorbell code, inserting your user and application keys instead of the phrases ‘AppKeyHere’ and ‘UserKeyHere’. You could also download the example script from our server by typing ‘wget www.shopperdownload.co.uk/adproj/doorbell.py and edit it with nano, as above. Save and exit by pressing Ctrl+X, Y, then Enter. You can now shut down the Pi by typing ‘sudo shutdown –h now’ and pressing Enter. Wait 15 seconds or so until the Pi is powered down, and disconnect the power, SD card and Ethernet cable.

Soldering the wires

Strip the outer sheath from the multi-core cable, and then strip the ends from four of the wires. Our phone cable had six wires inside, so we snipped the green pair off altogether. On the Adafruit Pushbutton there are five connections, labelled +, -, NC1, NO1 and C1. It doesn’t matter which wire you use for which connection, but write down which colour you’ve connected where. For example, we used the Orange with White wire for positive, White with Orange for negative, Blue with White for NO1 and White with Blue for C1. Solder the wires to the Pushbutton’s connections. If you’re nervous about soldering, you can connect everything dry by curling the bare wire around your pins and connections with a pair of needle-nosed pliers.

GPIO

This image shows the function of each of the 26 pins of a Pi’s GPIO connector. Pin 1 is marked on the Pi (as P1). When wiring, orientate the Pi so the GPIO connector is at the top-left corner of the circuit board for easy reading

Next, find your 10k-Ohm resistor. This will have bands of brown then black (to make 10), followed by orange (x1k), then gold (tolerance of five per cent). You need to place the resistor between the 3.3V pin on the GPIO and the GPIO pin you intend to use for control – we’ve used Pin 4, which corresponds to GPIO 4 (used in the Python code above). Then connect the NO1 wire from the Pushbutton (Blue with White, in our case) to the GPIO 4 side of the resistor (or whichever pin you have used). The other connections are straightforward: C1 goes to GND (Ground) on the GPIO, as does –, while + goes to the 5V GPIO pin. The spec sheet of the Pushbutton says that its LED requires 6V, but we found the 5V supply from the Pi was perfectly fine.

Circuit 1

Circuit 2

Use these diagrams to help you wire your Pushbutton to your Pi

Ensure that no bare wire touches any other bare wire (unless they share a GPIO pin), and once you’re happy, reassemble and power up your Pi. Log in and you’re ready to activate the doorbell script. Type ‘sudo python doorbell.py’ and you’ll see the ‘Doorbell Server Started’ message on the Pi’s screen, followed a few seconds later by your phone buzzing with the Pushover alert ‘Doorbell: Started’. Now press the Pushbutton and you should hear the MP3 chime you downloaded followed quickly by a Pushover alert telling you ‘Someone is at the door!’

To start the Doorbell.py script automatically, we’ll add it to the crontab. Type ‘sudo crontab –e’ to open the crontab file. Then instert the line ‘@reboot python /home/pi/doorbell.py &’ on its own line at the end of the crontab file, then save and exit. Test whether the script launches automatically by typing sudo reboot; after 30 seconds or so, you should receive the ‘Doorbell: Started’ message on your phone.

Make it wireless

Edimax

Having to route an Ethernet cable to your front door is a pain, so why not make the Pi controlling your doorbell wireless? There are a few Wi-Fi dongles compatible with the Pi; the most common being the Edimax EW-7811Un, which costs £8 from Dabs. The driver for this dongle is already installed with Raspbian, so it’ll work as soon as you plug the dongle in.

Overkill?

Using a Pi to make a wireless doorbell might seem like overkill when you can get wireless doorbell kits for under a tenner, but there’s a lot more you can do when a Pi powers your doorbell. Without adding any more code, for example, your Wi-Fi Doorbell can send your phone Pushover alerts over any kind of data connection, so you don’t even have to be in range of your home’s Wi-Fi. This means you can rush back from the shops to meet Great Aunt Ethel who was meant to call at half-past, not quarter-to. You might also be able to prove that your pesky courier didn’t in fact call earlier by showing the company the Pushover graph for your application.

Pages: 1 2 3 4 5

Read more

In-Depth