# Interactive Gift Box

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/049/623/medium800/leds_IMG_8190.jpg?1514071316)

https://www.youtube.com/watch?v=u1YS9pEoXig

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:

### Adafruit GEMMA M0 - Miniature wearable electronic platform

[Adafruit GEMMA M0 - Miniature wearable electronic platform](https://www.adafruit.com/product/3501)
The **Adafruit Gemma M0** is a super small microcontroller board, with just enough built-in to create many simple projects. It may look small and cute: round, about the size of a quarter, with friendly alligator-clip sew pads. But do not be fooled! The Gemma M0 is incredibly...

In Stock
[Buy Now](https://www.adafruit.com/product/3501)
[Related Guides to the Product](https://learn.adafruit.com/products/3501/guides)
![Pink polished fingers holding a Adafruit GEMMA M0 - Miniature wearable electronic platform. ](https://cdn-shop.adafruit.com/product-videos/640x480/3501-05.jpg)

### Lithium Ion Polymer Battery - 3.7v 100mAh

[Lithium Ion Polymer Battery - 3.7v 100mAh](https://www.adafruit.com/product/1570)
Lithium-ion polymer (also known as 'lipo' or 'lipoly') batteries are thin, light, and powerful. The output ranges from 4.2V when completely charged to 3.7V. This battery has a capacity of ~100mAh for a total of about 0.4 Wh. If you need a larger battery, <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/1570)
[Related Guides to the Product](https://learn.adafruit.com/products/1570/guides)
![Lithium Ion Polymer Battery 3.7v 100mAh with JST 2-PH connector](https://cdn-shop.adafruit.com/640x480/1570-00.jpg)

### Piezo Buzzer

[Piezo Buzzer](https://www.adafruit.com/product/160)
Piezo buzzers are used for making beeps, tones and alerts. This one is petite but loud! Drive it with 3-30V peak-to-peak square wave. To use, connect one pin to ground (either one) and the other pin to a square wave out from a timer or microcontroller. For the loudest tones, stay around 4 KHz,...

In Stock
[Buy Now](https://www.adafruit.com/product/160)
[Related Guides to the Product](https://learn.adafruit.com/products/160/guides)
![Bread-board friendly Piezo Buzzer](https://cdn-shop.adafruit.com/640x480/160-01.jpg)

### Medium Vibration Sensor Switch

[Medium Vibration Sensor Switch](https://www.adafruit.com/product/2384)
The "poor man's" accelerometer/motion sensor! These spring-vibration switches are **medium sensitivity** non-directional vibration induced trigger switches. Inside is a medium hardness spring coiled around a long metal pin. When the switch is moved, the spring touches the...

In Stock
[Buy Now](https://www.adafruit.com/product/2384)
[Related Guides to the Product](https://learn.adafruit.com/products/2384/guides)
![Plastic cylinder with two wires sticking out](https://cdn-shop.adafruit.com/640x480/2384-00.jpg)

### Through-Hole Resistors - 10K ohm 5% 1/4W - Pack of 25

[Through-Hole Resistors - 10K ohm 5% 1/4W - Pack of 25](https://www.adafruit.com/product/2784)
ΩMG! You're not going to be able to resist these handy resistor packs!&nbsp;Well, axially, they&nbsp;do all of the resisting for you!

This is a **25 Pack of 10K Ω Resistors.** More specifically, they are **carbon film** , through-hole...

In Stock
[Buy Now](https://www.adafruit.com/product/2784)
[Related Guides to the Product](https://learn.adafruit.com/products/2784/guides)
![Angled shot of 25 Through-Hole Resistors - 10K ohm 5% 1/4W.](https://cdn-shop.adafruit.com/640x480/2784-00.jpg)

### Through-Hole Resistors - 220 ohm 5% 1/4W - Pack of 25

[Through-Hole Resistors - 220 ohm 5% 1/4W - Pack of 25](https://www.adafruit.com/product/2780)
ΩMG! You're not going to be able to resist these handy resistor packs!&nbsp;Well, axially, they&nbsp;do all of the resisting for you!

This is a **25 Pack of 220Ω Resistors.** More specifically, they are **carbon film** , through-hole...

In Stock
[Buy Now](https://www.adafruit.com/product/2780)
[Related Guides to the Product](https://learn.adafruit.com/products/2780/guides)
![Angled shot of 25 Through-Hole Resistors - 220 ohm 5% 1/4W.](https://cdn-shop.adafruit.com/640x480/2780-00.jpg)

### Part: Wire!
quantity: 1
About a yard or two of wire

### Part: Multi-Colored LEDs
quantity: 3
Some LEDs for the blinky tree.

### Part: Cardboard
quantity: 1
A fairly sized piece of cardboard for making a box out of.

### Part: Paint
quantity: 1
Paint for the box. Can be any color. (Optional)

### Part: Solder
quantity: 1
Some solder for the components.

### Part: Soldering Iron
quantity: 1
For soldering the components

### Part: Hot Glue Gun
quantity: 1
Use to glue the box together + glue things to the box!

# Interactive Gift Box

## Step 1: Get a template

Info: 

![](https://cdn-learn.adafruit.com/assets/assets/000/049/398/medium800/adafruit_products_ChristmasBoxStep2.png?1513646725 Choose your sizes)

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&nbsp;[http://templatemaker.nl](http://templatemaker.nl "Template Maker")&nbsp;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&nbsp;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.

# Interactive Gift Box

## Step 2: Print

![](https://cdn-learn.adafruit.com/assets/assets/000/049/399/medium800/adafruit_products_BoxTemplateAdobie.png?1513647793 Image half on the page, Adobe Illustrator)

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:

1. Open the PDF in preview or whatever you open the image. Take the two slides and drag each one to your desktop
2. Open the box bottom template in Illustrator and select all. Then go to edit-copy, or use the copy keybind.
3. Open a new page (Command/Control-N), and make sure it's size is tabloid.&nbsp;
4. Paste (Command/Control-V), and make sure that the image is half on the sheet, as shown above.
5. Go to File-Print (Command/Control-P) and click Page Setup. It should take you to a new window. Change the print size to letter and click OK. Then press print.
6. Repeat step 5, but with the box template on the other side.
7. Open your box top template into an image editor (Not Adobe&nbsp;Illustrator, something&nbsp;like Preview).&nbsp;
8. Print it on to a tabloid-sized sheet of paper

Whew! complicated.&nbsp;

# Interactive Gift Box

## Step 3: Make the box

Info: 

# Interactive Gift Box

## Step 4: Electronics

![](https://cdn-learn.adafruit.com/assets/assets/000/049/620/medium800/leds_GiftBoxFritzing.png?1514067139)

[PresentBox.fzz](https://cdn-learn.adafruit.com/assets/assets/000/049/619/original/PresentBox.fzz?1514067105)
Now it's time to make the box work! Follow these steps carefully, and it should work. You will need:

- 1x Gemma M0
- 1x Lithium Ion Polymer Battery
- 1x Piezo
- 3x LEDs
- 3x 220&nbsp;Ω Resistor (Red, Red, Brown, Gold)
- 1x 10k&nbsp;Ω Resistor (Brown, Black, Orange, Gold)
- 1x Medium Vibration Sensor
- 2 yards of insulated wire
- Something to make holes with!

&nbsp;

You're&nbsp;done with the hardware! Now let's open up Arduino&nbsp;and start coding!

# Interactive Gift Box

## Step 5: The Code

Now let's get the board to work! Let's setup Arduino. If you don't already&nbsp;have the Gemma M0 board driver installed, check out this link:

[Using with Arduino IDE - Adafruit Gemma M0](https://learn.adafruit.com/adafruit-gemma-m0/using-with-arduino-ide)
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 &lt; 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 &lt; 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 &lt; 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&nbsp;turn purple! Hit it on the side, and it should light up and play music! Now you have an awesome gift box!

https://www.youtube.com/watch?v=u1YS9pEoXig

# Interactive Gift Box

## FAQ

Have questions? Click the 'Feedback? Corrections?' link on the left.

### 

Yes, but you might have to solder it differently and change the code.

# Interactive Gift Box

## Credits!

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&nbsp;@nis for helping me get my Gemma M0 to work in the Adafruit Discord.


## Featured Products

### Adafruit GEMMA M0 - Miniature wearable electronic platform

[Adafruit GEMMA M0 - Miniature wearable electronic platform](https://www.adafruit.com/product/3501)
The **Adafruit Gemma M0** is a super small microcontroller board, with just enough built-in to create many simple projects. It may look small and cute: round, about the size of a quarter, with friendly alligator-clip sew pads. But do not be fooled! The Gemma M0 is incredibly...

In Stock
[Buy Now](https://www.adafruit.com/product/3501)
[Related Guides to the Product](https://learn.adafruit.com/products/3501/guides)
### Lithium Ion Polymer Battery - 3.7v 100mAh

[Lithium Ion Polymer Battery - 3.7v 100mAh](https://www.adafruit.com/product/1570)
Lithium-ion polymer (also known as 'lipo' or 'lipoly') batteries are thin, light, and powerful. The output ranges from 4.2V when completely charged to 3.7V. This battery has a capacity of ~100mAh for a total of about 0.4 Wh. If you need a larger battery, <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/1570)
[Related Guides to the Product](https://learn.adafruit.com/products/1570/guides)
### Piezo Buzzer

[Piezo Buzzer](https://www.adafruit.com/product/160)
Piezo buzzers are used for making beeps, tones and alerts. This one is petite but loud! Drive it with 3-30V peak-to-peak square wave. To use, connect one pin to ground (either one) and the other pin to a square wave out from a timer or microcontroller. For the loudest tones, stay around 4 KHz,...

In Stock
[Buy Now](https://www.adafruit.com/product/160)
[Related Guides to the Product](https://learn.adafruit.com/products/160/guides)
### Through-Hole Resistors - 220 ohm 5% 1/4W - Pack of 25

[Through-Hole Resistors - 220 ohm 5% 1/4W - Pack of 25](https://www.adafruit.com/product/2780)
ΩMG! You're not going to be able to resist these handy resistor packs!&nbsp;Well, axially, they&nbsp;do all of the resisting for you!

This is a **25 Pack of 220Ω Resistors.** More specifically, they are **carbon film** , through-hole...

In Stock
[Buy Now](https://www.adafruit.com/product/2780)
[Related Guides to the Product](https://learn.adafruit.com/products/2780/guides)
### Through-Hole Resistors - 10K ohm 5% 1/4W - Pack of 25

[Through-Hole Resistors - 10K ohm 5% 1/4W - Pack of 25](https://www.adafruit.com/product/2784)
ΩMG! You're not going to be able to resist these handy resistor packs!&nbsp;Well, axially, they&nbsp;do all of the resisting for you!

This is a **25 Pack of 10K Ω Resistors.** More specifically, they are **carbon film** , through-hole...

In Stock
[Buy Now](https://www.adafruit.com/product/2784)
[Related Guides to the Product](https://learn.adafruit.com/products/2784/guides)
### Medium Vibration Sensor Switch

[Medium Vibration Sensor Switch](https://www.adafruit.com/product/2384)
The "poor man's" accelerometer/motion sensor! These spring-vibration switches are **medium sensitivity** non-directional vibration induced trigger switches. Inside is a medium hardness spring coiled around a long metal pin. When the switch is moved, the spring touches the...

In Stock
[Buy Now](https://www.adafruit.com/product/2384)
[Related Guides to the Product](https://learn.adafruit.com/products/2384/guides)

## Related Guides

- [Make It Glow: How to Solder NeoPixels, A Beginner's Guide](https://learn.adafruit.com/make-it-glow-how-to-solder-neopixels-a-beginners-guide.md)
- [Hidden Ink UV Message Reader](https://learn.adafruit.com/hidden-ink-uv-message-reader.md)
- [CircuitPython Essentials](https://learn.adafruit.com/circuitpython-essentials.md)
- [NeoPixel LED Mickey Ears](https://learn.adafruit.com/neopixel-led-mickey-ears.md)
- [NeoPixel Tiara](https://learn.adafruit.com/neopixel-tiara.md)
- [NeoPixel Ring Bangle Bracelet](https://learn.adafruit.com/neopixel-ring-bangle-bracelet.md)
- [Gemma Color Touch Pendant Necklace](https://learn.adafruit.com/gemma-color-touch-pendant-necklace.md)
- [NeoPixel NanoRing](https://learn.adafruit.com/neopixel-nanoring-gemma.md)
- [Trinket (& Gemma) Servo Control](https://learn.adafruit.com/trinket-gemma-servo-control.md)
- [Annoy-O-Matic Sound Prank Device](https://learn.adafruit.com/annoy-o-matic-sound-prank-device.md)
- [Larson Scanner Shades (Trinket-Powered NeoPixel LED Strip Glasses)](https://learn.adafruit.com/larson-scanner-shades.md)
- [Trinket Ultrasonic Rangefinder](https://learn.adafruit.com/trinket-ultrasonic-rangefinder.md)
- [Princess Peach LED Crown](https://learn.adafruit.com/bowsette.md)
- [Trinket / Gemma Mini-Theremin](https://learn.adafruit.com/trinket-gemma-mini-theramin-music-maker.md)
- [Adafruit LED Sequins](https://learn.adafruit.com/adafruit-led-sequins.md)
