Arduino

Interactive Zelda Treasure Chest – Technical Overview

Posted on Updated on

Note: If you haven’t read the introduction to this item yet, please start here.

While I have a basic understanding of electronics courtesy of the University of Minnesota, I knew I wasn’t up to snuff on actually building something along those lines from scratch. I’m a software developer by day, so I’m more used to virtual development environments than physical ones. Then stumbled upon Ardiuno. It’s more-or-less a miniature computer that fits on a small circuit board. While it’s not beefy enough to run a full operating system (like I hear Raspberry Pi can), you are able to control hardware directly from software in a tiny form factor. This seemed like a perfect platform for my first build.

I have to admit that it’s rare for me to actually get ideas for ways to improve things that are practical. I had seen some other people’s builds online: some played sound, others built the boxes from wood themselves, but I couldn’t find any that had the yellow uplights or proper workings for the fanfare once the item is removed. After reading up on what the Arduino can do with the extensive amount of add-on modules (called shields) and other hardware that had Arduino software libraries, I finally had my first project idea.

SAM_0341

Prop Recognition

I purchased four props to insert into the chest off of Etsy: a bomb, a heart piece, a purple rupee, and a boss key necklace. The hard part was getting the Arduino to recognize when a prop was placed in the box, and be able to tell each prop apart from the others.

My initial idea was to use reed switches (electrical switches that close when a magnet is nearby, turning the circuit on) and varying placements of magnets on the prop items to tell the Arduino which item was in the box. The idea was to MacGuyver a binary encoding system of sorts with the switches and magnets. This seemed to be a pain, since each item would have to be placed in exactly the right spot, or the system would think a different item was inside, and play the wrong fanfare once the item was removed. The biggest problem with that was that the system wouldn’t be incorrect, technically: it’s still a valid item, but the magnets weren’t registering on the switches, and the user would have no way to know that the system read it incorrectly until the item was removed and the fanfare played. I strongly dislike the possibility of human error, especially with something I made!

Thankfully, my friend Justin came up with a solution: RFID (a.k.a. NFC or near-field communication). I assume you’ve seen those cards that talk with the card readers just by being close to them? They are common in public transit and elsewhere… I know the Suica pass in Japan uses RFID. I’m sure other transit systems use them, but I wouldn’t know, because Minneapolis’ public transit system is practically nonexistent. I found an RFID reader/writer shield and some quarter-sized RFID chips, and attached them to the individual props. After jimmy-rigging the bundled software samples, I was able to write my own data to the chips.

Oddly enough, I ran into a snag with the RFID library. It seems that the method they have that checks to see if there’s a card present is a blocking call. Clearly that wasn’t going to work for me, since I have lights to animate, sounds to play, and need to be able to detect if a card is removed. I wrote another method for the library that polls for the presence of a card without blocking until one is present so I can read from it. I’m amazed the library didn’t have one baked into it already.

Lights

I found an LED strip online that was too cool to pass up. It’s a meter long, has a light every inch or so, and each light can have its color (RGB value) and intensity controlled independently of the others via my code. This was a very necessary feature, since I wanted each light to be a different brightness of yellow so I could accomplish the shimmering effect seen in the game.

In the code, I set the initial brightness of each of the 32 lights to a random percentage (0% to 100% “on”) when the system is powered on, then cycle each light through the same sine wave. This accomplishes the shimmering effect, and ensures that the actual pattern of lights is completely different each time.

Sound Driver

This proved a bit trickier than the rest, and ended up with me completely redesigning the project as a result.

I was torn between Adafruit’s wave shield and Sparkfun’s MP3 shield for the audio, but that lasted only a few seconds. I eventually chose the MP3 shield for two reasons: 1) The wave shield came as a kit that had to be soldered together. This being my first soldering project since 5th grade, I decided that I wanted to minimize the chances of me screwing it up. 2) The MP3 shield had a built-in SD memory card reader. It was really two features for the price of one!

I quickly ran into a problem with the MP3 shield, though. The Arduino has a finite number of digital pins available to use, and this thing used about two thirds of them! I still had to connect an RFID shield (which uses one digital pin), the LED strip (two digital pins), and a reed switch for the box latch (one digital pin). At that time, I was also having complications figuring out how to even configure which pin the RFID shield used, and it was overlapping with one of the pins that the MP3 shield uses. In the end, I opted for what I felt was the simplest solution: get a second Arduino, and put the MP3 shield on that one. This leads me to…

