Introduction: Arduino Music and Game Box
This project was a special gift to my son Eyal, for the birth of his younger brother Itamar.
It basically lets you play four games:
- Simon game
- Reaction time game
- Free play (baby-mode)
- Music mode - plays the Super Mario brothers, by Reyboz (Thanks!)
The hardware was heavily influenced by the AWESOME LenkaDesign instructable
The code except tone_functions.h was written by myself and the Game Box was assembled and wired with the wonderful help of Shani Spivak, thanks!
4 "L" Brackets (15 mm)
8 screws and nuts M4 x 10 (for brackets)
4 long standoffs M3 x 30
4 long screws M3 x 50
18 short M3 x 12mm screws and washers (example)
4 short standoffs M3 x 12 mm
2m Ethernet cable to be stripped for wires
0.5m Mini-USB cable to be cut.
1 x variable resistor (50 - 1M Ohm)
1 x 1k Ohm, 4 x 10k, 4 x 100 Ohm resistors
2 18650 cells from old laptop
2-pin battery terminals $2.91/10 pcs
Breadboard for nano (cut to 83 x 37 mm)
1602 LCD + I2C module - $1.78
Red, Blue, Green, Yellow huge momentary buttons - $1.56 each
White and black regular sized momentary buttons - $0.42 each
Large rocker switch - $0.55
Micro usb breakout - $0.22
Dual battery case - $1.18
5V Voltage booster - $0.39
Two 7030 TV speakers - 5W 4Ω - $1.97 each
Arduino nano compatible - $3.73
Printable Vinyl sheets for decoration (Optional)
Total about $19.8 if I got it right.
You're all set!
Step 1: Getting the Front/ Back Panels
Those two 5 mm acrylic panels make the structure rigid and robust.
A CNC shop or a laser cutting shop could do that job for you (online or in store).
Special thanks to Shani Karabiti 🎉.
I recommend a front patterned panel (see attached DXF by LenkaDesign) and an un-patterned back panel. I used both front and back patterned panels - it looks natural. It also allows easy access with a screwdriver to the volume control inside.
Step 2: Assembling the Box
Since the acrylic bases are much stronger than the MDF sidewalls, it makes sense to fasten the two bases together with long standoffs, with the sidewalls attached only to the lower panel. Sidewalls can't collapse inside as they are glued to each other.
For the side panels, saw off four MDF panels, 25x6 cm each.
Drill the four "L" brackets to the lower base and attach four long M3 standoffs at the lower base corners with M3 x 12 screws.
Attach the MDF panels to the L brackets, use hot glue to attach only three panels to each other, as you'll later need to install the power switch and the charging port on the 4th panel (on the right side).
Step 3: Arduino, Display, Buttons and Speakers
Cut the breadboard to 83 x 37 mm. Drill four holes 3mm for screws.
Solder the Arduino onto to the breadboard, with the mini-usb port facing to the right side of the game.
The 16x2 LCD display also serves as a baseplate for mounting (and hiding) the breadboard.
Note that you'll need to mill a notch in the acrylic for the bump on the right side of the LCD.
Wiring is standard: 5V, GND, SDA (A4 pin) and SCL (A5 pin).
LEDs on these buttons will most likely come with high resistors for operation at 12V. Take out the LEDs and replace the resistors to 100Ω, so they're nice and bright at 5V.
Connect as follows: pin A1 -> 1KΩ resistor -> Green button -> 10KΩ -> Black button -> 10KΩ -> Yellow button ->10KΩ -> Blue button ->10KΩ -> Red button ->10KΩ -> White button.
Solder each of the buttons' negative terminal to its respective LED cathode.
Wire the red, blue, yellow and green LED anodes to Arduino pins D5 through D8, respectively.
Label the white button "Menu/ Scroll" and the black button "Enter". This can be done either by printing stickers, writing on the panel with a permanent fine marker or any better way you may think of.
These make the easiest bit of the top panel. We'll use two speakers to allow more polyphonic sound and also for higher volume when needed. I think two screws per speaker are enough ;)
For volume control with a potentiometer, although it seems broken at a glance, the simplest solution turns out soldering D10 pin -> speaker -> potentiometer -> speaker -> D11 pin. This gives a decent sound volume with no distortion. The Game Box has been running like that for many hours, at low and very high volume levels. Notice to set your potentiometer to ~150Ω for the first run - not too low/ too high.
Step 4: Code!
The code is sectioned into a few headers: global functions, tones, LCD, memory game, reaction game and of course the main sketch.
The LCD and tones headers are declared first as the global functions header calls their functions.
Required external libraries
- https://github.com/bhagman/Tone/ (V1.0.0)
- https://github.com/fmalpartida/New-LiquidCrystal (V1.5.0 from a now closed BitBucket repo)
- Arduino's build-in EEPROM library
The "free play" game is embedded inside the main sketch and the music game is a part of the tones header.
You'll want to go ahead and calibrate your buttons' resistance. This is done by uncommenting the debug_flag (line #1 global_functions.h) so the sketch can communicate via serial. You should then send a 'c' (for calibration) over the serial port, click the buttons one at a time, and write down the digital voltages recorded by your Arduino.
Now hopefully the game should be all set-up.
Step 5: Battery and Charging
The first two figures show the charging system.
The power supply system is really simple. Two 18650 batteries torn apart from an old laptop battery (second figure) are connected to the TP4056 charge controller. It, in turn, is connected to the charging micro-usb port outside the box, and also to a 5V DC-DC boost converter for the Arduino and LCD. Circuits are glued to the back panel with hot glue.
The battery case is screwed to the back panel speaker grill using two M3 x 12 screws with some large washers.
A couple of notes:
- I didn't find a way to program the Arduino without using its mini-usb port, so I had to cut a mini-usb cable and solder the voltage pins to the boost converter, and the I/O pins directly to the port.
- Try choosing the most common cable type found in your home (if its USB-C, micro-USB or even lightning). If anyone wants to implement a wireless charging coil, please upload a pic 😛
- I found that the game can run for days on a single charge.
Step 6: Decoration (Optional)
I have to say that this part turned out more complex than I expected. In retrospect, I would have gone with Acrylic side walls, on which you can tape a wallpapers on the inside or outside. Choose any high aspect ratio (>16.7) high resolution image (mine is attached here as PDF).
- Since the image should be periodic anyway, there's no problem to tile several smaller images/ logos until you get to the target size of 100x6 cm. Might wanna make sure that the left and right image edges match when put together. I actually didn't bother with that one so there's a sharp color change on the rocker switch.
- The game is already pretty colorful thanks to those large buttons, so you might wanna go with a white background.
- In PowerPoint, setup a presentation the size of an A4 page. Crop the image into four segments of 25x6 cm each. Place two segments on each page. Leave a 0.05 cm gap between segments for cutting.
- Print at the highest quality on the sticker, cut with a utility knife and carefully apply to the sidewalls. Notice you'll have to cut openings for the power switch, USB port and screws.
Step 7: Ready!
- Press the white button at any time to return to the game menu and scroll between games.
- In the menu, double click the red button (child lock) to enter the preferences menu. White scrolls, black saves and returns to the game menu, red is "increase" and blue is "decrease".
- Clear EEPROM will erase the high scores and the game counter.
Hope you guys enjoyed this instructable as much as I've enjoyed making this project.
See you next time!