Hey everyone, I wanted to share a project I just finished up. I built a super secret locking box for my girlfriends little brother. He has a knack for creative lego building so I thought it would be a good idea to open him up to the Arduino as soon as possible. The super secret locking box will only open for those with right password or there is a hidden way to reset the passcode so that no prying little sister would ever be able to figure it out. That is, unless she finds this instructable. The secret method involves using some capacitive touch sensing. 

The Arduino stays asleep to conserve battery and only wakes when the button is pressed. Upon waking, there are two paths to go down, flash the green LED, unlock, and go back to sleep OR light up the red LED and wait for 20 seconds for the right passcode, then go to sleep. In the period before it goes to sleep, if you touch(not press) the button for 5 seconds, the passcode will be set to whatever the code is currently. It will then unlock and go back to sleep. The 20 seconds timer restarts every time the button is pressed.

ATmega168/328 on a PCB or an Arduino with a breadboard
Wood Box
small servo
3x Potentiometers & knobs
push button
2x 100 ohm resistors 
150 ohm resistors 
battery pack
depending on how you make the latch, these parts will be up to you, I used 1/4" square dowels to make the latch and supports 

Skills with a Dremmel
Soldering Iron
Hot Glue Gun
Wood Glue (I recommend Gorilla Wood Glue, the non-foaming kind)

If anyone can decipher the suspected Japanese characters, I would really love to know the original purpose of the box.

He loved it! 

Step 1: Cut and Wire It Up!

You will need to measure out where to cut 5 holes for the pots, LED, and button. Make sure to leave space for either the Arduino or a breadboard/pcb standalone. I chose to use an ATmega 328P-PU standalone running 8MHz internal clock to minimize battery consumption. On sleep mode, theoretically should only draw a few uA which is worlds better that the 25mA the UNO was consuming.
If you plan to use the arduino development board instead of a standalone version, be sure to bypass the 5V regulator by using the 5V pin to power it instead of VIN or the barrel jack. Trying to conserve any battery is pointless if it is being used.  

Connect 5V, GND and data lines to the appropriate pins. Remember to use resistors on the LED, red needs 150 ohms while blue and green need 100 ohm resistors. 

Remember, the pots must be connect to analog pins.

Whichever battery pack you choose must output a max voltage of 5.5V and a minimum of 4.5v. (3AA wired in series should work). The ATmega328 will run nicely anywhere from 1.8 to 5.5v but the servo requires a bit more juice. The data sheet for a 9g servo says 4.8v minimum. Since it is more common to find packs with 4 batteries which would produce 6v, a Shottkey diode can be used to drop to voltage to 5.6v. I don't think an extra .1v will damage the ATmega. 

3x 1.5v alkaline AA wired in series = 4.5v
I used 4x 1.2v lithium batteries for 4.8v

Step 2: Code

Interrupts can be tricky, digital pin 2 is also PCINT0. that is why the button is connected to pin 2 but the interrupt is attached to 0.

#include <Servo.h>

#include <CapacitiveSensor.h>

#include <avr/sleep.h>

const byte red = 6;
const byte green = 7;
const byte blue = 8;

const byte pot1 = A0;
const byte pot2 = A1;
const byte pot3 = A2;

const byte button = 2;

int code1 = 1;
int code2 = 1;
int code3 = 1;

int pot_val1 = 0;
int pot_val2 = 0;
int pot_val3 = 0;

int button_val = 0;

int touch;

unsigned long currentMillis = 0;
unsigned long codeMillis = 0;
unsigned long buttonMillis = 0;
unsigned long sleepMillis = 0;

CapacitiveSensor cs_10_11 = CapacitiveSensor(3,4);

Servo myservo;

int sleepCounter = 0;
boolean state = LOW;

void setup()
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
pinMode(button, INPUT);
pinMode(pot1, INPUT);
pinMode(pot2, INPUT);
pinMode(pot3, INPUT);
digitalWrite(button, HIGH);
attachInterrupt(0, interrupt, RISING);

void loop()
getPots(); //read in pot values
mapAllPots(); //adjust them to the correct scale
if(pot_val1 == code1 && pot_val2 == code2 && pot_val3 == code3) //if password is correct
g(); //light green led
unlock(); //unlock the latch
sleepNow(); //go to sleep
r(); //turn on red led

currentMillis = millis();
button_val = !digitalRead(button); //read the button value

if(button_val == 1) //if button is pressed, reset the timers.
sleepMillis = currentMillis;
codeMillis = currentMillis;