Cross-Arduino Communication

Now I had two control boards, each with a shield on them, and no good way for them to communicate. The Ethernet shields seemed like overkill, and potentially ran me into the same problem I had separated them to avoid: pin overlap. I was going to just link them with a pair of wires, and MacGuyver a rudimentary command system in binary with those two pins. Fortunately, Google then turned up a serial connection library for two Arduinos to talk to each other over a pair of wires. Even better, I could configure the library to use whatever pins I wanted for transmit and receive.

My first real snag came with this communication link. When the MP3 shield’s controller received a message from the main controller to play the sound, it received a message of the correct length, but it was all gibberish. It took two days of banging my head against a wall until I realized I had forgotten to link their ground pins so that they would share a common reference voltage (at this point, I was powering each Arduino off of the USB ports of different computers so that I could monitor each board’s state with debug output to the serial monitor). Oops. Tail between my legs, but victory nonetheless.

Sound Output

I had ordered a small handful of 0.5 watt, 8 ohm speakers, and an amplifier. I ran the numbers quickly, and decided that I needed another 42 ohms if I was going to be powering it off of the 5 volt battery pack that was used for the lights so I wouldn’t exceed half a watt. After confirming the calculations with someone who knows way more about this stuff than me (or so I believe, anyway), I hooked up the amp to the MP3 shield, battery, and speaker, and… barely anything came out the speaker. I took out the resistors, and still… barely anything. At this point, I figured I had nothing to lose, since the speakers were cheap, and I had more, so I hooked up the 9v instead of the 5v battery pack. Better, but barely anything still. I hooked the remaining speakers up to the first one in parallel. Still wasn’t satisfied. I ripped out all of that crap, bought a $10 tiny, powered portable speaker unit from Best Buy, and shoved it into the headphone jack of the MP3 shield. Best decision of this entire project. It introduces a third battery source, but it fits and sounds great.

Latch Switch

From an electronics standpoint, there was only one thing left to determine: how does the Arduino know whether the box is open or closed? at first, I thought a physical momentary switch would be best. In fact, I was planning on having the switch cut battery power until it was opened, then have the Arduino play the sound and start the lights immediately upon boot. This would have been the ultimate in battery conservation in my mind, and would eliminate the need for separate switches inside the box itself. Once I realized that wouldn’t work due to the Arduino’s delay while it loads the libraries and initializes them (about a second and a half), I decided to go a different route. I placed a reed switch in the corner of the box, and a magnet in the corresponding corner of the lid. With a simple pull-down circuit connecting the switch to a free digital pin, mission accomplished.

Power

I decided to go with power sources that could be easily and immediately replenished by common sources. This meant I needed to use alkaline batteries.

The LED strip requires that you not provide it with more than 6v. I used 4 AA batteries in series, plus a small diode to drop that down to 5.5v, per recommendation from the strip’s manufacturer.

Apparently, Arduinos themselves are quite versatile in their power inputs. Anything between 7v and 12v is tolerable. I used a 9v battery, and soldered in a second plug so that both could be powered off of one battery in parallel.

The speakers use 2 AAA batteries.

Cosmetic Touches

The Arduinos were secured to a thin sheet of particle board (that was spray painted black) with zip ties.

I built a rectangular frame with legs out of a square dowel, and spray painted that black as well. The electronic guts sit below the frame.

On top of the frame, I rested a false bottom. It was made by drilling 32 holes into another thin sheet of particle board, gluing a sheet of black velveteen to the top, then re-drilling the holes through the velveteen. The light strip was cut into four sections (re-linking the ends of each smaller strip with hookup wire and solder). Each strip was held to the underside of the board with electrical tape so that each light was visible through a hole. I then used silicone gel to attach the strips to the board permanently.

For a visual indicator of where to place the props, I wrapped a brass ring in black ribbon, and secured it to the center of the topside of the false bottom. This also acts and a gripping point to remove the false bottom.

Usage Notes

The 9v battery seems to last 30-45 minutes of use before the system becomes unpredictable. Random glitches seem to be what happens when this baby gets hungry.

The back-of-the-napkin numbers I ran suggest that I could expect to see about 2 hours of life out of the lights in a single set of 4 AA’s. I have yet to run them out yet, so no real-use numbers on these yet. They do seem to be outlasting the 9v by far, though. I’ve replaced two 9v batteries for the Arduinos, and have yet to swap out the AA’s.

