How to build a facial recognition doorbell with a Raspberry Pi
I want to buy a smart doorbell, but their cost is a little out of my budget. Instead, I use a Raspberry Pi, speaker system, and camera to build a smart doorbell system for a fraction of the cost.
In our latest project, we created a doorbell system that would ring when someone was at the door. This time, we’re going to develop the code to allow the project to identify when people we know are at the door and announce it accordingly. This will allow us to choose to run out the door or hide upstairs when our friends or in-laws drop by.
What you will need for this project
How to turn a Raspberry Pi into a facial recognition doorbell system
Before you start, set up your Raspberry Pi. If you haven’t already, check out our article on how to install a Raspberry Pi for the first time or how to make a Raspberry Pi headless installation (without keyboard and screen). For this project we recommend a Raspberry Pi headless installation.
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 that 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 command “make install” to install all the dependencies of the project. This script will take care of installing the lower level dependencies, as well as the Python libraries that you need for the project to run. It should take around 10 to 15 minutes on a Raspberry Pi 4.
cd ~/facial_recognition_doorbell/ make install
4. Set 3.5mm audio output as default audio output in raspi-config. To do this, run raspi-config (by entering sudo raspi-config at the command prompt) and navigating to System Options -> Audio -> Headphones 1. The pi allows audio to be output to either the 3.5mm analog output or the HDMI port. If you don’t have a monitor connected, headphones may be the only option.
sudo raspi-config # Navigate to System Options -> Audio -> Headphones 1
5. Connect your speakers to 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 use a megaphone, but feel free to use whatever speakers you have.
7. Test speech synthesis on your pi by running the following command. You should hear the text spoken aloud through your speakers.
say ‘hello there’ # Press Ctrl + C to exit if stuck
8. Flash custom RTSP firmware on your Wyze camera using this tutorial. Installing RTSP support allows us to connect to the camera and capture images directly with Python. You will need a Wyze V2 camera and a microSD card.
9. Get the value of the RTSP URL from your Wyze app, and edit the RTSP_URI variable in the Makefile to point the Raspberry Pi at your camera. You can find the RTSP URL in the “Advanced Settings” section of your Wyze app on your phone.
cd ~/facial_recognition_doorbell/ nano Makefile # STREAM_URI=rtsp://your_username:your_password@camera_ip_address/live
ten. Install your camera facing the outside of your front door. Keep in mind that the Wyze V2 is not weatherproof so I keep mine in a covered area. Ideally, the camera should be mounted above the door and point directly at anyone approaching. This allows facial recognition to work at its best.
11. Download photos of famous people and save them with their file names. Any .jpeg, .jpg, or .png photo with someone’s face will work. There should only be one face per photo, and it is not necessary to use more than one photo for each person. I have one for each of my friends who come by my house.
12. Copy photos of famous people to the src / faces directory.
mv ryder.jpeg /home/pi/facial_recognition_doorbell/src/faces/
13. Run the “make run” command on the pi at start the doorbell system. The system will first search for the detection of a person. When a person is detected, the doorbell rings and the system begins to identify all known faces from the face repertoire. If a face is found, the system will announce the person at the door using text-to-speech.
We now have a system that rings every time someone is at the door and announces their name if we have their picture in our records.