Introduction: Introduction: Halo Theme Music Box

Why did I make this Music box?

I'm a student at the HKU in The Netherlands. I study Game art there and for a project called "If This Then That" we were going to create something creative with an arduino kit.

I've been very fascinated by music boxes for a long time and after some research on them I've found out that there are no music boxes that have a Video Game theme ( at least I couldn't find one ). So I've decided to make one! And in the following steps you can see how I did it and make one of your own maybe!

Step 1: The Code That I´ve Used for This Project.

Here is all my code that I´ve used for this project.
It has multiple comments which will give further explanation about what that part of code actually does.
Just copy and load this code into your arduino UNO.

//#define DEBUG //uncomment this to enable debugging in


#include // Library for shield

#include // Library for sd card on shield

#include // Library for sd card on shield

#include // Library to control shield

#include // Special Library for controlling the servo

//create and name the library object

SFEMP3Shield MP3player;

SdFat sd;

SdFile file;

VarSpeedServo servo;

// Define pins and such

int sensorPin = A0; // Light Sensor connected to Analog0

int sensorValue; // variable to store the value coming from the sensor

int servoPin = 5; // Pin controlling the servo

int Led1 = 3; // Led 1

int Led2 = 4; // Led 2

int randomnr; // Random number for choosing a song from the song array we use later

boolean firstSong = 1; // This is so the first track on the sd card will always play first when booting up the arduino

void setup() // run once, when the sketch starts


Serial.begin(115200); // initialize the serial port

pinMode(A0, INPUT); // sets analog pin A0 to be an input

pinMode(Led1, OUTPUT); // sets pin 3 to be an output

pinMode(Led2, OUTPUT); // sets pin 4 to be an output

if(!sd.begin(SD_SEL, SPI_FULL_SPEED)) sd.initErrorHalt();;

//boot up the MP3 Player Shield



void loop() // run over and over again


sensorValue = analogRead(sensorPin); // read the value from the light sensor

delay(250); // Wait for a short moment

#ifdef DEBUG

Serial.print("Light Sensor Value: "); // send that value to the computer


Serial.print("Boolean Value first song: "); // send that value to the computer

Serial.println(firstSong); // send that value to the computer

Serial.print("Light detected: ");



if(isLightDetected(sensorValue)) //Light Detected function is true


if(!servo.attached()){ // We got to check if the servo is attached, so it will not attach it everytime it loops. This is made so we can stop the servo spinning as well when there is not enough light



digitalWrite(Led1, HIGH); //turns on led connected to pin 3

digitalWrite(Led2, HIGH); //turns on led connected to pin 4

delay(500); // Wait half a second for turning on the servo...


if(firstSong == 1) // Check if song hasnt played before, if so start it up!


char firstsong[] = "track001.mp3";




#ifdef DEBUG

//Serial.print("Boolean Value after song: "); // send that value to the computer

//Serial.println(firstSong); // send that value to the computer



randomnr = random(0,5); //random number generated for choosing a song from the array

//Song array for the music to be choosen random

char* trackArray[] = {







MP3player.playMP3(trackArray[randomnr]); // Play the song!

sensorValue = analogRead(sensorPin); //Read value from sensor to see if it still has enough light

#ifdef DEBUG

//Serial.print("Light Sensor Value After Loop: "); // send that value to the computer




else //No Light Detected


#ifdef DEBUG

Serial.println("Not enough light detected shutting everything off"); //


//Stop everything!


digitalWrite(Led1, LOW); // Turn of leds

digitalWrite(Led2, LOW); // Turn of leds




//Function to help us test if sensor conditions are met

boolean isLightDetected(int sensorValue) {

if (sensorValue > 50) {

return true;


else {

return false;



Step 2: Materials ( What Do We Need )

Here can you see my Fritzing image, we need this for later so save it and keep
it close!

Step 3: Modifying Your Servo.

Normally a Servo 9G can only rotate 180* and than returns to its original position, but we want it to fully rotate so we are going to modify our Servo.

To do this I've watched several youtube video's and destroyed one Servo in the process.
So watch out, this is hard and delicate work.

Links to tutorials:
Also here is a Instructable to do this:

Step 4: The Box, or Something Similar.

For this project I´ve scouted my city for something pretty and usefull.
Its not neccesary to use the same as mine as long as its pretty deep, so you could make your own!

For inside the box I've made a wooden construction inside to hide the Arduino and the other components.
On the picture you can see how I've made it.
The whole I drilled but don't forget to keep the wooden circle so you can use this as the rotating platform for your 3d model!

On the 3rd and 5th Pictureyou can see how i've made a construction to place to servo in.
This is so the platform rotates and not the servo, I've place the servo between some wooden blocks and nailed it in the wood. Also for even more safety I've used some tight ribbon for extra support.

Also the 5th picture Shows how the final result should be, I know I've used some tape here and there you can do this prettier but it worked for me.
Also you notice there is a hole left in my box, this is because of the cable so you can easily take it anywhere and plug it in a adapter and use it!

Also make a tiny hole somewhere for the light sensor, on the 5th picture you can see in the top right corner I've made a hole for the sensor so it sticks out and is visible inside the box to check the amount of light.
Without this sensor it is not going to work.

Step 5: 3D Printing Your Model.

For 3d printing you can go to a 3D printing store or look if you can print your model somewhere in the neighbourhood.
After printing you can paint your model like I did, I've used an Airbrush for painting my model.

Be sure that you dont print it to big, it has to fit on the small wooden rotating platform!
Also watch out the model doesn't get to heavy because the servo's are not that strong.

Step 6: Now We Need Some Music.

Now we need music.
Sadly, I can't share the Halo songs over the internet because of copyright.
So you need to buy these soundtracks or you know...

When you do have the soundtracks or any other music you like you name them as following:

Track001 = Always the first track the music box will play ( look it up in the code )
Track003 Etc...

The other tracks will be played randomly when shutting and opening the box.

Step 7: Final Product Video.

Here is a video link to my final product.

I hope you likes my instructable!