3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Secret Knock Detecting Door Lock

Step 3Lay Out And Test The Circuit

Lay Out And Test The Circuit
We're going to breadboard the electronics to make sure everything works. If you never make mistakes you can skip this step.

I've provided both a schematic and a layout diagram for the breadboard. Follow whichever one you're the most comfortable with.

We're going to go slowly and check as we go.

#1: Wire the Piezo Sensor
Solder a pair of 12" (30cm) leads to the Piezo speaker.  Connect it between Analog pin 0 and the ground.  Also attach the 1M ohm resistor between Analog pin 0 and the ground.

Test: With your Arduino plugged into your computer (via USB or Serial cable) and open the Serial Montor window. (That's the button furthest to the right at the top of the Arduino development environment.)   With the Arduino powered on you should see the text "Program start."  Tap the piezo speaker and you should see the text "knock starting" and "knock" each time you tap it.  Stop for a second or two and you'll probably see "Secret knock failed" or "Door unlocked!"

If you don't see anything or see junk, make sure your serial port is set to 9600 baud and reset the power on the Arduino.  If you're sure it's right, then try tapping Shave and a Haircut (Don't forget the two bits.  See the video if you don't know it.) and see if you can get the "Door unlocked!" message.

If you get knock messages without tapping it may be too sensitive.  If so you'll need to edit the sketch.  Around line 27 raise the value of threshold.  This can be raised as high as 1032 if you have a very sensitive detector.

const int threshold = 3;  // Minimum signal from the piezo to register as a knock

Once you have it working the way you want it you can comment out (or delete) the lines that start with Serial...  We shouldn't need them any more.

#2: Wire up the LEDs
Lets wire up some LEDs so we don't have to use a serial cable to see what's going on.

Connect the red LED to digital pin 4 and green LED to digital pin 5 with their corresponding 560* ohm resistors in line.

Test: If you power the circuit the green LED should light.  If not, check your connections and make sure the LED is the right way around.  Every time you tap the green led should dim.  After tapping the correct sequence the green led should blink a few times.  Tapping the wrong sequence should blink the red one. 

If none of this happens, check the polarity on your LEDs and all of your connections.

Your LEDs might require different resistance.

#3: Wire the programming button
Solder 8" leads to the button.  Connect one side of the button to +5v.  The other pin on the button connect to digital pin 2 and, with a 10K resistor to the Ground.

Test: Apply power.  When you press the button the red light should come on.  Hold down the button and tap a simple sequence. When tapping while programming both LEDs should blink.  When you're done the pattern you just tapped should repeat on both lights.  After playback is complete, the new knock code is saved and the lights wil alternate red and green to tell you so.

#4: Wire in the motor
Solder 8" of leads to the motor and follow the design/schematic.  Be sure to get the diode going the right way and you might want to check the pins on the transistor to be sure they match the diagram. (Some transistors might have the pins in different order.)

Test: Power the circuit.  Tap the default "Shave and a Haircut" knock.  The motor should run for about half a second.  If not, check your connections as well as the polarity of the diode.

Extra Troubleshooting tips
1) If the motor turns very weakly the diode might be reversed.

2) If you need more power on your motor make the following circuit change: Move the wire that goes from the motor to +5v to the Vin pin on the Arduino.  This will supply the motor with 9v (or whatever voltage you're supplying to it.)

Tip: Check which way the motor turns.  It should turn the same way as you turn your deadbolt lock to unlock it.  If not, switch the motor's leads which should reverse the motor.

Congratulations!  You have  a working secret knock detector!

Now we have to put it into something more permanent that we can stick on our door.

« Previous StepDownload PDFView All StepsNext Step »
12 comments
Mar 8, 2012. 12:32 PMjakejj says:
I bought an experimentation arduino kit that comes with a DC motor. The problem is I dont know whether the motor will work or not. This is the link to the kit.

http://www.adafruit.com/products/170

Thanks so much :)
Sep 12, 2011. 1:41 PMbutcher_pro says:
Hi people, i have the whole thing up and running, but when i turn the monitor on keeps reading this:
Program start.
knock starting
knock.
knock.
knock.
knock.
knock.
knock.
knock.
knock.
knock.
knock.
knock.
knock.
knock.
knock.
knock.
knock.
knock.
knock.
knock.
knock.
New lock stored.


Every ten seconds. i know that the knoks are the readings and it seems like the program is running a loop. I tried getting the sensitivity threshold up to the limit but any threshold variations dont seem to change anything. Any ideas?

Thanks for such an amazing project and gretings from Mexico! :D
Sep 20, 2011. 9:17 PMbutcher_pro says:
ok, i got the thing up and running today, was a serious bad conection LOL anyways im up to the record button and found out that a little cable plugged anoe side only to the digital 2 and the othere end NOWHERE, it works as an "antena" and detects the prescence of static fields so you can record without button. This is cool, but i would like to know if some1 knows whats happening :(
Jul 18, 2010. 11:05 AMDannne11 says:
the engine starts when I plug it into the Arduino: ( has anyone any idea what I'm doing wrong?
Jul 8, 2010. 12:35 PMchestercito says:
hey man..I want to use this but for an electric lock...what do you think i would need no change in the code or in the circuit??
May 10, 2010. 1:47 PMeng.7oka says:
I need to test the piezo without the microcontroller connected.. any idea how to do that?

Feb 14, 2010. 10:38 AMgrahamdube says:
The motor I wanted to use was just on the threshold of running with the 5Volt output. So i installed a relay with its coil on the 5V output and then had a battery in series with the motor on the N.O. pins on the relay so that when the relay is tripped, the battery runs the motor efficiently. Thanks for the the overall instructable, it was amazing.
Dec 23, 2009. 5:48 PMamr9000 says:
 I tried switching the motors power supply to the Vin pin caues I didn't think it had enough torque, I put my finger on it and it with a little pressure and it couldn't turn, so after I switched it it wouldn't do anything.. no power at all..
so I put it back to the 5 V pin, and it when I tap shave and a haircut, it shakes a Liiittle bit.. I don't know if I just touched something else in the process or if this killed my motor..
Dec 24, 2009. 11:09 AMamr9000 says:
 I figured the direct power part out right before you replied to that, got it running again, now how do I get direct power to the motor? I figured out my motor is not the correct 'gear motor' but it's Very powerful with a direct line from the battery.. is there anyway to do this through the circuit?

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
187
Followers
14
Author:Grathio(Grathio Labs)
Creative swashbuckler. Writer for MAKE Magazine, presenter of inventions on TV, radio, magazines and newspapers. Professional problem solver. Annoyingly curious. Hacker of all things from computers ...
more »