Who Ring My Doorbell – RaspberryPi Home Security Project

Do you want to know who ring your doorbell when you are away from your home? If your answer is yes then this video is for you. You will attach a camera to RaspberryPi and whenever a person presses the doorbell, RaspberryPi takes a photo and put it into a folder that is in sync with Google Drive. This way you will get the picture on your smartphone.

You need following components in order to make this project.

Step 1: Setup Raspberry Pi

This post will help you to setup RaspberryPi with an operating system and required hardware. Install overgrive and configure it by following instructions given here.

Step 2: Attach Camera

Connect camera to a USB port of RaspberryPi and install fswebcam application to RaspberryPi with this command. Open terminal and run following command.

sudo apt-get install fswebcam

Check if camera is working. Run the following command and check if camera is taking picture or not.

fswebcam -r 1280x720 -S image1.jpg

If camera is working you will not get any error and an image named image1.jpg will be created in current directory. Open image1.jpg and if you see an image the camera is working perfectly and you can go ahead.

Step 3: Connect button to Raspberry Pi

Connect ground port of the pin to ground pin of Raspberry Pi and other port of the button to Pin 18 (physical pin 12).

Step 4: Source Code

# import the necessary packages
import time
import sys, os
import RPi.GPIO as GPIO

# Use BCM GPIO references
# instead of physical pin numbers

# Define GPIO signals to use
# Physical pins 12
# GPIO18
pin_button = 18
GPIO.setup(pin_button, GPIO.IN, pull_up_down=GPIO.PUD_UP)

# allow the camera to warmup
while True:
    input_state = GPIO.input(pin_button) # Sense the button
    if input_state == False:
        os.system("fswebcam -r 1280X720 -S 15 image_" + str(i) +".jpg")
        i += 1

You can download the source code from the link given below.

Download “Door Alert” doorAlert_2.zip – Downloaded 376 times –

Run this program with the following command in terminal.

python doorAlert_2.py

Step 5: Test the project

if all components are properly connected and the program is error free then the camera will take the photo on every button press.

I believe that you will successfully make this project. You should have basic knowledge of Linux operating system and Python programming language. Still, if you face any problem ask in the comment box.

Required Material to make it yourself

Dr. Yogendra Pal

Ph.D. (IIT Bombay), M.Tech., B.Tech. (CSE) Dr. Yogendra Pal finished his Ph.D. from Educational Technology department at IIT Bombay. Mr. Pal holds B.Tech. and M.Tech. Degrees in Computer Science and Engineering. His interests include programming, web development, graphic design and educational technology.

This Post Has 7 Comments

  1. how can we use camera board module instead of usb camera

    1. All you need to learn how to use camera module with Raspberry Pi. Everything else will remain same. At present we don’t have video for camera module but you can search on the internet, you will find many.

  2. hi, i want to ask, if i change the camera with 5mp camera module raspberry pi, is it possible for me to use the same code?

  3. is the source code is still same if i use camera module raspberry pi instead of using usb camera?

  4. if input_state == False:
    os.system(“raspistill -o image_” + str(i) + “.jpg”)
    i += 1

  5. No, you’ll need to change the last bit of the code to the following…

    if input_state == False:
    os.system(“raspistill -o image_” + str(i) + “.jpg”)
    i += 1

  6. Hi, I’ve a personnal project. I’m an electrical engineer, but my pogramming skills are wery low. I’d like to create a doorbell with my own playlist. Everytime someone pushes the button, Rpi3 would play random track from my own playlist with “repeat all” function. I was thinking about using VLC, where I can set all these things. But I don’t know how to create a code using GPIO to play next track in VLC. It’d be awesome if the program would automaticly start after boot the system together with VLC, in case of blackout or reboot. I assume the code should be quite simple for someone who knows what is he doing. I tried to search the web, but your sample is the closest what I found. Could you help me?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Close Menu


Close Panel
Skip to toolbar