Детектор стука в дверь на базе Ардуино

17.11.2011
By
Secret Knock Detecting Door Lock
on November 2, 2009 – 9:54 am

knock_detecting_lock_title_image.jpgUpdate #4: Nov 23: The Instructable is complete. If you want more instructions than are listed here, go here and read all of the steps, see all the photos, and enjoy!

Update #3: Nov 11: If you’d like to get updates about the progress of the kits (like when they’ll be for sale and how much) you can sign up for the mailing list here.

Update 2 Nov 5th:  Thanks for all of your (overwhelming!) interest in buying/making/finding one for yourself! Unfortunately I don’t have the spare time to make any extras right now. However I’m looking into what I can do to put together a kit or finished product for you guys.  When I know something concrete I’ll post a message to the site.

Update Nov 3: Added a proper schematic. (Thanks Nik!) Also hosted some of the images elsewhere so hopefully the site will stay up until I can find a new, more reliable web host.

How many times have you seen a secret hideout with a secret knock?  It’s a staple of cheesy dramas, Saturday afternoon movies, and tree houses throughout the world.

While working on another project I ran across the Arduino knock sensor tutorial.  Sensing a single knock is a great little project for learning about microcontrollers, but what about sensing specific knocks?  Seeeeecret knocks?  And if we could detect a secret knock, shouldn’t it unlock a door?   If you can’t tell by looking this was cobbled together from spare stuff around the lab, it’s not much more than a piezo speaker, a tiny gear reduction motor, and an Arduino. And PVC pipe.

A microphone (okay, really a speaker) presses against the door and listens for knocks.  If it hears the right number of knocks in the right cadence it triggers the motor to turn the deadbolt and unlock the door.  If the sequence isn’t recognized, the system resets and listens for knocks again.

knock_lock_side_view.jpgSide view.  Arduino microcontroller up top and peeking out at the left is the button to program new knocks. The shiny bit with the nut and bolt goes over the lock and is connected to a motor you can’t see.  But you can see the piezo speaker on it’s spring to press it against the door.

The default code is Shave and a Hair Cut but if that’s too obvious you can enter a new knock sequence by holding down the red button and knocking your new secret knock (up to 20 knocks).  The rhythm of your favorite song, Morse code, whatever!  The widget will play back your knock (by blinking the lights) so you can be sure it heard everything correctly.

The whole thing is attached to the door with suction cups

The components are simple, most of the work is done in the microcontroller.  The source code for the Arduino is available at the bottom of the page if you’re curious.

How does it work?

First it records the time between knocks.  If there is a long wait for a knock it stops listening and starts analyzing.

First it checks the number of knocks.  If that’s right, we go on to more vigorous authentication.   First it converts the absolute timing of the knocks to the rhythm of the knocks.  This lets us knock fast or slow and as long as we get the rhythm right it will unlock.  That way I can still unlock the door if I’m tired or full of caffeine.  After this it compares the timing with the secret key and if any individual knock is off by too much or the whole thing is off by a certain average amount the door stays locked.  If not, we trigger the motor to turn and the lock to unlock.  If the programming button is pressed it saves the rhythm information and then plays it back.

The detection is surprisingly accurate and can even be dialed up so it’s precise enough  to detect an individual person’s variation on a knock, similar to a Morse coder’s ‘fist‘.  (Though when the verifying is this tight it also triggers false negatives which are annoying.)

To keep things simple (and it’s because it’s what I had available) a motor is attached to the deadbolt using two pieces of spring steel bolted across the D shaft of the motor so that the connection will slip when the lock turns as far as it can. A more precise (and probably durable) way to do it would be to use a servo to turn the lock or have a detector sense when the lock had reached its extent.  Or replace the dead bolt with a solenoid.  Or whatever else you can think of.

knock_lock_circuit.jpgThe circuity is pretty basic and fits on this little sliver of perforated board. Here I’m testing everything before cramming it into the «case».

The rest of the electronics are nothing special.  Its so simple that just adding feedback LEDs almost doubled the parts count.  The Arduino has a lot of unused potential on this project.

No proper schematic yet, but there’s a layout and parts list at the bottom of the page. Look for a fully documentedInstructable soon.

knock_lock_tight_fit.jpgIt’s a pretty tight fit.  Which is why people don’t generally use 1/2″ PVC pipe for project cases.

With some extra electronics (an H-bridge) it would be possible to have the door automatically lock as well as unlock. Other improvements or changes that someone could do:

  • Adding a knob to adjust the sensitivity.
  • Building it into an actual door knocker.
  • Using a more economical microcontroller and enabling a sleep mode for better battery life.
  • Making the whole package small enough to fit inside the door.
  • Storing several knocks so several people can have their own private knocks.
  • Adding a real-time clock and using different knocks for different days of the week or times of day.
  • Listening for door bell presses rather than door knocks.
  • Adding a servo or solenoid powered knocker to provide feedback through the door.  It could then offer a challenge-response security where the door starts a knock sequence and the user has to finish it correctly.
  • Rather than listening for knocks, putting a photoresistor in the peep hole and detecting flashes of light from a pocket flashlight or simply by placing your hand over the peephole. Or an infrared receiver and use special key presses on a remote control.

Do I have to point out that this is not a great security measure since overhearing a knock sequence is pretty trivial?  No.  But it’s fun to make and play with.

Here’s my code:
Update: If you have trouble with cut and paste below you can download the .pde file here.

And here’s the layout and parts list. (click to zoom in.)

knock_sensor_layout_and_parts_list.jpg
Special thanks for this schematic to the hard work of Nik K.B. (knutsonbradacnl(at)gmail.com)

Secret Knock Lock Schematic

Also thanks to Adafruit Industriesoomlout, and Sparkfun between whom I think I bought all of the electronics for this project.  And even if I didn’t, they’re awesome.

PS: Here’s a zero-technology solution to the «Yeah, but they’ll overhear your secret knocks» problem:  Scream while knocking.  No one will overhear the knock over the racket you’re making.

Добавить комментарий