I thought it would be fun if I would get a text message with picture every time someone presses the doorbell. It would also be nice if the current doorbell was not affected and no obvious cameras would be visible.
First of all I needed to get the Pi noticing a keypress. There are numerous walkthroughs to help you on your way like this one. Problem is that although i do have a momentary switch at my door, it is connected to a 8V AC circuit with the bell and a certain way to fry your Pi is to put 8VAC on a GPIO pin.
So to separate the circuits I needed a relay or something that switches when someone uses the bell. I happened to have some left over solid-state relays (G3MB-202P) from other projects so that shouldn’t be a problem except for the fact that need an DC current. Ah well, who hasn’t have some bridge rectifiers in their drawers.
All in all the schematic of my interface looks like this:
Which translates to:
So... when someone presses the doorbell the relay will activate the switch and connects pin 18 and 20 (GPIO24, GND) and than we are at where the earlier mentioned example talked about and can we do some of the programming…
When i came across a so called endoscopic camera I thought that would make the perfect camera for this purpose. Ordered from Hong Kong these things are very cheap (< 10 euro’s) and are waterproof, small and acts like just a standard USB webcam so it works great with fswebcam (sudo apt-get install fswebcam).
I used a python script that waits for the doorbell and takes a photo using fswebcam when needed. I used python interrupts (much less demanding on the CPU) but you can use of course a polling mechanism to achieve this.
#!/usr/bin/python
import RPi.GPIO as GPIO
import time
import subprocess
import os
GPIO.setmode(GPIO.BCM)
GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def erWordtGebeld(channel):
returncode = subprocess.Popen("/usr/bin/fswebcam -c /opt/develop/deurmonitor.cfg", shell=True)
print('Doorbell rang at ' + time.strftime("%a om %H:%M:%S"))
GPIO.add_event_detect(24, GPIO.FALLING, callback=erWordtGebeld, bouncetime=500)
print( "Deurbelmonitor is started at " + time.strftime("%A om %H:%M:%S") )
print( "Druk op Ctrl-C om te stoppen")
try:
while True:
time.sleep(3600)
except KeyboardInterrupt:
print "Cleaning up..."
GPIO.remove_event_detect(24)
GPIO.cleanup()
print "Done"
The second part is the configuration of the webcam. This is my configuration file:
device v4l2:/dev/video0
input 0
delay 0
resolution 352x288
set brightness=50%
set contrast=25%
set sharpness=5
title "Deurbel"
subtitle "...er wordt gebeld"
timestamp "%d-%m-%Y %H:%M:%S (%Z)"
jpeg 80
save /var/tmp/deurbel.jpg
quiet
# if you use Telegram to send the picture you can run it from here. If you
# do it differently leave it out or put in your own command
exec "echo send_photo Telegram_User /var/tmp/deurbel.jpg | nc 127.0.0.1 1208"
The last line, starting with exec executes a command (after taking the photo). I used this to send the photo through Telegram to my phone. You can use any command you want. Services like pushbullet or pushover would do just as fine.
Comments