Intermediateraspberry-pi

Build a Smart Doorbell with Raspberry Pi

Create a WiFi-connected doorbell with live video streaming, motion detection, and mobile notifications using Raspberry Pi.

4-6 hours
$45-65
Alex Chen
Build a Smart Doorbell with Raspberry Pi

Parts List

  • Raspberry Pi Zero 2 W
  • PiCamera Module v2
  • PIR Motion Sensor
  • Push Button
  • Resistor 330Ω
  • Breadboard and Jumper Wires
  • MicroSD Card (16GB+)
  • Power Supply (5V 2.5A)

Step-by-Step Instructions

1

Set Up Raspberry Pi OS

Download Raspberry Pi OS Lite from the official website and flash it to your MicroSD card using Raspberry Pi Imager. Insert the card into your Pi and connect the power supply, monitor, and keyboard. Run sudo apt update && sudo apt upgrade to ensure all packages are current before proceeding.

sudo apt update && sudo apt upgrade
2

Install Required Packages

Install the essential Python libraries needed for the doorbell project using pip. You will need Flask for the web server, OpenCV for camera access and motion detection, and gpiozero for GPIO control. Run the following command to install all dependencies in one go.

pip3 install flask opencv-python gpiozero
3

Wire the Hardware

Connect the PIR motion sensor to GPIO pin 17 on the Raspberry Pi, with its VCC pin going to 3.3V and GND to ground. Wire the push button to GPIO pin 27 with a 330Ω pull-down resistor to ensure clean signal transitions. Mount the PiCamera Module v2 to the Pi's CSI port by lifting the camera connector tab and seating the ribbon cable firmly.

4

Write the Doorbell Script

Create a new Python file called doorbell.py that imports Flask, OpenCV, and gpiozero. Set up a basic Flask web server that serves a live video stream endpoint and listens for button press events. Define callbacks for motion detection that trigger the camera to capture a snapshot when movement is detected near the door.

5

Configure Motion Detection

Initialize the OpenCV video capture and set up a background subtractor for motion detection. Define a region of interest that covers the door area and configure sensitivity thresholds to avoid false triggers from passing cars or animals. When motion is detected, save a timestamped image and trigger the notification system.

6

Set Up Mobile Notifications

Create a free Pushbullet or IFTTT account and generate an API key for sending notifications. Integrate the API calls into your doorbell script so that a push notification with the captured image is sent to your phone whenever the button is pressed or motion is detected. Test the notification flow by pressing the button and verifying the alert arrives on your device.