Home Creators Posts Import Register Favorites Logout

Content

This is a video tutorial requested by one of my lovely Patrons, which explains how to create a "knock, knock" ER puzzle, in which players need to tap out a particular rhythm (such as a secret doorknock) to activate a relay and unlock a maglock. 

I've demonstrated two different variations of the puzzle - one uses a Piezo sensor (activated by vibration) as an input, and this would work well for knocks on a solid surface such as a door, wall, or table. The second version uses a microphone input instead, which can be used to detect *any* percussive noise. That gives more flexibliity as to how players can solve the puzzle, but you'll also need to exercise some caution to make sure that it doesn't get set off accidentally by other sounds banging around! 

In both cases, the input knock pattern is normalised before comparison, which means that the correct input will always be accepted whatever tempo it is entered at. I've included some automatic calibration code which will adjust for the ambient noise level in the room, an input sensitivity adjustment, and also a variable error threshold that allows you to change the tolerance of incorrect timing.

I've tried to document the wiring diagram and code as thoroughly as I can, but please do ask if you have any questions! Links to download all the associated resources will be put up for $10 patrons shortly. 

Files

"Knock, Knock!" Arduino Escape Room Puzzle

This is a video tutorial explaining how to create a "knock, knock" puzzle as seen in some escape rooms, in which players need to tap out a particular rhythm (such as a secret doorknock), to activate a relay and unlock a maglock. Two versions are demonstrated - one using a Piezo sensor which is activated by vibration, and one using a microphone input which can detect any percussive sound. The secret knock pattern required to solve the puzzle can be set to any rhythm you want, and the player's input is normalised before comparison to make it tempo-independent. There are also configurable settings for input sensitivity and error tolerance. To download the Arduino code, wiring diagram, and list of components used in this video or any of my other tutorials, please see my Patreon at https://www.patreon.com/playfultech/posts - thanks!

Comments

Reid

We have a large wood xylophone in our space and I am soooooo curious if it could work with the microphone version of this!

Reid

Like an analog version of your 'play it once' midi keyboard puzzle

Valentin Chalan

