If you know someone who loves electronics, this is an awesome gift box for them! In this guide, you will make a homemade box that plays music and lights up when it is shaken. Here is what you will need:






If you know someone who loves electronics, this is an awesome gift box for them! In this guide, you will make a homemade box that plays music and lights up when it is shaken. Here is what you will need:
If you already have a box, you won't need this step, but if you don't, this is how to make one. First, head over to http://templatemaker.nl and find a box template that fits your creative imagination! There are a lot to choose from, but for this guide, I will be using the box-with-lid. It will give us space to put in our electronics, while also being easy to make. Choose the size. I chose a 6x3x6 inch box with a 6x1 inch lid. My clearance was 0.125. Choose download and click create.
Printing the image is one of the hardest parts because the image would be resized when you print it, or it won't fit on the page you are using. To do this, I used Adobe Illustrator and put the image into 2 tabloid-sized documents.
Here is how:
Whew! complicated.
Step 1: Take the template papers you cut out and tape them together, so that it would look like one image (shown on the right). Then cut it out. |
|
Step 2: Place your template on some cardboard and cut out the shape. First, score the cuts, then remove the paper, and make the scores deeper. |
|
Step 3: Turn the cardboard over and score, which is cutting halfway through the cardboard, the folds (marked with - - - - on the template). |
|
Step 4: Take your Hot Glue Gun and glue the sides of your box together, as seen in the gif on the right. (You may have to click the image to see it. |
|
Step 5: Cut out the template for the box top. Once again, ignore the flaps. |
|
Step 6: Cut along the template you made on the cardboard. |
|
Step 7: Score the folds like you did a few steps ago. Remember that the side you score on will be the outside of the box. |
|
Step 8: Glue the edges of the box together. This can be hard, so you may want to tape the parts together when it is drying. |
|
Step 9: Paint your box a solid color. I chose dark grey because it would make the lights of the tree show up well. |
Now it's time to make the box work! Follow these steps carefully, and it should work. You will need:
Take the top of your box and poke holes where you want the LEDs to come through. Make sure that you use the tree to measure where you want the LEDs. |
|
Put the tree on to the box, and poke holes through it so that the LEDs can go through. In other words, poke holes in the tree even to the holes you poked into the box. |
|
Put the LEDs through the holes on the box top. make sure to mark which side is positive and which is negative. Because of our layout, please put the positive side of the LEDs on the right. |
|
Warm up your hot-glue gun and put glue on the back of the tree. Place it carefully on the box, making sure the LEDs go through the holes. |
|
Connect the positive wire on the LED to a 220 Ω resistor. Then, solder the two together. |
|
Connect the resistors together. If needed, solder a wire to one of them so it can be extended. |
|
Now, solder all of the resistors together. You may need a lot of solder to do so. |
|
Cut a 1 ½ inch wire, and strip both ends. Then, connect one side to the resistors you just soldered. Touch your soldering iron to the solder joint you just made, and add your new wire to it. |
|
Take the wire you just soldered and make a hook on the other side. Attach that to pin D0 on the gemma, and solder it. |
|
Next, we are going to solder the negative sides of the LEDs to the gemma. Cut 3 1 inch piece of wire and strip it. Then, solder them to the negative side of the LEDs. |
|
Solder the 3 wires together, as shown in the picture. |
|
Cut another 1 inch wire and solder it to the LED's negative wires. Then solder the wire to the Gemma's Gnd pin. |
|
Get your vibration sensor out and connect the copper wire to a 1 ½ inch wire as shown in the picture. |
|
Take out your 10k Ω resistor and cut a inch long wire and connect them both to the middle wire. Then, solder them together. |
|
Take the first wire you soldered to the sensor and connect it to the 3vo pin on your Gemma. Then, solder it on. |
|
Solder the resistor to Gnd on the Gemma board. |
|
Solder the last wire to D1 on the Gemma board. |
|
Now it's time to set up the music! Cut a 1 ½ inch long piece of wire and solder it to your already used Gnd pin. To do so, place the tip of the iron onto the Gnd pin, and place the new wire onto the solder joint. Take off the soldering iron, and the joint will be complete! |
|
Connect the other side of the wire to any pin on the piezo and solder it on. |
|
Take another wire, about the same size, and solder it onto the other pin on the piezo. |
|
Take that wire and connect it to pin D2 on the Gemma M0. Then, solder it on. |
You're done with the hardware! Now let's open up Arduino and start coding!
Now let's get the board to work! Let's setup Arduino. If you don't already have the Gemma M0 board driver installed, check out this link:
After you have that installed, we need to put the Gemma M0 into Bootloader Mode. To do so, press the reset button twice, and the red LED should start flashing. Make sure that your board selection is right (tools-board-Gemma M0) and so is your port (tools-port), and then upload this code:
/* Interactive Gift Box When you shake the box, it will light up the tree and play music! */ int speakerPin = 2; int buttonPin = 1; int ledsPin = 0; int length = 26; int buttonState = 0; char notes[] = "eeeeeeegcde fffffeeeeddedg"; int beats[] = { 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2}; int tempo = 200; void playTone(int tone, int duration) { for (long i = 0; i < duration * 1000L; i += tone * 2) { digitalWrite(speakerPin, HIGH); delayMicroseconds(tone); digitalWrite(speakerPin, LOW); delayMicroseconds(tone); } } void playNote(char note, int duration) { char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' }; int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 }; for (int i = 0; i < 8; i++) { if (names[i] == note) { playTone(tones[i], duration); } } } void setup() { pinMode(speakerPin, OUTPUT); pinMode(ledsPin, OUTPUT); pinMode(buttonPin, INPUT); } void loop() { buttonState = digitalRead(buttonPin); if (buttonState == HIGH) { digitalWrite(ledsPin, HIGH); for (int i = 0; i < length; i++) { if (notes[i] == ' ') { delay(beats[i] * tempo); } else { playNote(notes[i], beats[i] * tempo); } delay(tempo / 2); } digitalWrite(ledsPin, LOW); delay(1000); } }
Press the upload arrow and the light on the board should turn purple! Hit it on the side, and it should light up and play music! Now you have an awesome gift box!
You may not know it, but there are some people behind the scenes who helped me get this guide up!
I'd like to thank Mr. Lady Ada (Phillip) and Kelly for letting me make a guide!
I'd also like to thank @Dan Halbert, @cater, and @nis for helping me get my Gemma M0 to work in the Adafruit Discord.
This guide was first published on Dec 22, 2017. It was last updated on Dec 22, 2017.