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.

CODE:

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.

IMG_3610

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.

HARDWARE:

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

GY-521

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

Servo:

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

LEDs

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

IMG_3630

9V

  • 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!

giftbox

IMG_3629

That’s about it. Here is the code!

Advertisements

Star Wars Picture Frame

My Secret Santa this year is a huge star wars fan. Since I already bought her something else, and I wanted to keep everything under budget, I decided to make this.

IMG_3511IMG_3512

A Star Wars picture frame. Operation is simple: it works like a night light. When the photoresistor receives less light, the LEDs glow brighter. So it acts as a nightlight at night, and can be turned on by just covering up the photoresistor at any time.

This can be built quickly, cheaply, and I didn’t have to buy anything since I had this kind of stuff laying around.

Parts:

  • Green LED
  • Blue LED
  • Resistors (values:
  • NPN Transistor (2N2222 was used)
  • 9V battery and holder
  • Picture frame
  • Drinking straw
  • Wire

Tools:

  • Hot Glue Gun
  • Soldering Iron

Build:

Prototype the following circuit to make sure everything works.

IMG_3510

IMG_3504

I based the circuit on a basic not gate (pic for reference).

20131206-095935.jpg

Now that the LEDs light up when you turn the lights around it off, it’s time to solder it all together.

IMG_3506IMG_3507

Attach the circuit to the frame.

IMG_3513

Wrap and give away. Merry Christmas 😀

Here’s a video of the build. As you can see, I was definitely riding the struggle bus. I didn’t have the right resistors on hand so I tried a bunch of equivalent resistor calculations and ended up giving up and stealing some from another lab. I also saw that the AA’s I was using were going to be too big for the back of a frame, so I went with a 9V. If I were to do the whole thing again I could probably do it in about in hour. You learn more from failures anyway, right?