if((currentMillis - sleepMillis) > 20000) //if timer expires, go to sleep
sleepMillis = currentMillis;

touch = highLow(cs_10_11.capacitiveSensor(30)); //read touch capacitance and map it to binary HIGH or LOW
currentMillis = millis();
if(touch == 1)
if((currentMillis - codeMillis) > 5000) //if touch is 1 for 5 seconds
b(); //light th blue led
storeCode(); //store code from pot values
codeMillis = currentMillis;
if(touch == 0) //if no touch reset timer to prevent time accumulation
codeMillis = currentMillis;


//end of loop

void interrupt()
currentMillis = millis();

if((currentMillis - buttonMillis) > 200)

buttonMillis = currentMillis;
void sleepNow() // here we put the arduino to sleep
off(); //turn off all leds

set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here

sleep_enable(); // enables the sleep bit in the mcucr register
// so sleep is possible. just a safety pin

attachInterrupt(0, interrupt, RISING); // use interrupt 0 (pin 2) and run function
// wakeUpNow when pin 2 gets LOW
MCUCR = bit (BODS) | bit (BODSE); // turn on brown-out enable select
MCUCR = bit (BODS); // this must be done within 4 clock cycles of above

sleep_mode(); // here the device is actually put to sleep!!

sleep_disable(); // first thing after waking from sleep:
// disable sleep...
detachInterrupt(0); // disables interrupt 0 on pin 2 so the
// wakeUpNow code will not be executed
// during normal running time

int highLow(unsigned long x)
if(x >= 300)
return 1;
return 0;


void getPots()
pot_val1 = analogRead(pot1);
pot_val2 = analogRead(pot2);
pot_val3 = analogRead(pot3);
void mapAllPots()
pot_val1 = mapPot(pot_val1);
pot_val2 = mapPot(pot_val2);
pot_val3 = mapPot(pot_val3);
int mapPot(int in)
if(in > 1010){
return 1;
else if(in > 950){
return 2;
else if(in > 900){
return 3;
else if(in > 630){
return 4;
else if(in > 480){
return 5;
else if(in > 190){
return 6;
else if(in > 80){
return 7;
else if(in > 30){
return 8;
else if(in > 3){
return 9;
void storeCode()
code1 = pot_val1;
code2 = pot_val2;
code3 = pot_val3;
void r()
digitalWrite(red, HIGH);
digitalWrite(green, LOW);
digitalWrite(blue, LOW);
void g()
digitalWrite(red, LOW);
digitalWrite(green, HIGH);
digitalWrite(blue, LOW);
void b()
digitalWrite(red, LOW);
digitalWrite(green, LOW);
digitalWrite(blue, HIGH);
void off()
digitalWrite(red, LOW);
digitalWrite(green, LOW);
digitalWrite(blue, LOW);
void unlock()

Step 3: Latch

There are many latch systems out there. I almost went with the chopstick between the cup hooks methods used in this project http://arduiniana.org/projects/the-reverse-geo-cache-puzzle/. The problem with the chopstick method is that it must wait for the box to close before it can go back to sleep. I wanted int to sleep as soon as possible and waste no time waiting on an indecisive moment. So I combined the two ideas from that project and this one https://www.instructables.com/id/Super-Secret-Lock-Box/

In my latch, the servo is not connected to the latch. It simply pushes it and hold it open for a brief period. A clothespin style spring I bent from a paper clip keeps the latch down and locked at all times. You will have to mess with the tension of the spring so that it doesn't fight the servo too hard but still remains securely latched.

I used wood glue to join pieces of 1/4" dowel rods together and carved them with a dremmel to make the latch system. It is secured to the box with wood glue. 

<p>great lock i was planning on making this tho the only thought i have is that i won't be using the arduino so how would i get the code to work so i can change the pass code?</p>
Hey , ryclmer!<br><br><br>Nice Instructable, I'm planning to make this project myself. But what library's did you include.
<p>#include &lt;Servo.h&gt;</p><p>#include &lt;CapacitiveSensor.h&gt;</p><p>#include &lt;avr/sleep.h&gt;</p>
<p>I can't find a download link for the &quot;avr/sleep&quot; library, could you give me a download link please.</p>
<p>It think its a built in feature, no need for download. </p>
<p>Thanks rclymer</p>
<p>Awesome! nice job! </p>
<p>thank you so much for doing this. I want to build this with my son. Can you please put up part numbers for some of the stuff? Especially the pots? Where did you get knobs like that?</p>
<p>Thanks so much, I'd be glad to help you find some of the same parts. Everything came from either ebay or amazon.</p><p>pots ~ <a href="http://www.ebay.com/itm/271315681087?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649" rel="nofollow">http://www.ebay.com/itm/271315681087?ssPageName=ST...</a></p><p>knobs ~ <a href="http://www.ebay.com/itm/290803952185?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649" rel="nofollow">http://www.ebay.com/itm/290803952185?ssPageName=ST...</a></p><p>button ~ <a href="http://www.amazon.com/gp/product/B0094FPJ4O/ref=oh_details_o01_s00_i00?ie=UTF8&psc=1" rel="nofollow">http://www.amazon.com/gp/product/B0094FPJ4O/ref=oh...</a></p><p>servo ~ <a href="http://www.ebay.com/itm/SG90-Mini-Gear-Micro-9g-Servo-For-RC-Airplane-Helicopter-Car-Boat/321284392104?_trksid=p2047675.m1850&_trkparms=aid%3D333008%26algo%3DRIC.MBE%26ao%3D1%26asc%3D321%26meid%3D4305027800320344966%26pid%3D100011%26prg%3D1167%26rk%3D1%26rkt%3D5%26sd%3D360760177538%26" rel="nofollow">http://www.ebay.com/itm/SG90-Mini-Gear-Micro-9g-Se...</a></p>
Those are Chinese Character, not Japanese. You also have it upside down in the photo. The words means incent dispensing device. So I assume this is a storage box that stores some form of incent dispensing device. <br> <br>This is a link to a page with many pictures of antique units of what the original device inside might look like. http://www.baike.com/wiki/%E9%A6%99%E5%85%B7 <br> <br> <br> <br>
are they simplified characters? if not they could be either chinese or japanese (kanji). but yeah, upside down box for an incense burner.
Very clever! how did you build the capacitive touch switch? i've been trying to get that working right for another project but its too erratic and touch input read have a high error rate.
All the capacitive touch is taken care of in code. The library does all the hard work. I soldered a jumper to the nut on the screw to make contact with your finger. You will have to use the serial monitor and fool with the values the sensor returns and set a threshold that triggers the timer. If you are using a laptop, make sure it is plugged in. A laptop not grounded will give you inconsistent readings.
My 15 year old grandson has been teaching himself Japanese. He says the picture of the characters is upside down. The first one is &quot;fragrant&quot; and the second one can refer to several things. One is &quot;sapling&quot; So it appears that the box was for a plant with the &quot;cover&quot; on the bottom.
Not knowing Japanese I would have guessed that the symbol on top is &quot;man with goatee&quot; and the bottom symbol is &quot;happy dancing&quot;.
My friend came to a similar conclusion - http://translate.google.com/#auto/en/%E9%A6%99%E5%85%B7 <br> <br>I'm guessing that the &quot;lid&quot; here was actually the bottom of the box originally, hence the upside-down-ness of the characters.
Excellent, I studied a little about code locks earlier and 3 dials with 10 digits gives you 1000 combinations, so you can crack it number by number in less than an hour :) <br>I've designed my own mechanical code lock, its still waiting in my sketchbook to be made some day :)
Exactly right. It would be a hassle but it is quite crackable. I thought to add a 4th dial but decided it would be too cluttered and not really necessary since it is a gift for a kid. If I build one as an actual safe, it will absolutely have 4 dials. I think that makes for 10,000 combinations. Next time I will use rotary encoders for better accuracy. Thanks for the post.
4 dials first number usualy 1 becouse the code is usualy a date :D the second digit's usualy from a non long past so its 0,9 or 8 you just decresed your cracking time to minutes :D
Social engineering doesn't diminish real security. 4 digits is good enough for most locks.
I suggest a lockout as cellphones have, after tree wrong tries it locks itself for some hours. This only applies to the patient thief without a hammer, rock or saw. :) A better way to secure is to have a hardened steelframe inside of the woodbox, another lock, these three dials plus lockout code. <br> <br>(When somebody tried to steal my bike I understood that security can't be one thing, it have to work like a chain or layers.) <br> <br>...oh yes, thanks a lot for this instructables! <br>I doubt that I'll use this method, somehow it's easier to add a key and a lock instead of arduino... yes, I know, shame on me!
if you want security keep it a secret, no one knows, no one wants.
Kinda cool, but add a power input connection, so if the batts go dead, you can plug in a wall wart and power it up! <br> <br>great Xmas gift for a kid! <br> <br>
I thought about it but the battery should theoretically last for well over a year and the small pinhole should prevent you from every being locked out. Also, If he plugged in the wrong adapter, say a common12v adapter, it would destroy it, then we would require a voltage regulator, but then there will be dropout voltage and higher quiescent current consumption and would the defeat the battery saving code techniques. Batteries alone are the most efficient solution.
Good thoughts fer sure, but if you have a work around , then it is not an issue. It is a very cool project. I made my own box when I was a kid, learned a lot from my mistakes. Now I want to make one with a tumbler system and carve the top and sides and maybe archane symbology for the numbers!!<br><br>again, nice box
Commercial safes have the batteries inside a detachable control panel.
Nice work, I've been thinking to do something like this, don't have the box yet though. Is it possible to replace batteries from outside? Even though the batteries should last for decades, but how do you open it if they are depleted?
There are panel mounting battery compartments that would do that. If you watch the video, you will see I drilled a very small hole just big enough for a paper clip to push the latch open. The box is definite the hardest thing to find.
As Ozzie_G said the box is upside down. In Chinese the character on the bottom 香 (on the top of the box is right side up) means fragrant and 具 means tool, I imagine in Japanese it means box. The characters for Chinese and Japanese are mostly similar even if some of the meanings are slightly different.
That's a really cool thing to build for a kid. Nice job!
Thanks a lot. I hope he thinks it's as cool as everyone here has said it is.
From the WikiPedia: Diode: <br> <br>For silicon diodes, the built-in potential is approximately 0.7 V (0.3 V for Germanium and 0.2 V for Schottky).
Thanks for input. That will save a lot of trial and error later on.
me likey!
This is an excellent instructable, just curious how much did it end up costing you?
I'm glad you like it. It costs me about $50 but that is also including the extra parts leftover. Everything but the box came from eBay or amazon. Here is a rough list of parts and prices<br> Box - $20<br> Button - $5<br> RGB LED -&nbsp;$1<br> Pots - $4<br> 9g Servo -&nbsp;$4<br> ATmega328 - $3<br> PCB board - $1<br> Battery pack - $4<br> wire - $3<br> <br> <br> <br> <br> <br> <br> <br>
i think u might wanna put the code that typed out into a library so pple can just down load it.
I didn't prove the store wrong. These characters are used in both Chinese and Japanese. (Japanese has additional character set) <br>My Chinese is very poor. The box may have contained incense or something that incense is used in. A ceramic container with holes in it through which the smoke can escape for example. <br>Did you attach the hinges, or did the box normally open in this way? <br>It looks as if the &quot;box&quot; was actually the cover and what you now use as a lid was a bottom. <br>So perhaps something pretty was standing on the bottom and could be covered by your box when not in use.
Yes, I was thinking the same thing. The lid was probably was used as a platform. It came with a strap through the holes in the lid and you can see where they have worn out the finish in a V shape. To me, that confirms your theory.
Yeah, that was the plan, I am getting an error when I try to upload it. So for now copy &amp; paste is the best Ive got.
I found one problem, which is probably no big deal, but 4 AA's in series give off six volts not 4.5v. Great inatructable though!!!
Right you are, what a silly error. I forgot to mention that I am using lithium batteries that are 1.2v each so my output is 4.8v. Im not an expert but with 6V, because it exceeds what the ATmega is rated for, it may be a good idea to use a Shottkey diode to drop the it down to 5.6v. Thanks for catching that.
Genius! BTW, how strong is the mechanical latch? I've been planning to make one of these but I had a hard time researching for an indestructible latch.
Since its such an old box I haven't really given it a proper strength test because I think the box itself would break before the latch. The dowel rods are made of fairly soft poplar so it may not be indestructible, maybe using some stronger wood and a metal support around the lid would be a nice improvement. I made the latch with a steep angle to minimize collision with the lid.
Nice little instructable. <br>What makes the box even more mysterious is that the Chinese characters are upside down. :-) <br> I am no expert but 香具 means something like an incense box. <br>
Very interesting. The antique store I picked it up at told a big tale of brining it back from Japan. Incense seems like a good fit for a box its size. Thanks for the post.
This would be a great application for my gun safe, sporting goods box, and fishing tackle ! I would never have to worry about my stuff getting pilfered again!<br>Good job<br>
thanks dad, I think it may be me doing the pilfering though.
Very Cool<br>Lauren's brother will love it!

About This Instructable




Bio: I burnt the cider.
More by rclymer:Super Secret Lock Box w/ Capacitive Touch Ultrasonic Garage Parking Assistant with Arduino and an ATtiny85 
Add instructable to: