Christmas Puzzle Box

As a running gag within my family, I make my sister’s Christmas presents rather difficult to open. Usually this just consists of taping the entirety of the box in packing tape. Last year, my sister PJ did me one better, and wrapped twenty $1 bills, all in separate boxes. This year I thought I would get her back, with a box that has to be solved before it will open. And since I had a gy-521 chip lying around, hey why not?

IMG_3633 IMG_3631

The box is an old cigar box, loaded up with an Arduino, a servo, LEGOs, a few LEDs, and a gyroscope.


In order for the box to open, it must be rotated in a specific pattern

int puzzle[5][3] = {{0, 0, 90, },{90, 0, 0 }, {-90, 0, 0 }, {-180, 0, 0 }, {-180, 90, 0 }};

which is predefined by an array at the top of the program [complete program at bottom of post].

The build is very rough, as it is made for a one time use, and I didn’t really want to nail anything down or permanently alter anything.

First I focused on the code. I looked up the gy-521 and found some very helpful code here. It gave me a great starting point, as I would have no idea how to get data from the chip.


I created a method that takes the angular velocity and makes approximations of how the chip has been turned.

From there I created a puzzle. The puzzle has 5 “frames” or stages. The puzzle allows you up to 30 degrees of error on any particular frame, and tells you on which axis the box must be rotated.  Once you are within the frame, it tells you by blinking a green led, and then loads the next frame. Once all frames are complete, it turns on the green light indefinitely, and tells the servo to move to 90 degrees.

There is a challenge, as you only have a certain amount of time to pass any frame. If the time is exceeded, the green light blinks repeatedly, and you have to turn the box off and on again and start the whole puzzle over.


The hardware is all rather simple, and since I didn’t want to make anything permanent, I just stuck a mini breadboard in the box. Here is the pin layout


  • SDA to A4
  • SCL to A5
  • VCC to 5v
  • Gnd to Gnd


  • data to D9
  • pos to 5v
  • Gnd to Gnd


  • Green to D13
  • Blue to D4
  • White to D5
  • Red to D6



  • Red to VCC
  • GND to switch to GND

The only tricky part from there is making the angular motion of the servo control a lock. I used some LEGOs and a cup hook to get the job done fast and relatively easy. Wrap some wire to the servo and LEGO actuator arm and looky here we got a lock!



That’s about it. Here is the code!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s