Introduction: Knock Box (it Opens When You Knock on It!)
Hi! This is my first Instructable. Let's start!
The idea was to create a box that opens if you knock on it with the correct rhythm. It may not be so useful, but it is a great chance to learn further Arduino and create something awesome, having the right to say: "I made it!".
Above you can see some sketches I made to figure out how the box will look. However, don't take the layout too seriously: in the final version it is different. But they are still useful to understand the "user interface".
Analyze the main image.
First of all, the switch (1): there is no much to say.
Secondly, three LEDs: when turned on, the red one (2) means that the box is locked. As you can easily imagine, the green one (3) means it is open. The last, blue LED turn on when the user knocks on the box. In this way, he/she knows if the box detected the input or not.
Then, the box provides three buttons. The first one (6) closes the box, the second one (7) plays the rhythm saved, and the third one (8) record a new rhythm.
Warning: due to technical reason, if you record a new rhythm it stays until you turn the box off. However, you can easily fix that saving the rhythm in the Arduino EEPROM (reference).
In the next step, I will show you how to realize the electrical circuit.
Step 1: Circuit and Code
Let's do it!
Things we need:
- a piezo element;
- a servo motor;
- a 100uF capacitor;
- three LEDs (red, green, blue);
- three push buttons;
- three 220Ω resistors, three 10kΩ resistors and one 1MΩ resistor.
You can find everything in the Arduino Starter Kit.
The circuit
Recreate the electrical circuit. The scheme is the one in the main image.
I have insterted also some pictures of the completed circuit.
Code
You can download the code from here.
Step 2: Finally, the Box!
It's time to create the physical box. Take one big enough to contain Arduino (or the chip, if you want to create a stand alone) and the other components. I bought a wood one for about €2.50.
Pay attention: the box's lid must not be totally straight, but it needs a vertical component, as mine does. The animated gif shows how the locking system works.
Make three holes for LEDs, three for push buttons and one for the switch. See the pictures.
Now, make another hole on the, and then smooth the area next to it inside the box, so the servo's flap has enough space to move. The servo motor will move in there and prevent the box from opening.
While making holes, try to be more precise than me. It was the first time I had a drill in my hands.
Finally, insert Arduino (or chip) and components inside the box. Fix the piezo sensor at the centre of the lid and the servo motor in correspondence of the last hole.
Congratulations, your KnockBox is ready to take care of your secrets!

Participated in the
Arduino Contest
24 Comments
6 years ago
Hello sir, ive made your project and it was working well. But i only have one problem, every time i pressed the button to register new pattern, it automatically knocks by itself. It knocks 10 times straight. Hoping for your fast reply! :) Thankyou.
6 years ago
Sir how is the position of the servo in the box, so that it can open? And what if i only have a piezo sensor, how can i add a buzzer? Many thanks for your reply :)
Reply 6 years ago
Hi! For the piezo, it is just fine, you can use the sensor as a buzzer too. I glued the servo in the box, and a piece of metal with a hole in it, on the top. In this way, when the servo moves, the white end goes into the hole, closing the box.
Anyway, I made another version of this box, using a capacitive sensor instead of a piezo (you can just use a piece of aluminium paper, attaching a wire to it). If you can do it - it only requires a few changes in the code - it's a lot more efficient sensing the user's touches!
Reply 6 years ago
How can i use the sensor as a buzzer too?
Reply 6 years ago
Thank you for the fast reply. I think ill be sticking on using piezo sensor, im still not good at making codes.
The piezo sensor i saw is (https://josephmalloch.files.wordpress.com/2010/01/... like this? It doesnt have buzzer right? hehe
And about the servo, i still dont get it. I dont know what's the use of the hole in the picture for the servo. Sorry its my first time to use arduino and servo, to make something like this.
6 years ago
Hello sir, nice circuit. What piezo have you use? Piezo buzzer or piezo sensor? Thankyou!
6 years ago
Tuixte, that is a great idea and i was making the circuit and when the time to upload the code to the arduino came what was my surprise, i cant download the code, can you upload the code again please?
---Sorry for the bad english
Reply 6 years ago
Hi, thank you! I just tried to open the link in the instructable, and it worked for me.
It's this one: http://pastebin.com/9mDBrR0D
Maybe you have some connection issues?
Let me know if you have other problems.
7 years ago on Introduction
do you have a .ino code? The only one here is a .cpp one
Reply 7 years ago
Hi mknyawi, just take the code from the link and put it into a .ino file.
Reply 7 years ago on Introduction
yeah but I think this one wouldn't work with arduino, there are commands that arent familiar with arduino. Thanks a lot for the rest though, it's an awesome project!
Reply 7 years ago on Introduction
I tested it and it works! :D Which commands are you referring to, by the way?
Thank you, I'm really glad you like it!
Reply 7 years ago on Introduction
I changed it to .ino and it compiled fine thanks! I have an important question though, I am using a buzzer but I tested it separately and it's not reading any analog values so I will order a piezo element from the link you posted. Do you think that would be the issue? Also, do I need the 1Mohm resistor with the piezo element or is it fine without it? I don't have it.
Reply 7 years ago
It could be, but make it sure to test it correctly before buying a new one, maybe it was just a broken wire. Anyway, the resistor is important, without it you'll get value too high and difficult to handle
7 years ago on Introduction
Getting error 'servo does not have name type' from line 146 of the code. Any help?
Reply 7 years ago
Hi marcus, are you sure you downloaded and installed Servo library correctly?
8 years ago on Introduction
Is there any chance you could post a breadboard layout for this. I'm new to all this, but would really like to have a go at this as it's just what I need for a project that I have in mind, but at the moment I struggle with the circuit diagrams.
Many thanks
Reply 8 years ago on Introduction
Here (http://postimg.org/image/fibm77mcr/) you can find a picture of my breadboard layout, but I have to tell you that I really needed to make it as fast as possible, so it can be difficult to understand: moreover, some pieces (like servo and leds) are completely fixed into the box. Sorry I cannot help you better :)
8 years ago on Introduction
So nice :)
Reply 8 years ago on Introduction
Thank you! :D