loading
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

This is how the finished circuit works:


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!
<p>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.</p>
<p>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 :)</p>
<p>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.</p><p>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!</p>
How can i use the sensor as a buzzer too?
<p>Thank you for the fast reply. I think ill be sticking on using piezo sensor, im still not good at making codes.<br>The piezo sensor i saw is (https://josephmalloch.files.wordpress.com/2010/01/... like this? It doesnt have buzzer right? hehe<br>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.</p>
Hello sir, nice circuit. What piezo have you use? Piezo buzzer or piezo sensor? Thankyou!
<p>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?<br>---Sorry for the bad english</p>
<p>Hi, thank you! I just tried to open the link in the instructable, and it worked for me.</p><p>It's this one: <a href="http://pastebin.com/9mDBrR0D" rel="nofollow">http://pastebin.com/9mDBrR0D</a></p><p>Maybe you have some connection issues?</p><p>Let me know if you have other problems.</p>
<p>do you have a .ino code? The only one here is a .cpp one</p>
Hi mknyawi, just take the code from the link and put it into a .ino file.
<p>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!</p>
<p>I tested it and it works! :D Which commands are you referring to, by the way?</p><p>Thank you, I'm really glad you like it!</p>
<p>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. </p>
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
<p>Getting error 'servo does not have name type' from line 146 of the code. Any help?</p>
Hi marcus, are you sure you downloaded and installed Servo library correctly?
<p>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.</p><p>Many thanks</p>
<p>Here (<a href="http://postimg.org/image/fibm77mcr/" rel="nofollow" style="">http://postimg.org/image/fibm77mcr/</a>) 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 :)</p>
<p>So nice :)</p>
<p>Thank you! :D</p>
what the type of arduino that u use? <br> <br>is it difficult ?
Hi anugroho7, I used a Arduino Uno REV 3. It's pretty simple, you can find a lot of tutorial on the official site www.arduino.cc, or maybe you could buy a Starter Kit and learn from the book - I did so.
Awesome.
Thank you :)

About This Instructable

5,982views

40favorites

License:

Bio: Born in Naples, Italy, lover of everything concerning about technology. Currently studying Automation Engineer at Federico II University of Naples.
More by tuixte:Simple working/gaming desk Romantic LED Heart Andy - The robot arm 
Add instructable to: