Picture of Secret Knock Detecting Door Lock
Protect your secret hideout from intruders with a lock that will only open when it hears the secret knock.

This started out as a bit of a joke project, but turned out to be surprisingly accurate at judging knocks. If the precision is turned all the way up it can even detect people apart, even if they give the same knock! (Though this does trigger a lot of false negatives, which is no fun if you're in a hurry.)

It's also programmable. Press the programming button and knock a new knock and it will now only open with your new knock. By default the knock is "Shave and a Haircut" but you can program it with anything, up to 20 knocks long. Use your favorite song, Morse code, whatever.

Maybe a video will explain it better:

Important Notes:
(I hate to even have to say this, but since someone's going to say it, I'll say it first:)
1) This is for entertainment purposes only. Really. This decreases the security of your door by adding another way to unlock it, and it makes your unlock code known to anyone who can hear. If you put this on your door, be sure to carry your key too. The batteries might die, the suction cups might fail or you might forget your knock. Don't complain to me if someone imitates your knock and steals all your stuff, you've been warned.

For obvious improvements to safety, security and whatever, see the final page of the Instructable.

2) This is not a project for a beginner! Read through it carefully and be sure you understand it before you start! I will not take time to answer questions that are already in the instructions or from people who have gotten in over their head.

(If you think this project is too complex you might go here and sign up for the kit mailing list. The kits will be much more simple than this.)

Sorry about that. Now that that's out of the way, lets get to work.
VisionaryNutcases made it!9 months ago

My version is installed in a fridge and using an electromagnetic lock - keep those office thieves away!




Krizbleen made it!8 months ago

Guys - thank you for this tutorial! I used the code to program a secret sliding library door project and it works great. The secret knock is the part people like the best. People giggle when I show it to them. I owe you a beer!


Grathio (author)  Krizbleen8 months ago
Fantastic work! I love how well the bookshelf hides your secret room. Never would have guessed it was a pocket door.

Thanks for sharing!
KGuy1 year ago

Here we are! Finally done after months of procrastination! I added a buzzer and a third led (not in the picture). The code was changed very slightly but it works perfectly. A latch in the back hangs it on the door. I must thank you, however for the genius of this invention.

Eloisa CamelM KGuy10 months ago

hi sir, how did you do this one. where do i put the new code for the led and the piezo.. please, needed for a presentation, our prof. did not give us enough time to master this. and it serves as our final exam.. thank you in advance..

Grathio (author)  KGuy1 year ago

Beautiful work! Thanks for sharing!

Matienzo1 year ago

here is my little one in an iphone box

vinny034 years ago
I have modified the Arduino code to add the functionality of ''Users''. What it does is that it let you program a secretCode for four users. For example: If you push the button X times, after 4 seconds the green LED will blink X times and then you enter program mode (simply do your secret code). I also added the functionality to take a picture when your sequence is bad with LabVIEW and a WebCam camera. Then the picture is saved in my folder and pictures are incrementing with numbers.
Circuit sur porte.JPGMontage.JPG
Grathio (author)  vinny034 years ago
Looks great, and really nice added features! I had done a version with his & hers knocks, but this goes well beyond that!

Fantastic job!
bserrato4 years ago
I saw your project some time back and I thought it was great. I decided to take it and improve on it, the result was a system that locks and unlocks. Also if a person inputs an incorrect knock, the system will send a signal via bluetooth to a computer terminal to snap a picture and save it.


Check out the vid. Hope you like it.
Grathio (author)  bserrato4 years ago
That really made my week! It looks fantastic and works great. And the bluetooth camera is a great idea of added security.
josiasfilho5 years ago
Hi Steve!
As you know, I already started to do mine, with a few modifications. I uploaded a new video with a new option:

As soon as I finish my project I'll post the code online
Did you finish yet?  Can't wait to see the code.
Grathio (author)  josiasfilho5 years ago
Fantastic work with the servo and the unlock option.  (And an off switch!)

It looks like your setup is really sensitive.  Really nicely done! Your achievement patch is on the way!
TheBestJohn5 years ago
I have been playing around with this code for the past hour or so and found out how you can hard code in your own rhythm if need be.... at the part that looks like this
// If we're recording a new knock, save the info and get out of here.
  if (digitalRead(programSwitch)==HIGH){
      for (i=0;i<maximumKnocks;i++){ // normalize the times
        secretCode[i]= map(knockReadings[i],0, maxKnockInterval, 0, 100);

add this little guy
and open up your serial monitor....
make sure you un-commented the serial begin up at the setup and then it should spit some numbers back at you... put these numbers into the array and enjoy.
Whoot finally got my relays for my motor and heres a neat little Idea for your visual feedback....

Grathio (author)  TheBestJohn5 years ago
Oh, and for your awesome work you have been added as an official Master of Secret Knocks.  Your patch is on its way!
Grathio (author)  TheBestJohn5 years ago
 This is awesome!  Thanks for sharing your code and video.  Having the door unlatch too makes it that much more mysterious.  And I like the feedback through the peephole.

Great work!

And if I ever have any questions about taping something to something else I'll be asking you. :)
4B-24N48 minutes ago

Can I use a side button to generate a auto lock function?

4B-24N2 days ago
i would use it in the school locker
4B-24N4 days ago
how to open it inside ?
4B-24N4 days ago

how to control inside?

xezark9 days ago
keyless16 days ago
2illickans29 days ago
KiwoongW1 month ago

I really want to see a code and parts list . Can you give me a code and parts list?
Thank you

KiwoongW1 month ago
WilliamL221 month ago
FadiJ1 month ago
Great job
Pedro PauloL2 months ago

First of all, congratulations for this nice project.

Grathio, i'm a Brazilian student and i'm going to develop a similar object using Arduino at school, but i have one doubt. How can i use a digital knock sensor instead an analog piezo sensor? Is it very difficult to convert your code (using analog entries) to a code with digital entries(like ky-031)?


mouse232 months ago

Here's an adjunct idea for those more paranoid. As long as an arduino is employed, one can add an keypad for entering a secret code. But the code is not correct if it is not punched in on the right cadence.

For the lock clamp...why not get a large piece of PVC (large enough to encompass the lock), and then fill the innards with some sort of hardening putty. Press your lock knob into the putty enough to make a perfect indent, then let the putty harden. Then mount the motor to this somehow. Or you could use putty to make a mold of your knob, and make it from something stronger, like cast aluminum.

bobelon2 months ago

Geeeze, Just when I was about to give up on instructables because of the endless dumbass projects using duct tape and making fudge this brilliant piece of irreverent mind expansion comes along - faith restored - thanks!


Nice, you should enter it in the home automation contest!

can we use arduino uno for knock detecting door lock system?

Yes, any Arduino should be able to handle this. Are you asking if the Arduino can detect if the lock is engaged/on?

Harrylorence2 months ago
Your schematics is the clearst i have ever seen...u rock..ur r an awesome inventor...love u
PierrotT made it!3 months ago

Hi, thank you for this instructables !

I have change the motor with an Servo, and an Arduino Nano in a little box.

I will use it for a Geocache ;)

2015-05-28 17.17.28.jpg2015-05-28 17.18.00.jpg
hakange3 months ago

Hi, Thank you for great tutorial and walkthrough guide. I am doing the project step by step and checking each step as suggested. Things go normal when running my Arduino Uno via USB Cable or 9V Battery through barrel Jack. My final application is supposed to be working on wall adapter so I am checking each step with a 9V wall adapter too. At this point things go weird. Even on the early stage, checking piezo and led functioning, all things go crazy. Red and Green LEDS are on/off randomly when on wall plug. Attached is the picture of adapter. Am I missing something here? This occurs only when Arduino powered by 9V wall adapter.

Thanks in advance.

hakange hakange3 months ago

Edit to my post: I figured out that switching to wall adapter results in extra sensitive piezo! Piezo sensing everything (or may be there iselc noise) I tuned the treshold values in the original code and everything works perfect. If you have any other suggestions ( changing the resistor of pieze etc) please let us know. Thank you.

when i try to upload the code this message is shown ''Arduino: 1.6.3 (Windows 7), Board: "Arduino Uno"

Sketch uses 4,404 bytes (13%) of program storage space. Maximum is 32,256 bytes.

Global variables use 362 bytes (17%) of dynamic memory, leaving 1,686 bytes for local variables. Maximum is 2,048 bytes.

avrdude: ser_open(): can't open device "\\.\COM4": The semaphore timeout period has expired.

Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

This report would have more information with

"Show verbose output during compilation"

enabled in File > Preferences. '' what should i do

Grathio (author)  ahmedmagdy88994 months ago

As it says, there is a problem uploading to the board. (That is, your computer cannot talk to the Arduino.) You should try the suggestions at the link provided, http://www.arduino.cc/en/Guide/Troubleshooting#upl...

what a cool idea

sharlae.brown5 months ago

I need so much help! My science project is due in a week and I don't even understand how to test it on a circuit board or complete the step, "

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." Please yep me. Email me at sharlaebrown@gmail.com and change the subject to secret knock lock or something. Please help!

Great project ! .... I was verry pleased to see that it works ( the code and all the components ..everything) i have only one problem .... my motor isn't strong enough to turn the lock... im using a 9-24 DC motor from an old printer that i salveged ...any tips or advice ? thx

ThomasS135 months ago

It's working great! I did make a small modification to the code to allow the programmed knock to survive across resets / power loss using the EEPROM. If you're super concerned about security, you can always set the lock fuses, but if you're super concerned about security, you would probably be using a different lock system (Important Note 1) :-)


mathewvgarcia made it!5 months ago

This was berry helpful thank you. I'm working on a music box for my wife and I though I would add the Knock detector to make it a little more fun. Thank you!

Zelda Knock.jpg
YousefA16 months ago

when ever i knock it says "New lock stored." after the knock what do i do??? :(

yashkapoor7546 months ago

unable to upload code gives error Arduino: 1.6.0 (Windows 7), Board: "Arduino Uno"

sketch_mar01a.cpp.o: In function `setup':

/Arduino/sketch_mar01a.ino:46: undefined reference to `pinMode'

/Arduino/sketch_mar01a.ino:47: undefined reference to `pinMode'

/Arduino/sketch_mar01a.ino:48: undefined reference to `pinMode'

/Arduino/sketch_mar01a.ino:49: undefined reference to `pinMode'

/Arduino/sketch_mar01a.ino:54: undefined reference to `digitalWrite'

sketch_mar01a.cpp.o: In function `triggerDoorUnlock()':

/Arduino/sketch_mar01a.ino:163: undefined reference to `digitalWrite'

/Arduino/sketch_mar01a.ino:164: undefined reference to `digitalWrite'

/Arduino/sketch_mar01a.ino:166: undefined reference to `delay'

/Arduino/sketch_mar01a.ino:168: undefined reference to `digitalWrite'

/Arduino/sketch_mar01a.ino:172: undefined reference to `digitalWrite'

/Arduino/sketch_mar01a.ino:173: undefined reference to `delay'

/Arduino/sketch_mar01a.ino:174: undefined reference to `digitalWrite'

/Arduino/sketch_mar01a.ino:175: undefined reference to `delay'

sketch_mar01a.cpp.o: In function `validateKnock()':

/Arduino/sketch_mar01a.ino:210: undefined reference to `digitalWrite'

/Arduino/sketch_mar01a.ino:211: undefined reference to `digitalWrite'

/Arduino/sketch_mar01a.ino:212: undefined reference to `delay'

/Arduino/sketch_mar01a.ino:213: undefined reference to `digitalWrite'

/Arduino/sketch_mar01a.ino:214: undefined reference to `digitalWrite'

/Arduino/sketch_mar01a.ino:215: undefined reference to `delay'

/Arduino/sketch_mar01a.ino:217: undefined reference to `digitalWrite'

/Arduino/sketch_mar01a.ino:218: undefined reference to `digitalWrite'

/Arduino/sketch_mar01a.ino:221: undefined reference to `delay'

/Arduino/sketch_mar01a.ino:222: undefined reference to `digitalWrite'

/Arduino/sketch_mar01a.ino:223: undefined reference to `digitalWrite'

/Arduino/sketch_mar01a.ino:225: undefined reference to `delay'

sketch_mar01a.cpp.o: In function `listenToSecretKnock()':

/Arduino/sketch_mar01a.ino:85: undefined reference to `millis'

/Arduino/sketch_mar01a.ino:86: undefined reference to `millis'

/Arduino/sketch_mar01a.ino:88: undefined reference to `digitalWrite'

/Arduino/sketch_mar01a.ino:90: undefined reference to `digitalWrite'

/Arduino/sketch_mar01a.ino:92: undefined reference to `delay'

/Arduino/sketch_mar01a.ino:93: undefined reference to `digitalWrite'

/Arduino/sketch_mar01a.ino:95: undefined reference to `digitalWrite'

/Arduino/sketch_mar01a.ino:99: undefined reference to `analogRead'

/Arduino/sketch_mar01a.ino:103: undefined reference to `millis'

/Arduino/sketch_mar01a.ino:108: undefined reference to `digitalWrite'

/Arduino/sketch_mar01a.ino:110: undefined reference to `digitalWrite'

/Arduino/sketch_mar01a.ino:112: undefined reference to `delay'

/Arduino/sketch_mar01a.ino:113: undefined reference to `digitalWrite'

/Arduino/sketch_mar01a.ino:115: undefined reference to `digitalWrite'

/Arduino/sketch_mar01a.ino:119: undefined reference to `millis'

/Arduino/sketch_mar01a.ino:130: undefined reference to `digitalWrite'

/Arduino/sketch_mar01a.ino:132: undefined reference to `digitalWrite'

/Arduino/sketch_mar01a.ino:133: undefined reference to `delay'

/Arduino/sketch_mar01a.ino:134: undefined reference to `digitalWrite'

/Arduino/sketch_mar01a.ino:135: undefined reference to `delay'

/Arduino/sketch_mar01a.ino:137: undefined reference to `digitalWrite'

/Arduino/sketch_mar01a.ino:143: undefined reference to `digitalWrite'

/Arduino/sketch_mar01a.ino:144: undefined reference to `digitalWrite'

/Arduino/sketch_mar01a.ino:146: undefined reference to `delay'

/Arduino/sketch_mar01a.ino:147: undefined reference to `digitalWrite'

/Arduino/sketch_mar01a.ino:148: undefined reference to `digitalWrite'

/Arduino/sketch_mar01a.ino:149: undefined reference to `delay'

/Arduino/sketch_mar01a.ino:150: undefined reference to `digitalWrite'

/Arduino/sketch_mar01a.ino:151: undefined reference to `digitalWrite'

sketch_mar01a.cpp.o: In function `loop':

/Arduino/sketch_mar01a.ino:59: undefined reference to `analogRead'

/Arduino/sketch_mar01a.ino:61: undefined reference to `digitalRead'

/Arduino/sketch_mar01a.ino:66: undefined reference to `digitalWrite'

C:\Users\kaumudi\AppData\Local\Temp\build8307707147705721311.tmp/core.a(main.cpp.o): In function `main':

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/main.cpp:32: undefined reference to `init'

collect2: error: ld returned 1 exit status

Error compiling.

please fix

Grathio (author)  yashkapoor7546 months ago

I've just tested the code with your setup (Arduino 1.6.0 IDE, Windows 7 Arduino Uno) and found no errors.

Troubleshoot your system by uploading a simple sketch, like Blink, and make sure that works. If so, download the secret knock sketch again, and follow the instructions.

can we use arduino uno for knock detecting door lock system?

Aidanj17 months ago

Have not made this yet, but you can make a song detector where you have to play a song to open it. It would take a little more programming, but would be fun.

goldenshuttle7 months ago

If you replace the piezo with a microphone, will it work as a secret clap switch ?

Grathio (author)  goldenshuttle7 months ago
If you want to use a microphone, check out this version of the project: http://makezine.com/projects/sound-activated-outlet/

(It's not a door lock, but you should be able to swap the circuit for the microphone, and the code, and get something that works.)

Thanks Grathio: indeed the link you gave has things that would do. Now I am working on a totally different project based on the clap switch..sky is the limit here...many thanks..please keep posting these creative gems.

thank you for this great project sir..

Sundback7 months ago

Hi Grathio!

First of all - a very nice project! I have a tiny problem and that is that when I've unlocked the door I can't turn the lock back to it's origin. When I've unlocked the door, how am I supposed to do so I can turn the lock back?

I would really like to get an answer.

Thanks in advance, Alex.

Nadeera NadiM8 months ago

what type of motor and lock its specification

we took this idea for diploma engineering project, we made the circuit connection correctly. after that connect it to the Aurdiuno (freeduino board). but the motor is not running. can u tell us the probable errors? pls reply fast..........

RHED8 months ago

can i use electret mic as substitute to the piezo?

ArvindS211 months ago

Hey Grathio

We took this idea for school project. We made the circuit connections correctly. After that we connected it to the Ardiuno ( UNO instead of a duemilanove). But the motor is not running. Can u tell us the probable errors? ( Will UNO cause problem since we didnt use Duemilanove?)


AzizK1 ArvindS28 months ago

we are using Uno board aswell, code will not compile properly. can you help us?

Krizbleen made it!8 months ago

Guys - thanks for posting this tutorial! I used the code as part of my secret sliding library door project and it works great. People giggle when I demo it to them. I owe you a beer for this!

shreyask1 made it!9 months ago

AWESOME!!!!!project......It works properly.......Can someone say me how can i put a servo instead of a geared motor........PLZZZZ.


Hey guys, how can I program a DEFAULT secret code? I means how can I determinate de values (in the array), per knock? for example if I want something like "HBD to YOU" or "We r the champions my friend", many thanks for your help.

Grathio (author)  El_Minion_Dice9 months ago
Great question! The default timing information is stored in a variable near the top. It looks like this:
 int secretCode[maximumKnocks] = {50, 25, 25, 50, …
The easiest way to figure out what the new numbers should be for your rhythm is to have the lock its self tell you. To do that find the line near the bottom of the sketch that reads:
// only turn it on if there's a delay
Right below that, add this, on its own line:
Serial.println(secretCode[i], DEC); 
This will print out the secret code values when you program a new knock.

Upload the modified sketch to your Arduino, and keep it plugged into your computer.  Open up the Serial Monitor in the Arduino IDE. (It's the little magnifying glass button on the upper right. In older versions it looks like a radio.)  On the little window that pops up, be sure to set the baud rate to 9600. (The little pulldown at the bottom right should read "9600 baud"). If everything's working correctly you should see the text "Program start." in the serial window, and it will print some other status messages as you use the knock.

Now program a new knock like normal. When you're done you'll see some text and numbers in the serial output window. There will be twenty numbers.

Go back to the sketch and find the line near the top of the sketch that starts:
int secretCode[maximumKnocks] = {
And replace the numbers with your new numbers, starting from the top of the list. Make sure there are 20 numbers, and there are commas between them all, or the sketch will break. When you're done it might look like this (but with your own numbers, of course):
int secretCode[maximumKnocks] = {72, 54, 66, 60, 100, 45, 22, 80, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
After making the change, upload the modified sketch, and you're done! The new default will have been changed.
george.kaileh made it!9 months ago


I've made your project, but I have changed 2 things in it:

1- Instead of piezo speaker I have kept resistor alone so nobody can hear the knock (its now working by touch, all you have to do is touch the resistor as the secret knock and the door will open)

2- I have put the battery from outside the door as a key to power everything, by that way you won't worry about the battery dying or electricity outage (if you're using a power adapter).

justnik679 months ago
The author has stated he will not answer questions for beginners. So did you make this for people that already have the skills to do it on their own? If you are not here to teach, then you are just showing-off! I am a total beginner but managed to figure out a way. Instead of using a motor, I used a 12v solenoid lock from adafruit. It automatically locks and there is no need to make metal brackets or a PVC contraption. Use a seeed relay shield. Move motor control digital pin 3 to one of the relays on digital pin 4,5,6, or 7. Now you can control anything up to 120vac. You will also have three additional unused relays available. Move led 4 and 5, to digital pins 8 and 9. I also took apart a Gfi 120vac outlet I had installed just outside the door, and wired the reprogram button to the test switch. If you want it fail safe, rewire the reset button in the gfi to a battery. 120vac power can also be used from the outlet, to the relays if you need it. Anyway, that's how this beginner did it.
goldenshuttle9 months ago

This is a great project. Can it be extended to make a multi-appliance clap control system ? like certain clap opens curtains, certain clap closes curtain, another clap opens cupboard drawer, and other clap closes it..and so on in one Arduino sketch ?

Eloisa CamelM10 months ago

thank you sir it worked.. :)

Eloisa CamelM10 months ago

it worked sir.. thank you very much..:)

mr led11 months ago
that`s so interesting.
reyscreamz11 months ago

what type of door lock should i use?

please specify :D

thank you so much

reyscreamz11 months ago

what type of door lock should i use?

please specify :D

thank you so much

reyscreamz11 months ago

what type of door lock should i use?

please specify :D

thank you so much

reyscreamz11 months ago

what type of door lock should i use?

please specify :D

thank you so much

reyscreamz11 months ago

what type of door lock should i use?

please specify :D

thank you so much

ndiaz91 year ago

im just wondering. why do you need to put the knock detector at the back of the door and not in the front door? thanks for your reply, if ever :)

longandy made it!1 year ago

Here's my build - thanks for an awesome instructable!

changes - replaced motor with relay to trigger an external motorized door opener

inverted some of the green LED states so it is normally off but flashes on when knocking

sarci1 year ago

we have a filipino who made this project? just txt me this is my # 09169033782 and help me how to do this project! please! tnx...

docu please :)

What size does the SPST momentary pushbutton have to be?

maski11 year ago

does it have to be gear motor or can i use solenoid lock instead?

palominom1 year ago

I'm a guy from Spain and I am doing this proyect for a competicion but I have a problem with the gear motor. All is good except the gear motor it isn't move i don't know why?

Please help me, THANK.


Danny1411 year ago
Please help I need this for a school project please...
Danny1411 year ago
Hi guys! Please what changes do I add to the code if I want to replace the knock sensor with a capacitive touch sensor
mbessam1 year ago

i have all things goin great but my motor is not spining

billbillt1 year ago

very cool

Matienzo1 year ago
Hi there, I hope there is someone hanging out in this project.
I got a problem with my motor.
I made it work in the breadboard but when i solder that circuit it doesn't work. I'm getting the knock and the button running but the motor does not react when the lock is opened. I checked the circuit for about 3 hours and it looks exactly as the one here (not the breadboard, the other one)
Any one made it like that?
jkctech1 year ago
idk why but my programming button isnt working, is this because im using an arduino uno or did i mess it up? everything works but the programming button.
KGuy jkctech1 year ago
Check the polarity of your rectifier diode.....and if that doesn't work continuously check the circuit diagram for any mistakes on your breadboard
KGuy1 year ago
Whew! After a few weeks, I have successfully completed the (perfectly running) circuit. I did have to make a few modifications to the code to increase the sensitivity of my piezo (thanks to your helpful hints) but hope to find a way to increase it even more. I plan to finish this project (the hardware) in the next few weeks.....
I find your projects amazing, good sir.

And for all those who can't seem to get their motor running.....
MAKE SURE YOU KNOW THE VOLTAGE....my first few motors were over the standard voltage of 5v. If your motor uses around 6 or 7 volts, I recommend using the vin pin, which gives you a little extra power (keep it safe though). If your motor doesn't work no matter what, get a lower voltage motor :)
sleepyone1 year ago
Hi there, I am currently working on this project and manage to get everything run smoothly. However instead of using a buzzer to detect knocks, I use two digital arduino pins to create a touch sensor as well as replacing the gear motor with a servo. Now, for added security, I would like to prompt the user to key in the original touch rhythm before they are allowed to key in the new touch rhythm they desire when the button is press. I am not very good in programming, I was wondering if you would be able to assist me in this perhaps? hope to hear from you soon. thanks in advance.
jkctech1 year ago
How to program the knock?
nahtanoj1 year ago
Can someone please tell me were you can get the 5v gear motor ad the perfboard?what if
Kenneth DK1 year ago
hello Steve
I decided to recreate this project for a school project I have coming up this month. I saw this video a couple of years ago and recently bumped into it again. I really want to build it. I have done all of the construction used for this project but I need a little help with the code. I used a servo instead of a gear motor and there for the code does not work. I do not know how to code a Arduino at all!!!!!! Could you please give me a code that will work for an Arduino?? it would really help me a lot. in one of the other vids there was a guy who could unlock his door and then press a button and it would lock again. If you have time could you please make the code enable that feature too. I really need your help.......
Kenneth DK1 year ago
Any ideas how I can attach a servo instead of a motor.
Jawknee52 years ago
I don't know if anyone who has successfully completed this actually checks the comments, but im in the process of doing this- but i added an H-bridge to do two seperate knocks, one to lock and one to unlock... The circuit is correct, by switching the wire motor output from one pin to the other on my Hbridge IC, i can get the motor to move in two different directions, but apparently I'm not the best with programming...but i know a quite a bit.

Im just not sure on where i would add programming, just a simple knock of three, that would make a digital pin(7 in my case) HIGH and enable my motor through the Hbridge...... any help would be great!
Berniecheah2 years ago
Hi. Im interested in making your project but the only motor I have with me right now is a 12V stepped motor. The one with 5 wire-cables ( red-ground, orange, pink, blue, yellow ). I was wondering is it different compared to the gear reduction motor u used for this project? I assume the arduino codes will need some changes? Hope to hear from you soon! :)
cstawell2 years ago
brilliant, I think my little girl would find this a brilliant toy, XD
Andsetinn2 years ago
Very interesting idea and well executed. I've been thinking of putting similar system on the doorbell in my apartment building so that ringing the bell in a certain pattern would open the downstairs door.
There are security issues that stop me. :(
whitkari42 years ago
My senior project team just got our device to work with a servo. Yay we plan on adding wifi so that we can figure out how to lock and unlock remotely via a website and mobile application. Once we get everything we plan on posting our code etc for others.
snibbalol2 years ago
My red Light is all ways on so that`is not a good thing right? and another trouble i am having is eaven tho reject value and average reject both are above 80 and my knock is just simple 4 knocks 100, 100, 100, 100, 0, 0, 0,.... etc my device wont regonize the knock as right one and wont do anything to motor what so ever could someone please assists me with this issue since i would need to complete this work by the end of this week / begin of the next week. thank u so much beforehand. :)
dmarinho2 years ago
hey, newbie here, can someone upload the code to the lock and unlock system? also the gear motor, does it hold the key or you got to put the device literally inside the door?(sorry for bad english =\ )
enagel32 years ago
that got my attention

masonson2 years ago
cool next project
hanyc932 years ago
Does anyone know what is the use of the diode? I know it allows current to flow in one direction only but when I remove the diode, the motor still can turn properly.
Grathio (author)  hanyc932 years ago
It's called a Flyback Diode and you really want to keep it in there. Electric motors generate spikes of current when they're stopped and the diode is to protect that current from feeding back into the rest of the circuit, destroying the Arduino or whatever other circuitry you have attached. It's the 3¢ part that will save you $300.  Read the link above for much more information.
mrmerino2 years ago
Oh my god, I just realized that putting this in my hypothetical future kid's treehouse would make me the coolest dad ever.
n79c2 years ago
I am having a problem with button - it adds a knock when I release the button - any suggestions? Everything else works.
Grathio (author)  n79c2 years ago
This is just a guess, but I suspect that releasing the button causes enough physical movement that it registers as a knock. To fix it I'd try one of these:
- Reduce the sensitivity (see step 2)
- Use a button that has softer action.
- Move the button further from the sensor.
- Physically insulate the button so vibrations aren't transfered to the sensor.
- Be really really gentle when releasing the button.

It's possible that the switch is very electrically noisy and is putting a spike somewhere that puts garbage into the circuit, in which case changing to a different model of button would help.
n79c Grathio2 years ago
Thanks for responding - no I am a dork! I watched your youtube and realized that I released the button too soon. When I waited until both lights went on it was ok. My bad.It is finished and boxed you and working great. Thanks
PS any chance of getting the unlock/lock code that someone said they did?
Grathio (author)  n79c2 years ago
This is just a guess, but I suspect that releasing the button causes enough physical movement that it registers as a knock. To fix it I'd try one of these:
- Reduce the sensitivity (see step 2)
- Use a button that has softer action.
- Move the button further from the sensor.
- Physically insulate the button so vibrations aren't transfered to the sensor.
- Be really really gentle when releasing the button.

It's possible that the switch is very electrically noisy and is putting a spike somewhere that puts garbage into the circuit, in which case changing to a different model of button would help.
n79c2 years ago
Hi Can I please have the code that will use a server motor and will lock and unlock?
SubEclipse2 years ago
I'm in the early stages of attempting this build, and am gathering all the necessary parts.

I can't come up with a motor locally, and have been looking online. Everything I find online is either coming from China or Canada and was hoping to find something located in the US.

The Solarbotics GM22 used as an example looks great, though a little expensive... I couldn't seem to find these offered by anyone other than the manufacturer (also in Canada).

If someone could point me in the right direction, I would greatly appreciate it.

I got this all wired up on a breadboard tonight and it's working perfectly (substituting the gear motor with a LED for now). Now I just need to track down a decent motor and put it all together. I'm about to break down and order the one from Canada, since I can't seem to find any decent ones offered from US vendors.
twighahn2 years ago
could you dummy this down for me?
twighahn2 years ago
would you please dumy this down for me i think it would be a great idea for a panic room
englishfire2 years ago
How can I modify the Code to work with a servo?
englishfire2 years ago
Why to you use a 9v battery? Why is 5,5v from the arduino Not enough?

In which way do I have to change the code if the motor should move to the origin position after a view minutes?

Greetings from Germany
Grathio (author)  englishfire2 years ago
>"Why to you use a 9v battery?"

For two reasons. 1) The motor doesn't create enough torque at 5v to turn the lock. And 2) The 5v pin on the Arduino can only safely pull about 200mA. The motor can pull over 500ma under load. This keeps the voltage regulator on the Arduino from burning out.

>"In which way do I have to change the code if the motor should move to the origin position after a view minutes? "

This is not a simple change and would require more circuitry to allow the motor to turn the other way. (Typically an H-Bridge is used for this.)

A simpler way to do this would be to use a servo to turn the lock since they're naturally high torque and can turn either way without extra components. I don't have an Instructable for that yet, but do a web search for "Secret Knock Gumball Machine" to see how that would work.
yozarseef3 years ago
I have some difficulties designing a model with locking ability .. any help please? I will be thankful
KGuy3 years ago
Is it basically the same with arduino uno?

If it is I could make it today.......

Nice job!
cmelad3 years ago
good day sir, I was just wondering if you can give any recommendations or possible innovations for this project. I am studying engineering here in the Philippines and I want to make this as a final year project. my teacher demands for an innovation and I cannot think of any.
eng.7oka5 years ago
hey.. sorry to bother you again.. I just want to know what the function (map(knockReadings[i],0, maxKnockInterval, 0, 100); does..
Grathio (author)  eng.7oka5 years ago
Arduino reference for the map() function.

This normalizes the data so the longest time between knocks gets "100" and the rest are adjusted proportionately.  We do this so it doesn't matter if you knock fast or slow as long as you get the rhythm correct.
I read that in the comment.. but the thing is I'm programming usuing another language.. so I need to understand the mathimatical algorithm behind it.
Grathio (author)  eng.7oka5 years ago
The best description of what it does is in the link I provided to the description of the function in the Arduino Reference manual.
this is the function

long map(long x, long in_min, long in_max, long out_min, long out_max)
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
area363 years ago
My motor is getting no action. I have tried it on the 5v and vin pins along with switching the diode and still nothing. Anyone know whats wrong?
bmondor3 years ago
where do the positive ends of the LEDs go. also i only have 2 wires that go into the digital pin in the arduino. i cant figure out how to get it to work even though i have all the wires in which seem to be the right places.
darthtony5 years ago
Is it possible each time you program a new knock code(on the fly , using the program button)  the arduno stores it in the EEPROM so you dont have to re program it when you reset?
can someone help me with this?
Grathio (author)  darthtony5 years ago
Yup, it is possible, and a good feature. Here's an outline of the changes you'll need to make:

- in Setup()  you'll need to read the data from eeprom. (If there is any.)
- in the validateKnock() function (around like 208) you'll need to write the info to eeprom.  You could do it as part of this code loop:

 for (i=0;i>maximumKnocks;i++){ // normalize the times 	secretCode[i]= map(knockReadings[i],0, maxKnockInterval, 0, 100);  	// Write the value of secretCode[i] to EEPROM here // } 
Here are examples of how to read and write EEPROM.

You also might want to look at the code for my Rock-Paper-Scissor Playing Glove for an example that saves and reads info to/from the Arduino EEPROM.
Grathio (author)  Grathio5 years ago
 Gah.  Instructables is still eating preformatted text.  Lets try the code again:
 for (i=0;i>maximumKnocks;i++){ // normalize the times
 	secretCode[i]= map(knockReadings[i],0, maxKnockInterval, 0, 100); 
 	// Write the value of secretCode[i] to EEPROM here //

awesome... i've got my code reading the EEPROM on power-up and writing to the EEPROM whenever a new knock is programmed.

i also added some audio feedback, for instance a "game show"-like "fail" buzz through a second piezo for a bad knock, and audible playback of a newly-programmed knock in unison with the LED flashes since it seems like listening to the code being played is absorbed by my brain easier than just watching the LEDs (for me, it all stays in the realm of sound).

also, i'm triggering an Electric Door Strike (commonly used in apartment complexes to remotely unlock a door) instead of a deadbolt or door handle... this means less hardware on the door (only the sensing piezo, actually) and the added convenience of simply being able to push the door open (very helpful when one's arms are full of groceries... and/or beer!).

thank you for this brilliant project and your kindness in helping everyone here who seeks to employ this device around the world!
Grathio (author)  KevCarrico3 years ago
Fantastic work, thanks for sharing!

We've been playing with electric door strikes as well. They're obviously more invasive (you have to install them in the door frame) but they work much better. You can even mount the knock sensor somewhere other than the door if you want to be extra sneaky. (Or if you're using it to open a secret door hidden by a book case.)
lol... all great stuff.

added a "darlington pair" touch switch to a bare metal thumbtack and now the code can be tapped -- silently -- with one finger.

no more neighbors sneaking in and stealing my beer.

thanks again!
stephin993 years ago
oh my ive got it!!! add a wifi unit and have it text you every time someone enters the code wrong
jakejj3 years ago
Disregard my previous comment. The motor won't work. I do however have a micro servo with enough torque. Any tips on writing code so the knock will unlock the door (servo turns 45 degrees) and then a different knock would lock it(servo turns back to original position)? Thanks so much. Fantastic instructable
jakejj3 years ago
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.


Thanks so much :)
Jaslene1003 years ago
how did you figure out the array pattern for the "shave and hair cut" rhythm?
andrewbaker3 years ago
This would be perfect if you had a deaf roommate
Can somebody explain to me about line:
int secretKnock [maximumKnocks] = {50,25,25,50,100,50,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}
this is the initial setup:Shave and a Hair Cut..Is it mean that I can only knock using this type of knock?Then how do I record new knock...
Else,is it really matter if I use any type of program button? I mean NO, NC?
It because my reset button went crazy each time I try to record other knock, it only listen to Shave and a Haircut knock...all the master please help me...
Anybody,can you tell me whether I can use arduino with Atmega8-16PC instead of Atmega328P to do this project.And can I use the program that you (Grathio) gave without change anything.It is because they don't have Atmega Duemilanove.
etlerd3 years ago
I know little of electronics or arduino. I'm fact, this is my first project. I've put it together, substituting a servo for the gear motor, and a speaker for the piezo. It works great. One problem: the servo seems to be generating some sort of feedback which occasionally interferes with knock detection. For instance, if it's just sitting there, an occasional knock is detected, and if you manually twist or bump the servo horn, a few knocks are detected (which is what leads me to think its the servo). If this happens when I'm knocking, it interferes with the detection of a correct knock sequence.

Any suggestions to prevent this? I'd be grateful!
robker3 years ago
how much wold you sell it for
mvillarin3 years ago
i'm from the Philippines and i'm trying to do this project. i try to buy a piezo speaker

and they say to me that the piezo speaker is a transducer. i search for the picture

of a transducer and it is just like a flat thin disc so i decided to buy a 2400 buzzer..

is it ok to use a 2400 buzzer for the speaker?
it's ok to use 2400 buzzer. I've used that on mine. My problem now is with just like butcher_pro problem. It always sense knock eventhough i adjust the threshold to the max. I've tried the connection on different breadboards but still the same problem. Do you any suggestion?
ayanez3 years ago
i cannot download the code :/
groger23 years ago
I can't find a reduction motor here in our place so I decided to buy a servo motor.

The problem is I don't know how will I connect the servo motor to my circuit

because it has 3 wires. I search about the polarity of the servo motor wires and I

saw that the red wire is for power, black for gnd and white for signal. Can anyone

help me how will I connect those 3 wires to the circuit? I use the same circuit that

is posted here in this project.
hello im vanessa from philippines..i am having a mini-thesis today..i really love these sites because it helping me a lot in my thesis..i am doing a light clapper...i want to know the Schematic Diagram of these project...please help me....thanks..:)
butcher_pro3 years ago
Hi people, i have the whole thing up and running, but when i turn the monitor on keeps reading this:
Program start.
knock starting
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
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 :(
butcher_pro3 years ago
Hello, im from Mexico and i loved this project, but im having trouble getting it to work properly. First i want to know if i can use this transistor http://www.datasheetcatalog.org/datasheet/fairchild/KSP2222A.pdf wich is the one im currently using, but i get knock starting, then some knocks then knock stored. But no lights or engine motion whatsoever. I tried switching the threshold up to the maximum but this makes no change at all. i would love some help. i know im doing something wrong, ive doublechecked the resistors and buttons and batterie but everything seems ok to me. Please please some1 help, i know electronics but not very good and i would love to see this arduino project running!!!

Thank u very much! :D
respect...for you
Lorddrake4 years ago
good job. just saw that your knock detector lock was front page on "there i fixed it"


bjarni19954 years ago
Great tutorial, i made a prototype of this but i used a servomotor, i found it really easy to edit the code to work with a servo.

can we use other type of knock rather than Shave and a Hair Cut. Because all video related to this project is using the same type of knock. It's make me a little bit confuse. If we just can program it using that knock so what is the secret means?..really interested in this project but lil bit confused.
I'm printing the template for the secret knock detecting gum ball machine
that you did from makezine!

Where do i find the code?
Grathio (author)  Jordan arduino4 years ago
Read #1 above.

If you're still having trouble after following those instructions post again.
Thanks awesome
im 11 years old and i know how to program the arduino
you make the code really precise and pretty good
the last time i  did a progect i got confused but this is
Hey, I set this as my only lock to my house, and I got robbed! why would you post this?! Just kidding, really cool instructable though!
shishi yat4 years ago
Can we replace the atmel micro-controller with PIC micro-controller? if yes..what type of PIC that suitable to use to make the knock detecting lock project..if no..can you explain me why the PIC cannot be used..your answer are very helpful for me..and i hope i can get the answer..Tank q...:)
Grathio (author)  shishi yat4 years ago
The best way to figure this out is to look at the project, determine what the technical requirements are and then see if you can find a PIC processor that meets them. Some of the technical requirements are:

Looking at the schematic you should be able to get:
- Number of analog and/or digital pins needed.
- Operating voltage.

Other things you'll need that you can get from looking at the code and the data sheet for the Atmel328 processor (the Arduino's main chip) ( http://www.atmel.com/dyn/products/product_card.asp?part_id=4720 )
- Amount of flash ram and sram.
- Amount of EEPROM used (if any)
- Processor speed.
- Special hardware features such as interrupts, timers, PWM, USB, SPI, etc.

After you have all this go through the specs for the various models of PIC microprocessors and see if you can find one that meets or exceeds this. There's a good basic outline here: http://www.best-microcontroller-projects.com/pic-microcontrollers.html

Porting the code will be easiest if you use a C compiler since Arduino code is C.

beehard444 years ago
this was my original project when i bought my arduino uno. Problem is, i need a motor (or a servo) and it'll take me some time beore i go to town (i'm in dunstable)
can the secret knock save to eprom memory?
Grathio (author)  neutron_robot4 years ago
It would be very straight forward to add  with the Arduino EEPROM library. Just make sure you add a way to clear or reset it if you forget the knock.
Putrid4 years ago
What did you use to go from the 9V battery to the 9V in plug on the Arduino? More specifically, what is the connector piece called that you used to go from the +/- of the 9V to the power input?
Grathio (author)  Putrid4 years ago
It's similar to this power adapter from Adafruit.  Alternately you can:

Just use a 9v plug adapter and plug the red wire into the Vin and the black into Gnd on the Arduino.

Make your own with a 2.1mm barrel connector. (I think you can find these at Radio Shack.)  (The 2.1mm is the diameter of the inside plug.)  Be sure to connect the center pin to the positive lead from the battery.
Putrid4 years ago
In step #8, you reference a 220 ohm resistor. I (think) hope you mean a 2.2K ohm resistor.
Grathio (author)  Putrid4 years ago
Fixed! Thanks. (Can't believe after 66,000 views there are still typos that people haven't pointed out!)
noobduino4 years ago
would any of these moters work http://www.thesource.ca/estore/category.aspx?language=en-CA&catalog=Online&category=Motors i am Canadian (no radioshack for me only the source)
Grathio (author)  noobduino4 years ago
Nope, those are all high speed, low torque motors. This project needs low speed, high torque motors.

The motor I link in Step 1 is sold by a Canadian company so shipping costs, etc should be minimal.
jigsawnl4 years ago
I'm just started with my Arduino Uno. This was a great tutorial to learn more about electronics and programming. After setting up the Arduino i thought about how I could improve it with the little bit of knowledge that i had gethered. I removed the two LED's and put a RGB instead. I added Digital 6 to the code. Now standby shows green. A false knock pattern red. And when you press the button to program it's becomes blue.

Thank you for this great instructable.

PS. i had some problems at first. Happens to be that my knock sensor is really hard to trigger. Even with threshold = 1. It's a really small knocksensor encased in plastic.
PyroMonger4 years ago
Could a piezo transducer be used instead of the buzzer - are they pretty much the same thing?
Grathio (author)  PyroMonger4 years ago
Yup, they're essentially the same thing.
Pingman7474 years ago
First off, this is a great project. I could see alot of personal use for this project. As such, I'm in the process of recreating this instructable. In doing so I noticed a line of code I have a question about. I noticed around line 45 in the setup routine you setup the knockSensor pin as an OUTPUT. Is this intentional and I'm just being thick, or is this pin supposed to be an INPUT (what I suspsect)?

Thanks so much for the great project. I'll be watching you for any other great ideas.
Grathio (author)  Pingman7474 years ago
Yes, you are correct.  Good catch!

Fortunately that line doesn't actually -do- anything so it's not super critical.

It looks like I haven't updated the PDE here in several versions. You can get the latest here:

I'll also try to update the coke embedded above, but the Instructables interface doesn't make it easy.
Dr_Stupid4 years ago
Finally SOMEONE posts a really interesting and USEFUL Instructable. +1
Ok, I've got it up and running ! All I need is some cable sorting and I'm ready to show the world! Do you have any of those patches left? :D
Grathio (author)  Crimson-Deity5 years ago
Fantastic! Any chance you can post a photo or (even better) a video?
Ok! Its mearly finished! http://www.youtube.com/watch?v=V6X6jEcNDY8 You can see my current status there ! :D
Grathio (author)  Crimson-Deity5 years ago
I really like your take on it, thanks for sharing!  Your patch is on the way!

(And here's the video embedded for everyone else to see.)
I'll upload a video as soon as I'm completely finished ! I also have to find a Wall to USB adapter since a 9volt wall-adapter makes my green indication light blink for some reason :S
hjuyhgfghjh5 years ago
Can I buy this because im not very good with electronics. im UK based
godgodgodgo5 years ago
How much did this cost to make?
Grathio (author)  godgodgodgo5 years ago
I answered this one below, but since there are a lot of comments to read through I'll answer it again:

It cost me hardly anything since it was all stuff I had lying around. To buy all the parts as listed is around $80 USD. Most of that price is from the Arduino ($30) and the motor (Around $15). You can bring that down if you use an Arduino clone like the Boarduino ($17) or Diavolino ($13)  (But you will need a USB->TTL adapter to program these boards.)

You can also replace the motor with a high torque servo to save a few dollars but you'll have to modify the program and mounting to work with a servo.
Chewie425 years ago
totally awesome...would be great for a secret panel somewhere
Dannne115 years ago
the engine starts when I plug it into the Arduino: ( has anyone any idea what I'm doing wrong?
chestercito5 years ago
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??
B.F.L.M5 years ago
it could be more secure if you use layered security (e.g. RFID, knocking, PIN, iris scanner, fingerprint, AND key!!! (in a specific order of course) ) p.s. im a little paranoid
pls help.. can I use an atmel 8051 micro?? how would the programming be??
nmarbm5 years ago
Where do you draw the sketch, the colorful one (with arduino and protoboard)?
Grathio (author)  nmarbm5 years ago
It was done with the free application Fritzling.


It's super easy to use and can also generate schematics and even make (simple) PCB layouts for manufacturing.
nmarbm Grathio5 years ago
Thank you vey much. And when I am on this page I could say it is a very good project, and I build one yesterday (but only on protoboard) and it works perfectly. And because I am very intrested in arduino, I would like to ask you would you post more new arduino projects?
iceng5 years ago
I used an accelerometer in my e-lock, this responded to drumming fingertips and made it look as if I was bored as I leaned with my back to the secret door while my hand was sending a complex tap code. This works on a car if you include a temperature adjustment for cold weather. iceng...
iceng5 years ago
If you are using the 2N2222 transistor (NPN), the Emitter (arrow) should be the pin wired to ground and the Collector wired to the motor ! It may work backwards as the schematic shows, but with very very poor gain. Change this for a better motor drive. Good Luck... iceng...
wout smeets5 years ago
 how do you make an h-bridge for this doorlocker

i come from belgian srry for my bad inglish you can anser me on woutsmeet1997@hotmail.com
Grathio (author)  wout smeets5 years ago
 There are a number good Instructables on the site for making H-Bridges, just click here.  (Or type "h-bridge" in the search box in the upper right, which is what I did.)

Of those I think this one might be the most helpful since it also mentions how to program the Arduino to use it.
 i have my arduino today

Storming idea, but i don't know what happen when AC power cutting which usually done in my country?
juanvi5 years ago
woha! very nice and clever!! i really like it, but have you ever used it in real life? as going out without keys and returning 5 hours later and be opened by it?? how much does the battery last??
Very nice. I thought that it was for opening any doors. Even though, Very clever invention!!!
alcurb5 years ago
Very clever invention. For increased security, may I suggest to add a touch sensor option connected to door handle/knob. Lightly tap your code on the door handle/knob. The neighbors won't be able to hear that.
godgodgodgo5 years ago
Do I need a power supply for the Arduino Duemilanove and the circuit board?
Grathio (author)  godgodgodgo5 years ago
Reread the 'Materials' section carefully and you can see my recommendations for powering the project.
godgodgodgo5 years ago
Why when you etched the board out did you not just leave a long line of the copper instead of the wires for the power. Also should you not have done it so that some of the holes are linked?
Grathio (author)  godgodgodgo5 years ago
The board is a perfboard, not a custom etched board.  Follow the link in the 'Materials' section to see what I'm talking about.
Could this be modified to work with music. For example, tones played in a certain order unlocks the lock?
Grathio (author)  nitetime30215 years ago
Unfortunately recognizing tones is a different task from rhythm.  The piezo element would need to be replaced with a microphone and amplifier.  The code would need some excellent noise removal and pitch recognition, probably some kind of FFT,  which is difficult (though not impossible!) to do on the Arduino's limited hardware.

By the time you do all that it would essentially be a different project.  A very cool project, but a different one.
Robot Lover5 years ago
When I download the file and open it in the arduino sandbox it says "Bad file: Processing can only open sketches and other files ending in .pde" Help anyone?
Grathio (author)  Robot Lover5 years ago
 Sometimes the file that Instrucatables gives you is a different file name.  Just rename it to secret_knock_detector.pde and it should work fine.

I already did but it still does not work. Any suggestions?
Grathio (author)  Robot Lover5 years ago
 Hm.  I'm guessing some computer somewhere is messing with the encoding.

You can also download it directly from my site here.  If both of those links don't work for you try a different web browser to download the files.
louwhopley5 years ago
Great project!
Haven't read the instructable, but the video looks really good!
eng.7oka5 years ago
Ok..I Think I will use C ... I'm looking for C compiler for my PIC now... Thanks again
eng.7oka5 years ago
Thanks alot man.. it's really useful.. I have a small problem though. I'm using PIC 18F series. How can I modify the program
Grathio (author)  eng.7oka5 years ago
 The Arduino uses an Atmel chip which is functionally pretty similar to the PIC 18F series.  However they speak pretty different languages.

The code I provided would require some kind of conversion.  If you're programming the PIC in C the conversion should be pretty straight forward since the Arduino code is mostly straight C.  If you're using Assembly or some other language you'll have to port the whole thing over.  How hard that is depends on the language and how good you are with it.  I've commented my code pretty well.  You might find the Arduino reference manual useful for seeing what specific instructions do (like timing and reading/writing pins). 
eng.7oka5 years ago
I need to test the piezo without the microcontroller connected.. any idea how to do that?

Grathio (author)  eng.7oka5 years ago
 If you have a particularly nice multimeter you might be able to use that, (Set it to 2v)  though often the sampling is too slow to register.

I simply made a quick sketch that continuously read the values coming from that pin and dumped them to the serial port.  It's not too different from this or this Arduino tutorial.  (Looks like you're using PIC, so you'll have to port or modify the code.)
ratgod5 years ago
I love the "Scream while knocking" solution.
jmn19935 years ago
This is prity cool..
Just 1 thing, were can some 1 get an arduino??
Grathio (author)  jmn19935 years ago
 It depends where someone is in the world. There is a list of suppliers here.
jmn1993 Grathio5 years ago
cheers heeps .
luishfialho5 years ago
 oh, i've already seen it in the instructions x) my bad, sry
luishfialho5 years ago
 hi, great job! where do you get the white piece? (or something similar) thanks!
mdawg225 years ago
thats pretty sick man... cool...
jasper_muc5 years ago
 Hey guys,
Does anybody know how a sleep mode could be implemented? I assume that could boost the battery life tremendously.

Thank you,
first, i'd like to say this is one of the coolest arduino builds i've ever seen. truly inspired!
my first thought for power saving was a magnetic on/off switch so that, in addition to knowing the correct knock, you would also need a "key" (a relatively strong magnet) and know where to put it.  of course this would probably require the opener to be a permanent installation and might detract from some of the novelty.  but in a secret door application (which would make this already awesome device even more awesome) the more security the better.
Grathio (author)  tinkerist5 years ago
That's a great idea!  It would certainly be one way to implement a sort of two factor authentication (something you have + something you know) for a truly secret entrance.   A rare earth magnet in a piece of jewelry and a reed switch just might make a winning combination. 
is an arduino complex enough to operate in tandem with an RFID set-up, so that an individual has an exclusive knock associated with their RFID? or would that require multiple controllers or connection to a server of some kind?
Grathio (author)  tinkerist5 years ago
Most RFID readers are very trivial to hook to a microcontroller, they simply spit out the RFID tag's ID through a serial connection, so you could very easily use one as a second form of authentication.
"magic" ring + secret knock + hidden door = awesomeE9
there are other options too.  you could have an external power supply that connects to stealth contacts on the outside of the door.  or a candle stick/fake book on/off switch, al a old horror flicks.

the possibilities are endless, i'm going to be geekin' on this for a while, i think.  :)
Grathio (author)  jasper_muc5 years ago
 I'm still experimenting with this. So far it looks like you can use voltage produced from a knock on the piezo to trigger a wake from sleep... sometimes.  And it then takes a bit to wake fully.  To use it you have to knock once loudly, wait for it to wake up (if it did), and then do your secret knock, which kind of makes it hard and cranky to use.  My goal is to make it to wake reliably and within 0.1 sec so the usage is the same if it's asleep or not.

I'm going to keep looking into it though.  There are a few other power saving ideas:
  • Underclock it.  I'm not sure how low you can go, but I'd be surprised if it wont run at 4mhz or even 2.
  • Use a LillyPad Ardunio (ATmega168), which should* use less power, since it uses the internal resonator and doesn't have to drive a serial buss.  (It also likely pulls less power since it runs at 8mhz.)
  • Power down the pins and subsystems not used. 

*I haven't looked up the specs to see if it actually uses less power, I'm just assuming it does.

The voltage regulator on the Arduino board likely takes as much or more power than the Arduino itself just idling. You'll need a better power supply. 
 nice work
matej4445 years ago
hi, i have something really stupid question, I dont know where I must connect my battery on arduino. if someone can tell me where I connect this?
And I have litle problem my LEDs always blinking and I dont know where is problem, maybe that write somewhere in comments, but I dont have to much time to reading, and Im not good in english
Grathio (author)  matej4445 years ago
Next to the analog pins there is a pin lableed "GND" that's where the ground (-) goes.  Next to it is "Vin" which stands for "Voltage in"  That's where (+) goes.

You can put anywhere between 7-12 volts into it via those connections.

You can also use a 2.1mm plug connected to a battery pack and plug it into the power jack on the board that's below the USB connection.

More info is here.

robbotica5 years ago
great project ,) 
maybe i would add a feature that unlock all the system when the battery is low.
grahamdube5 years ago
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.
Grathio (author)  grahamdube5 years ago
 Thats a good innovation.

Depending on the requirements, an easy way to provide more voltage to the motor is to connect the motor (+) to the raw power in pin on the Arduino (or straight to the battery). But check the ratings on your transistor to be sure you're not going to overload it with the motor.
EnigmaMax5 years ago
This is a great project, but I did mine a bit different. I drilled a hole in my door and used a infrared LED instead of the peizo. I then programmed a (hacked) NES zapper to the "knock" sequence to flash its led to it. The door opens metroid style.
Grathio (author)  EnigmaMax5 years ago
 Ha!  That's fantastic!  The NES zapper is an inspired touch.
thanks. again, this is a great project.
Grathio (author)  EnigmaMax5 years ago
 Any chance you can post some photos?  It sounds awesome!
sorry, I don't have a camera, but it looks exactly as it sounds.
Grathio (author)  EnigmaMax5 years ago
That's no problem.  Thanks for sharing!
jasper_muc5 years ago
 Hey guys,
I had already everything working as can be seen here:

However I had to take everything apart for storing issues. Now that I have actually built a mount and want to get going it doesn't work anymore.
The problem is that every time I set it up, the LED connected to pin 5 blinks like crazy (if i try to knock after a short period, the other led does really quick the three blinks (doesn't matter if the knock is right or not) and then the other led blinks crazy again.

Did anybody encounter similar problems?
Anybody suggestions how I could find out what's wrong?
I loaded the blink sketch on the board so that I could test if my arduino board pins are broken but everything worked fine. So I guessed is a software issue but since it has been working before that cannot be either...

I would be very thankful for help,
Grathio (author)  jasper_muc5 years ago
If the pin 5 LED is blinking like crazy its because it's getting garbage data from the piezo.  Some things you might try:
  • Around line 28 there's a value for "threshold" set at a default of 4. Raise that to 10 or 50 or 100 (or 500) and see if it stops. If it does, reduce the value to just above the noise threshold.
  • If that doesn't work you might have a short somewhere in your piezo. Check all of the connections.
  • Another way to test the hardware is to go do this really simple tutorial.  If you can't get that to work, it won't work on the lock.
  • Try another pin for the piezo.  And change the definition of "knockSensor" on line 21 to match.  The ADC on the ATMegas aren't that great, so trying another pin might reduce the noise.
Good luck.
Grathio (author)  Grathio5 years ago
I just discovered another thing that might help.  If you have a noisy power supply it can cause the same thing. Putting a couple of 0.1uF capacitors between + and - really smoothed things out and let me drop the sensitivity from 100 down to 2.
XOIIO5 years ago
Is it me or does he not look a bit like Sheldon from The Big Bang Theory?
Grathio (author)  XOIIO5 years ago
I always thought it was the other way around.
jestrada95 years ago
This is an awesome instructible.  I've almost completed mine, just need to mount the spring for the piezo, mount the motor & put the lock turning clamp on.  I'm definitely a beginner but was able to make this because of all of the detailed instructions.  Now I just need to learn how to read wiring diagrams and build a playhouse for my kids so I can mount this to their door.
Grathio (author)  jestrada95 years ago
Thanks for sharing the progress!  A playhouse is the prefect place for it.
amr90005 years ago
 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..
Grathio (author)  amr90005 years ago
(I'm going to assume that your motor is rated to run at 5v, will work correctly when you apply power directly.)

This is a good time to use your multimeter and see what kind of current you're getting through the motor.

This can happen if your diode is in the wrong way.  Check the polarity of the diode.  Probably wouldn't hurt to check the transistor's pins as well. Don't just mount it by looking at the shape, check the spec sheet and be sure that the pins are going to the right places.

amr9000 Grathio5 years ago
 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?
gp1200r5 years ago

On the third picture on this page, with the breadboard layout diagram, the parts list on it says PNP transistor, which I'm thinking is incorrect.  The similar-looking diagram in step 3 has it fixed, though...  Not a huge deal, but it's something you might want to fix.  Thanks a lot for this Instructable, it's great.

Grathio (author)  gp1200r5 years ago
 Thanks for catching that!  Fixed.

(The diagram on Page 3 was the corrected one, the one on page 1 had a few small errors on it.)
amr90005 years ago
 okay.. I don't know what I'm doing wrong, I got in a Huge woop about this, spent 80 dollars or more on parts.. and once I got to the wiring part.. it just went downhill;
for one thing, the wiring doesn't seem to make any sense, thought it was just me but then I had an engineer sit down and look at it and neither the digital nor the live picture of the wiring scheme makes sense.
the program you posted seems to have a glitch;
it starts the program, then first knock, then one Right after another till it hits it's limit and says new lock stored.. and considering while it does this it is hooked to Nothing but the USB that seems a bit impossible to be actually happening.
until I set the sensitivity to 1023, it doesn't see Anything at 1024, but at 1023 when I touch the wire of the piezo, or any wire for that matter, it see's a knock..
have I gone completely crazy? I've worked with plenty of this stuff before.. so I guess maybe this is just new to me........................................................................?
really not sure considering I'm not sure considering how this circuit seems impossible yet so many people seem to have gotten it fine..
if anyone has Any advice to get this thing on it's way so I Haven't wasted 80-100$, Please give it
KnexFreek5 years ago
gp1200r5 years ago
 I'm planning on implementing a project like this one after I get my Arduino for Christmas, and one of the biggest challenges for me will be mounting the whole device.  This will be going into a dorm room, so I can't modify the door, drill holes, or anything like that.  So as for this, I am planning on using a whole lot of 3M commandstrips.

For the motor shaft/deadbolt interface, one thing that caught my attention as a possibility is aluminum C-channel.  It would work by the same principle of the sheetmetal approach you used, slipping over the deadbolt.  The attachment of the aluminum to the shaft might end up being difficult, though, which could negate the benefit of not having to bend sheetmetal.

Another option might be to fix a piece of aluminum c channel to the deadbolt with some extra off one side, making it something like the equivalent of a servo horn, and using a servo to control it.

If anyone else has a brilliant idea for this particular step of the project, I'd love to hear it.
Grathio (author)  gp1200r5 years ago
 A servo with an appropriate horn is a much better idea than what I've done here.  It's easier to attach to the lock and is easy to make it lock as well as unlock .  The primary reason I didn't use one is that I didn't have one on hand that was powerful enough to turn the lock.

The 3M command strips should work.  If they don't, 3M's extra strength double sided foam tape definitely will, though more permanently .  (Back in my dorm days we stuck a chair to the ceiling with it...)

chase0445 years ago
heres an idea idk if you have thought about. but how bout making one like this but instead of knocking, putting a momentary switch on the door that you could put the same type of code into. you would have to press the button with the same timed rythem as knocking. this would make it more secure than knocking your code like you said since even is someone is watching you press the button it would be hard to tell the exact code you used.
Grathio (author)  chase0445 years ago
I think that would be great.  Connect to to a doorbell switch on the outside of the door and no one would know!  (Though they'd wonder why the doorbell doesn't work...)
robotkid2495 years ago
 This is sweet, fantastic build!!
BSprague5 years ago
 Thanks for this fantastic guide, I just modified it so that I have a laser activated door lock, which works by breaking the beam to a set rhythm. It works fantastically, and people can't figure it out simply by hearing it. ;)
Grathio (author)  BSprague5 years ago
 That's a great idea!  I'd love to see a photo or video of it  in action.
 My camera is broken, but I'm picking up a new one in a couple weeks hopefully. I'll definitely record it doing it's thing and I'll send you a link.
kicker1095 years ago
this is the single most brilliant device i have ever seen
amr90005 years ago
Shut The Front Door!!
Alright, I'm seriously planning on building one of these. I think the main course is under the tree ;D
Also I see two other opportunities for this
1, ever lock your keys in your car?? either something that moves the thumb lock itself (would be easier on older cars) or something that actually installs inside the door on whichever cable 0.o
2, okay, little out there, but I'm picturing one of those rooms where the bookcase is the door. Or you know, something similar :P
wearingpink5 years ago
awesome idea and well done! it would be good for a bedroom door, especially in a college house. Too bad I don't know anything about building electronics.
MJDOG85 years ago
This is a great idea and i think i will try to make one
photis225 years ago
 Simply wonderful, I love it and would love to make it.
 I think this might also be a really interesting thing to put on the inside of a desk if you had a somewhat smaller version, that might unlock it aswell.
This has to be one of the "coolest" ibles I've seen!  I am totally going to have to try this sometime!  Now if only I can figure out how to make my sliding/pocket door open automatically, and incorporate that and the knock-lock together....
Yea.. definitely the coolest thing Ive ever seen
astro boy5 years ago
 man this is awesome ive just been thinking and im going a bit far like at first it was like position sensitive, then it turned into wouldn't it be cool if a drum kit came up and you played a beet or a guitar or even thinking to open it! way to futuristic but you never know. i think touch sensitive, position sensitive and time sensitive would be great
boltfox205 years ago
 There is one method for fixing the security problem. Instead of holding th button and knocking on the door, you could also hold the button until it enters the programing mode, push the button to the beat of the knock, then hold the button again to set that knock. That way no one would hear the new knock until after you need to use it.

Otherwise, this is a great idea, and would certainly be a good gift for a child if they have a "secret" club. Otherwise, this is also a great alternative to picking your lock when you lose your keys.
zebaron5 years ago
 I'm thinking of making one of these and moding it to open a desk draw.  What kind of motor would be best, some kind of mini hydraulic cylinder?  
Grathio (author)  zebaron5 years ago
Hydraulics are complicated and probably overkill for this. Depending on the design of your desk here are the ways that come to mind:

1) Rack and pinion.  Lego parts might come in handy.  Attach the rack part to the drawer, motor with the matching gear to the inside of the desk.

2) Spring load the drawer (put a compression spring or two behind it) and latch it closed with a solenoid.  When the solenoid withdraws the drawer springs open.
zebaron Grathio5 years ago
 Thanks a lot, I think I'll try going with the rack and pinion.
I've used power antennas for cars to actuate the drawers that my amps were in back in my high school days.
themonorail5 years ago
 about how much did this cost to make. by the way i think this is one of the coolest things i've ever seen.
Grathio (author)  themonorail5 years ago
 For me it didn't cost anything because I had this stuff lying around the lab.  To buy everything is probably less than $80.  The two most expensive items are the Arduino (about $30) and the motor (about $15).

(These prices are for the USA)
 You should call it your "Nerd Cave", like I do.
cacaloz5 years ago
very cool!. I like it very much. it very good idea.
What is electric board to use. Is it microcontroler or you make in yourself?
( blue board )
Absolutely first class!!  Would there be a way to voice-activate this device instead of the secret knock?
vr3605 years ago
 that was amazing!! congratulations!! :)
elmegil5 years ago
This is very cool.

I saw someone (an electrical engineer) do this for the lock on his Corvette, about 20 years ago....beatiful work, completely hidden, and no external lock on the car.

Not entirely sure how he would deal with a failure in the system, though I suppose he probably had a jimmy bar.
Alchymist5 years ago
I can see this being amazing for kids, bedrooms and tree houses etc. I wouldn't put it on my front door but the desire is still there :P
insanely cool one question though ... does it work with any sound like say a music clip from your phone? so if you put your phone next to the door and played the music clip it will open? because if thats possible then a person could create a "key" device that sends vibrations of a music clip to this lock opening mechanism .
Grathio (author)  computer_nerd5 years ago
 That is a very cool idea, but it won't work with this design.  The sensor pretty  much only senses big vibrations (like knocking) and not small vibration like sound.  The code would also need to be dramatically rewritten to account for arbitrary sounds rather than discreet timing between knocks.

Great idea though!
yea thanks for the quick reply and this item even though it may or may not have a solid consumer base its kool as mess!
erosser5 years ago
 This is Uber-brilliant!  Admittedly a little too advanced for me, but I shall attempt one after I play with some more microcontrollers.

Nice work!  The end product is very sleek and elegantly arranged.  Plus, an AWESOME idea!
revelae5 years ago
is the arduino capable of pitch recognition? cus i have an idea, theoretically the pitch of a knock should change with the location of the knock on the door, so if you recorded a single knock's pitch and then used that instead of a pattern, you could use that.
also, to the random observer it would seem like an ordinary knock.
JohnJY5 years ago
Very nice, extremely detailed!  Uses real English, not that LOL crap, and you even did something I haven't seen before, and I don't make things, the only thing I've done since I've been joined for a year is view Instructables, and I've never, never(!) seen anyone say what skills you'd need to make the Instructable.
How long does this type of quality take to create? 
Seven stars out of five!
Grathio (author)  JohnJY5 years ago

I think the skills are just as important as the tools and parts.  Nothing worse than getting into a project and finding out that you're in over your head.

As for how long it took...  I'm a bit of a perfectionist so it takes me quite a while.  When I made the original one I had no intention of making a DIY (or even a kit) so I had to make another one just to document it. That probably took 3 hours.  Plus taking photographs, I took a total of 127 photos.  Didn't use them all, but did Photoshop the best ones so they're clear as possible.  That's several more hours.  Writing and proofreading probably another 6=8 hours (or more).

So it's no small task, but people loved the idea so much that it seemed worth it to share.

But it depends on the 'ible.  For example my Make a glove work with an iPhone DIY took 90 minutes at most.
Spydamonky5 years ago
 I cant down load the code. it downloads as a tmp. could you post it please
Grathio (author)  Spydamonky5 years ago
 Just rename the .tmp file to .pde and you're good to go!
This would be perfect to permanently mount to a secret door, one that was flush in the wall. No outer lock, with a battery backup and constant power... You'd have to add the lock function though.. Would be fantastic for that secret lair I've always wanted.. And I know what you thinking, oh noes what if the power is out long enough for the battery to die.. Well, first off I was thinking computer battery backup, like a cheap one, should last a real long time, but on the off chance it did, I suppose you'd have to install some sort of batter life meter, and have a failsafe that unlocks it before it dies..

Only one problem, where can I put a secret door in my house.... Hmm...
Looks like it's time to start building that extension to the house... another cool thing would be like a container of some sort with a solenoid to open it up. Like a table or desk that just looks solid  w/ a built in power bar... plug the power bar in and presto the arduino is active and ready for your knocking.
Of course with this you would also want to hold the lock/unlock start in a variable so you could knock lock the thing as well. Perhaps I'll edit the code and maybe add a sensor to tell the script whether or not the door is locked so it can lock for me too...

On another note I am in the process of making a physical computing Club here at my college and we are going to be making some of these as one of our first projects. There are 10 of us in the club and it looks like we'll be getting approved for recognized status. Thanks to Grathio for making this open source and coming up with such a cool Idea. On a final note, i'd like to complement you on your elegant code Grathio It took me a few minutes to see how it was working but once I grasped the concept I thought that I would never be able to come up with that. It looks as if it could be used for a slew of other things as well.

Shazzam.tky5 years ago
Way too kewl man!
goeon5 years ago
 awesome ible btw step 6 image one it says "a food of leads attached"
Grathio (author)  goeon5 years ago
Thanks for catching that!  Fixed it.

(I'd give out patches for finding spelling errors in my 'bles, but I'd run out of them in about a minute.)
tahirhh5 years ago
You look like Jimmy Carr
ljfa3215 years ago
Put it simple, "Best Instructable Ever".
I can't believe you even describe the code for us :D~
Mooncaller5 years ago
 This is the coolest thing I ever seen!!! :D Good job!!!
lucek5 years ago
neat device now change out that typical door and lock for a hidden passage and your golden.
dark sponge5 years ago
 Nice! I might try this with a ATtiny and a servo I have from an old robot!
h3llo415 years ago
 so awesome, i really wish i knew a little more about tech so i can make one.
You really should sell these, i would buy it :D 
ClayChip5 years ago
This is just plain AWESOME! I do not know how to use Arduino, but this instructables makes me want to learn it.  5 stars from me.
Kaiven5 years ago
No way! My friend gave me a link to this video a while ago, it's such a cool device!
Joe426 Kaiven5 years ago
Featured on HacknMod a while back : http://hacknmod.com/hack/secret-knock-detecting-arduino-door-lock/
Get your patent on this one PDQ. This is a hell of a security device, no lock to pick or keys to lose.
That is the coolest thing ive ever seen!!! i dont have the time,money or skills needed but i really want one!!! 5 stars faved and subscribed!!!
crapflinger5 years ago
this is the bees knees! (and 23 skidoo and what not)...i really like the idea of putting a knock-back-device on it as well to do a challenge knock...you could do some massive annoyance with that (make a 6 level authentication profile where you have to knock, then it knocks back, and you have to knock, then it knocks back etc...)

another "modification" could be to use an actuall electric deadbolt (or something as simple as a really beefy solenoid) in place of the current deadbolt, so you wouldn't have to muck with lock turning mechanism....just tie into the existing contacts on the electrick lock and you're good to go...

or make it a "star trek" door....put some form of actuator...so once you authenticate and the door unlocks, it also opens the door for you...this would be made even more awesome if you've got pocket doors....it could even play the star trek "door open woosh" noise