I want to buy a smart doorbell, but the cost of them is a little outside of my budget. Instead, I’m using a Raspberry Pi, a speaker system, and a camera to build a smart doorbell system for a fraction of the cost.
In our last project, we created a doorbell system which rang when a person was at the door. This time we’ll expand on the code to allow the project to identify when people we know are at the door, and announce it accordingly. This will let us choose to either run to the door, or hide upstairs when our friends or inlaws drop by unexpectedly.
What You’ll Need For This Project
- Raspberry Pi 4 or Raspberry Pi 3 with power adapter
- Desktop speakers or a megaphone with a 3.5mm input and 3.5mm cable
- Wyze Cam V2 (Wyze Cam V3 is not yet compatible)
- 2x8 GB (or larger) microSD cards, one for Raspberry Pi, another for the camera.
- Monitor with HDMI and power cables. (Optional)
How to Turn a Raspberry Pi into a Facial Recognition Doorbell System
Before you get started, get your Raspberry Pi set up. If you haven’t done this before, see our article on how to set up a Raspberry Pi for the first time or how to do a headless Raspberry Pi install (without the keyboard and screen). For this project, we recommend a headless Raspberry Pi install.
1. Install git. We’ll need it to download the code from GitHub.
sudo apt-get update sudo apt-get -y install git
2. Clone the repository to your home directory. This will ensure we have all the code and audio files we need to run the project.
cd ~/ git clone https://github.com/rydercalmdown/facial_recognition_doorbell.git
3. Run the “make install” command to install all project dependencies. This script will take care of installing lower level dependencies, as well as the Python libraries you need for the project to run. This should take about 10-15 minutes on a Raspberry Pi 4.
cd ~/facial_recognition_doorbell/ make install
4. Set the 3.5mm audio output to be the default audio output in raspi-config. You do this by launching raspi-config (entering sudo raspi-config at the command prompt) and navigating to System Options -> Audio -> Headphones 1. The pi allows for audio to be outputted to either the 3.5mm analog output, or over the HDMI port. If you do not have a monitor attached, headphones may be the only option.
sudo raspi-config # Navigate to System Options -> Audio -> Headphones 1
5. Plug your speakers into your Raspberry Pi using a 3.5mm cable.
6. Test your speakers by playing the doorbell audio file. You should hear a doorbell sound from your speakers. In my case I’m using a megaphone, but feel free to use whatever speakers you have available.
7. Test text to speech on your pi by running the following command. You should hear the text spoken out loud through your speakers.
say ‘hello there’ # Press Ctrl + C to exit if stuck
8. Flash the custom RTSP firmware to your Wyze camera using this tutorial. Installing RTSP support allows us to connect to the camera and grab frames directly with Python. You will need a Wyze V2 camera and a microSD card.
9. Get the RTSP URL value from your Wyze application, and edit the RTSP_URI variable in the Makefile to point the Raspberry Pi to your camera. You can find the RTSP URL in the “Advanced Settings” section of your Wyze application on your phone.
cd ~/facial_recognition_doorbell/ nano Makefile # STREAM_URI=rtsp://your_username:your_password@camera_ip_address/live
10. Install your camera facing outwards from your front door. Keep in mind the Wyze V2 is not weather proof, so I’m keeping mine in a covered area. Ideally the camera should be mounted above the door pointing directly towards any person who would approach. This allows the facial recognition to work best.
11. Download photos of known people and save them with their file names. Any .jpeg, .jpg or .png photo with someone’s face will work. There should be only one face per photo, and it’s not necessary to use more than one photo for each person. I have one for each one of my friends that comes by my house.
12. Copy the photos of known people into the src/faces directory.
mv ryder.jpeg /home/pi/facial_recognition_doorbell/src/faces/
13. Run the “make run” command on the pi to start the doorbell system. The system will first look for the detection of a person. When a person is detected, the doorbell will ring, and the system will start identifying any known faces from the faces directory. If a face is found, the system will announce the person at the door using text to speech.
We now have a system that will ring whenever a person is at the door, and announce their name if we have their photo on file.