What I Would Do Differently Next Time

I have since reconciled the pin usage between the MP3 and RFID shields, so I could probably stack them now. This would remove the need for the second Arduino, freeing up $30 from the cost and theoretically make the 9v last twice as long. The problem is that the chest I used is not deep enough for this to work well. I saw some other chests at JoAnn Fabrics when I was there, and will probably use one of those from now on, as they are slightly deeper.

The brass ring on the top of the false bottom seems to reduce the RFID reader’s ability to read the chips, though thankfully not enough to completely break it. I suspect some sort of Faraday Cage effect to be the culprit, and will use a plastic ring in the future, just in case.

I’m currently using hookup wire jammed into the stacking headers of the Arduino boards. I had tried using the non-stacking headers and soldering them together for a more permanent solution, but got less than stellar results. My plan for the next iteration is to use a screw terminal shield between the Arduino and the MP3 shield (if stacking the two), but this will require an even deeper chest.

I would probably also use hot glue instead of silicone gel. The gel takes 3 hours to completely dry, and is mostly used for its waterproof qualities to seal things in bathrooms. I only used it because I had it laying around, and thought it would work just as well. While it did end up working, it was sloppy and took forever to dry.

Parts and Materials List

Adafruit:

Sparkfun

Amazon

Etsy

RadioShack

  • 22-gauge, solid-core hookup wire (red, green, black)
  • Ceramic magnets
  • 25 watt soldering iron with soldering station
  • Solder

Best Buy

  • Small portable speaker

JoAnn Fabrics

  • Velveteen sheet
  • Brass ring
  • Black ribbon

Home Depot

  • Square dowel (x2)
  • Particle board
  • Zip ties
  • Black flat spray paint
  • Silicone gel

Conclusion

This project was way more fun than I even thought it would be! While I ran into a few snags along the way, I was amazed at how quickly the experiences from college came flooding back as I found myself putting the knowledge to use (the common ground between the two Arduinos idea came to me without the aid of Google, oddly enough).

If you know basic electronics and software development already, you should be fine taking this project on yourself.

Happy building!

Interactive Zelda Treasure Chest

Posted on Updated on

Over the last few years, I’ve been intrigued by the idea of ordinary objects with electronic or digital characteristics. The idea for this project (my first) came from a combination of two sources, almost simultaneously:

  1. A rather skilled cosplayer I follow online who goes by the name Lopti (AKA “Some Like It Blue”) posted about how she would be cosplaying Zelda for an upcoming convention.
  2. A random post on Cheezburger of all places showed a similar chest, just without most of the bells and whistles.

Since the Zelda series has always been a favorite of mine, and because I thought the chest I saw could be even cooler than it already was, my first inspiration had struck. I realized that I could make a chest that mimics all of the functionality of the one in the game.

SAM_0339

When an item is placed in the center ring, the box identifies which item it is, and turns on the yellow lights to acknowledge its presence. When you close the chest with an item inside, the lights turn off to conserve battery. As soon as the chest is opened, the lights turn back on, and the theme music begins playing. Finally, when the item is removed, the lights fade out, and the fanfare music corresponding to the item is played.

For a first attempt, I think it turned out pretty well:

I designed it with the following characteristics in mind:

  1. Portability – The biggest concern was carrying the thing around. I wanted it to be small enough, both in dimension and weight, for someone to carry around while cosplaying at a convention without slamming protein shakes for a month ahead of time. I also chose a chest that has a latch, so the user can ensure it stays closed when not in use.
  2. Simplicity – Slide away the false bottom, flip a few switches, and it’s live.
  3. Realism – I tried to stay true to the game as much as possible. This means no exposed electronics, switches, etc. The lights also randomly shimmer to mimic the uplighting in the game.
  4. Easy Recharge – Nobody wants to drain the battery, then sit there while it recharges. Everything can run off of standard alkaline batteries. Carry spares, and the downtime is minimal.

While the parts did end up costing more than I’d expected, I have since found ways to optimize it to reduce cost by about 10%. I expect version 2.0 to be a bit more reliable, less chaotic power-wise, and slightly less expensive.

If you’re more technically minded, I’ve put together a technical overview on how I built it.

Thanks for reading. As always, I welcome questions or constructive criticism.

P.S. If you’re into cosplay at all, you need to check out Lopti’s stuff. She also does a great job of explaining how to get the same effects she does on her YouTube channel.