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.
- Raspberry Pi 3: https://goo.gl/XQDIqX
- ELP USB Camera: http://amzn.to/2DzUUTj
- Push Button: http://amzn.to/2zOlK7V
- Jumper wires: http://amzn.to/2s9wfkc | https://goo.gl/QK5BN4
- BreadBoard: http://amzn.to/2DwnFAn
Step 1: Setup Raspberry Pi
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 GPIO.setmode(GPIO.BCM) # 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 time.sleep(0.5) i=0 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") time.sleep(0.3) i += 1
Run this program with the following command in terminal.
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.