Hi Alastair ! Your Knock Knock code works very well, i'm allways surprised of what electronic can do ! By knocking on a door, we can open it at the same time. It's crazy... I love it ! But (cause there's allways a "but") i meet troubles with using it without serial monitor opened. 3 examples : - My arduini is connected to my PC, with IDE and Serial Monitor opened => it works -My Arduino is connected to my PC, with IDE opened but Serial Monitor closed => doesn't works. -My Arduino isn't connected to my PC (but powered by an external 12v dc source) => doesn't works. How is it possible ? It's like Arduino needs Serial Monitor display to understand the code... Do you know how i can fix it ?

Nick San Souci

Excuse me for hitting enter in my excitement and sending you a "Hi there Alastair!" greeting without the rest of the message.

Nick San Souci

Oops, I did it again! So here's my question: When I try to upload the Knock, Knock code it is coming back with this message: An error occurred while uploading the sketch. There appears to be a whole bevy of said errors, none of which I am competent enough to fix on my own. Do you think it is something as simple as having the wrong version of Arduino IDE on my computer? I downloaded the latest version 1.8.9, but did you write the code in an earlier version perhaps? Thanks for your help!

Alastair Aitchison

Generally speaking, older code will normally run on newer versions of the IDE (though not always the other way around). Please post the full error message here and I'll take a look what it means.

Nick San Souci

Sorry for the delay in getting back to you, Alastair, and thanks for the prompt reply. I'm new to this Arduino thing so forgive me if my error is a laughable rookie mistake! Here's the error message in total (I apologize, it's quite a lot!): C:\Users\Bilbo\AppData\Local\Temp\Temp1_KnockKnock_Resources.zip\KnockKnock\KnockKnock.ino: In function 'void setup()': C:\Users\Bilbo\AppData\Local\Temp\Temp1_KnockKnock_Resources.zip\KnockKnock\KnockKnock.ino:93:47: warning: invalid conversion from 'const int*' to 'int*' [-fpermissive] playbackKnockPattern(secretKnockPattern, 500); ^ C:\Users\Bilbo\AppData\Local\Temp\Temp1_KnockKnock_Resources.zip\KnockKnock\KnockKnock.ino:385:6: note: initializing argument 1 of 'void playbackKnockPattern(int*, int)' void playbackKnockPattern(int knockPattern[], int maxKnockInterval){ ^ C:\Users\Bilbo\AppData\Local\Temp\Temp1_KnockKnock_Resources.zip\KnockKnock\KnockKnock.ino: In function 'void loop()': C:\Users\Bilbo\AppData\Local\Temp\Temp1_KnockKnock_Resources.zip\KnockKnock\KnockKnock.ino:157:38: warning: invalid conversion from 'const int*' to 'int*' [-fpermissive] printPattern(secretKnockPattern); ^ C:\Users\Bilbo\AppData\Local\Temp\Temp1_KnockKnock_Resources.zip\KnockKnock\KnockKnock.ino:412:6: note: initializing argument 1 of 'void printPattern(int*)' void printPattern(int pattern[]){ ^ C:\Users\Bilbo\AppData\Local\Temp\Temp1_KnockKnock_Resources.zip\KnockKnock\KnockKnock.ino:161:55: warning: invalid conversion from 'const int*' to 'int*' [-fpermissive] if(comparePattern(inputPattern, secretKnockPattern)){ ^ C:\Users\Bilbo\AppData\Local\Temp\Temp1_KnockKnock_Resources.zip\KnockKnock\KnockKnock.ino:305:6: note: initializing argument 2 of 'bool comparePattern(int*, int*)' bool comparePattern(int inputPattern[], int secretKnockPattern[]) { ^ Sketch uses 7548 bytes (23%) of program storage space. Maximum is 32256 bytes. Global variables use 257 bytes (12%) of dynamic memory, leaving 1791 bytes for local variables. Maximum is 2048 bytes. C:\Users\Bilbo\AppData\Local\Temp\Temp1_KnockKnock_Resources.zip\KnockKnock\KnockKnock.ino: In function 'void setup()': C:\Users\Bilbo\AppData\Local\Temp\Temp1_KnockKnock_Resources.zip\KnockKnock\KnockKnock.ino:93:47: warning: invalid conversion from 'const int*' to 'int*' [-fpermissive] playbackKnockPattern(secretKnockPattern, 500); ^ C:\Users\Bilbo\AppData\Local\Temp\Temp1_KnockKnock_Resources.zip\KnockKnock\KnockKnock.ino:385:6: note: initializing argument 1 of 'void playbackKnockPattern(int*, int)' void playbackKnockPattern(int knockPattern[], int maxKnockInterval){ ^ C:\Users\Bilbo\AppData\Local\Temp\Temp1_KnockKnock_Resources.zip\KnockKnock\KnockKnock.ino: In function 'void loop()': C:\Users\Bilbo\AppData\Local\Temp\Temp1_KnockKnock_Resources.zip\KnockKnock\KnockKnock.ino:157:38: warning: invalid conversion from 'const int*' to 'int*' [-fpermissive] printPattern(secretKnockPattern); ^ C:\Users\Bilbo\AppData\Local\Temp\Temp1_KnockKnock_Resources.zip\KnockKnock\KnockKnock.ino:412:6: note: initializing argument 1 of 'void printPattern(int*)' void printPattern(int pattern[]){ ^ C:\Users\Bilbo\AppData\Local\Temp\Temp1_KnockKnock_Resources.zip\KnockKnock\KnockKnock.ino:161:55: warning: invalid conversion from 'const int*' to 'int*' [-fpermissive] if(comparePattern(inputPattern, secretKnockPattern)){ ^ C:\Users\Bilbo\AppData\Local\Temp\Temp1_KnockKnock_Resources.zip\KnockKnock\KnockKnock.ino:305:6: note: initializing argument 2 of 'bool comparePattern(int*, int*)' bool comparePattern(int inputPattern[], int secretKnockPattern[]) { ^ Sketch uses 7548 bytes (23%) of program storage space. Maximum is 32256 bytes. Global variables use 257 bytes (12%) of dynamic memory, leaving 1791 bytes for local variables. Maximum is 2048 bytes. avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x30 avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x20 avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x30 avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x20 avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x30 avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x20 avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x30 avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x20 avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x30 avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x20 An error occurred while uploading the sketch

Nick San Souci

Very helpful advice, Alastair, thank you! Turns out I had the correct arduino selected (the Uno) but the wrong COM port. However, is there something else I have to do before this will work? The code successfully uploaded to my Arduino but I have tried and tried each knocking pattern but no luck in getting the maglock to pop. Sorry to be a pain. I appreciate your help and feedback immensely!

Nick San Souci

*Entering Setup Setting Pin Modes Playing back knock pattern Initialising lock Calibrating sensor Sensor base reading: 30.10 Setup complete

Nick San Souci

When I knock nothing happens on the serial monitor, so what does that mean?

Nick San Souci

So it turns out the issue was that I didn't have the sensitivity for the microphone dialed up high enough so the sensor wasn't picking anything up. Once I turned that up, it worked like a charm! Thanks for all your help Alastair! I can't wait to implement a version of this in my upcoming escape room!

Johnny Tyler

Hello! I am on the "Inventor" tier for you here on Patreon but I cannot seem to locate the wiring diagrams or code for this puzzle. Can you point me in the right direction please? Thanks a lot!

Rafy Riquelme

I'm having difficulty finding a 165Ω resistor for the buzzer. Would a 150Ω do the job? Ohms Law says it would be 30mA.

Tom Amon

Will your knock knock code run on a nano or micro? I assume I may have to change a couple pins.

elad sinay

hi. i signed up but not sure how go forward and get the code

David J Sebek

if(comparePattern(inputPattern, secretKnockPattern)){ When I copy and pasted the code into arduino I received an invalid conversion from const int to int* (-fpermissive) for this line of code while I was compiling

MUBAAH ABDULLA .

how to normalize any given melody? i cannot get my maglock to unlock :(

Tom Amon

When the puzzle is solved the buzzer plays continuously until the reset button is pressed. Is this how it was designed, or is this a bug?

Maciej Jander

Hey Alastair! In fact, everything goes without a problem. I connected the whole kit, uploaded the code to Arudino, but the lock remains open. Only after I play the appropriate combination, the relay is activated (the red diode lights up) and the lock closes. As if something was the other way around. Any idea what might be wrong?

Joe Square

Hi, Alastair, I'd like to set this up WITHOUT the feedback items (buzzer and LED). As you can imagine, this would probably be a much different code to omit all those lines. Would you happen to have Arduino code that omits those two items?