Pi Door Lock

Retrofitted to my door lock, I present to you my Raspberry Pi door unlocker:

Although in this picture it was powered by the Pi Car mobile 1200mAh battery, it is now powered off the mains. The 4 AA batteries power the servo, which has a lifting strength of 15kg/cm. The servo pulls a piece of string to pull back the catch – opening the door.

The quickly-built web interface, with currently a simple JavaScript check for the password validity (I know, I should use server-side checking or MD5 hashing at least, but hey – its only a prototype!)

<input id=”code_input” type=”tel” name=”enteredcode” onfocus=”clearThis(this)” autocomplete=”off” /><br />

The code for the input box: type = “tel” brings up the numeric keyboard on phones, clearThis is a JavaScript function (function clearThis(target){ target.value= “”; } ) that clears the box when clicked. I also turned the browser’s autocomplete off. When a correct password is entered, the following script is run:

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)
GPIO.setup(3, GPIO.OUT)
GPIO.setup(7, GPIO.OUT)
#GPIO.output(7, True)

p = GPIO.PWM(3,50)
p.start(7.5)

try:
p.ChangeDutyCycle(10.5)
#time.sleep(2)
p.ChangeDutyCycle(7.5)
time.sleep(3)
p.ChangeDutyCycle(10.5)
#GPIO.output(7, False)
time.sleep(1)

except KeyboardInterrupt:
p.stop()
GPIO.cleanup()

GPIO.output(7, False)
GPIO.cleanup()

This script changes the duty cycle of the PWM being supplied to the servo (changes the servo angle), from 10.5 (rest) to 7.5 (string pulled) for 3 seconds and back to 10.5 again.

Matt