This instructable was created in fulfillment of the project requirement of the Makecourse at the University of South Florida (www.makecourse.com).

Welcome to my MAKE course final project at the University of South Florida. This instructable will detail my process to developing a light sensitive instrument that can be played via light exposure. Funny thing is, I originally wanted to design a music box, but with some last minuet alterations, created a playable instrument. I will of course show you both functions, although the music box is still in a rough stage of development. I couldn't get the box to work correctly due to difficulties producing disks and the stepper motor acting up, but it did function to a degree so I will give enough information here to get everyone started on their path to creating this device without the huge hassles I dealt with.

This project deals with Arduino programming, 3D printing parts, and some mild understanding of hardware. But don't worry, all files, code, and details on how to build the machine will be given step by step, so this should be easy.

Step 1: Concept of the Music Box

Lets begin with my original idea of the music box.

So what we have here is an electrical version of a traditional hurdy gurdy sort of crank music box. We've all seen one at some point if you've torn open a snow globe or your sisters's jewelry box. Its a barrel with a bunch of little pins sticking out of it that pluck a tiny keyboard looking thing. Pretty simple right? Not really. Attempting it myself, I found that there is some pretty annoying physics involved when trying to get the activation of a tone just right. Maybe you can come up with a better way to do this, but I came up with something close to a record player.

This is sort of a mouth full so I'm going to break down this machine from bottom to top.

At the bottom, there are several led lights that supply a direct light source to the machine. This supplies a reliable amount of light so the machine can function at max efficiency. Thing is, this machine has a threshold of light in order to correctly call notes. I will talk about that later when we get into the code. But for now, just know that this machine works best in a dim environment so its main light source are the leds.

In the middle, we got the 3D printed disk set on a motor to spin like a record so all the holes can pass through the system and create music. Besides the creation of the disk, this is relatively simple. There is a stepper motor with the shaft pointing up so the disk can be laid down on top like a record. Pretty easy.

The top of this machine will consist of a row of photo resistors that act like the keyboard of the music box. These things pick up the light and call the frequencies based on what combinations they are activated, and how much light they are exposed to. This will be where all the programming for the notes comes into play. You can create any note you wish and however many you want based on how many photo resistors you have to arrange.

Step 2: Lets Get Technical ---- Hardware Breakdown

So with all that in mind, and having a general idea of how this thing works, I'm going to gut this machine and show all the nitty gritty bits of hardware this runs with. Its all pretty cheap stuff.

To recreate my machine you'll need the following:

  1. An Arduino UNO micro controller
  2. A 5V stepper motor and a driver
  3. 6 red leds
  4. 6 photo resistors
  5. 6 220 ohm and 6 10k ohm resistors
  6. A piezo buzzer
  7. Some solderless breadboards and solderles digital pins(both male and female)
  8. An appropriately sized housing for the leds and motor to sit on
  9. A 3D printer (If that's impossible, you can try to fabricate it another way. I trust in your creativity.)

You'll also want to download the Arduino compiler so you can upload the code to the Arduino. Its completely free from the Arduino website so no worries. http://arduino.cc/en/main/software

Step 3: The Formal Circuit Layout

This step will give you a more detailed visual of how all the components are hooked up.

The flow of power will run from the Arduino as the main power source, and will move from the large breadboard to the small one via the digital pins.

Step 4: Arduino Code

At this point, I hope you got the Arduino compiler I told you about earlier. Anyway, here I will post my finalized code for the whole music box mechanism. Know that no alterations need to be made to the code for it to change to the instrumental adaptation.

I will also include my file that helped me learn how to write simple musical jingles with the tone function. In the one that I made, I developed the song Fur Elise. You can change tempo, how many notes you want, how long you want it, exactly what frequency each note is, etc. You have a lot of control, but that also means there is quite a bit to mess up. So I'll be elaborating on what could go horribly wrong so you don't feel my sorrow.

Just in case you can't open the Arduino code files, I attached some documents that you can just copy and paste the code from instead. It should work the same way. (The FinalFinalFinal_attempt2 = Finalized Arduino Code.... They are the same thing so don't get confused.)

So I'm just going to let you know how to change what you need to change in order to make other songs and do other cool stuff with it.

I'm going to start with the Finalized Arduino Code part since that is our main sketch here after all (I'll ask you to have the code open while you read this so you can see what I'm talking about). At the top of the sketch you will see pins for your stepper, a delay time for the stepper, sensor values for the photo resistors, and the pin for your piezo. ALL of which need not be touched necessarily. But just below that pin for the piezo "const int buzzerPin = 5;" , you will see all the important integers for the musical portion.

int duration will allow you to change the duration of notes and how long they are held out. i.e. how long each loop takes to process.

int threshold will allow you to alter the amount of light intake that is necessary for the photo resistors to activate and play a note. The higher it goes, the more light they need to activate. If you need to change this value because its not responding to the light you need it to, you can check the serial print readings and check what amount of resistance they read at a base level without light, and then with light. You can then place the threshold at some level between that.

int photoResistPins[6] = {A0, A1, A2, A3, A4, A5}; Theres a couple of things you'll want to note here. First and foremost, I don't know for sure if you can use any more than six photo resistors for this project if you're using an Arduino UNO. For the very simple reason that a photo resistor runs of of an analog pin and there aren't enough analog pins on the UNO. Maybe with a micro controller with more of them we could create even more note possibilities, but as of this project with an UNO, we will use only six resistors. But still, that leaves us with something around 30 to 40 notes or more. Its still pretty good. So this function is going to be the one where you assign the photo resistors their own pins. The A means its an analog pin on the Arduino.

int onValue[6] = {1, 2, 4, 8, 16, 32}; This line just assigns the bool values for each combination of notes so the later code can determine which photo resistors are being activated. Don't tough this unless you are adding or subtracting photo resistors for some reason.

So in the void setup we really don't need to change anything because there is nothing there that could be altered to get new notes or anything. So we just won't bother with that. However in the void loop we can touch on the switch case function that goes through and determines which note to play based on the input it receives. You should see a long list of things called "case 1....case2......case3....... etc." that detail each possible note frequency based on what photo resistors are being exposed to light. Here you can change frequencies of notes as well as how many notes there are available to be played, as well as what combinations of photo resistors are required for each note.

IMPORTANT: Remember that line of code up at the top where we assigned bool values to each photo resistor? This is where it becomes important. For each note combination, we need to add together the bool values for each photo resistor we want to be activated in order to play the frequency in that specific case. So for instance, the difference between "case 1" and "case 7" is that "case 1" is just the first photo resistor (A0 which has bool value of 1) exposed to light while "case 7" is a combination of three photo resistors (A0, A1, and A2 = bool values of 1, 2, and 4). If you add that up it had a value of 7. Thats why its "case 7" and only activates when those three photo resistors are exposed to light.

Knowing all that, you can go ahead and make more note combinations by adding different combos of the bool values for each photo resistor. You may also change the frequency value just below it.

That's all you really need to worry about in that sketch so have fun experimenting with it!

And just for fun I'll include my Fur Elise sketch that you can use to just have a piezo play a song for you. In it, you can specify how many notes you want, of what frequency you want the notes, how long you want the song to be in terms of beats, the tempo you want, and it lets you write the song in a single long line of code. as seen at the top. Eventually I started switching between capital and lower case letters since they can count as different variables. Have some fun playing with that too. I believe to start working on that I took base code from the Arduino library of examples. You can find this by going to File, Examples, then 02.Digital, and you'll see tone functions at the bottom.

Step 5: Printed Part Specifications

Here I'll attach the .stl files I used in this project. Of course you may need to alter them if you change the box used. Since that may be the case I'll just let you know what everything is for so you can make your own if necessary.

RIG - The rig I speak of is the housing outside the box that holds the photo resistors. It is a two part over hang that drapes over the spinning disk and allows for direct exposure from the leds to the photo resistors. The top part where the photo resistors go can be tricky. The holes on top have to be large enough to fit the photo resistor, but the bottom of the hole must be small enough to not let the photo resistor through.

Disk - This disk is about a six inch diameter and the holes should be about 3 to 4 mm in diameter. Also pay attention to the dimensions of the stepper motor's shaft so you can model the center hole just right for a not too loose fit.

Flute Mod - The "flute" adaptation is basically the same as the top of the rig set up, you just need to create more space between the holes. Mine was about 160 mm long and had about 23 mm of space between each hole. These specifications are arbitrary. However, the thickness of the flute is NOT. It needs to be thick enough to hold the entire photo cell inside. I made it about 25 mm thick and it works just fine.

Step 6: Assembly

Once you have created all your necessary parts, and tested the hardware to see if it works with the code, you can begin the assembly of the main attraction.

Place the Arduino and the small breadboard with the leds inside the box so they fit in accordance to the holes you drilled in the sides of the box for the wires. I would suggest wiring up the Arduino after you place it in the box so you don't forget to put all the wires through the holes first. Also make sure the leds are placed directly under the photo resistor housing so we know we're getting direct light exposure through the disk. Lets not forget the bottom half of the rig that holds up the photo resistor housing. Just snap that on the bottom of the box and place the top of the rig for the photo resistors on the prong of the bottom rig.

Now we can place the stepper with the rails on top of the box. You also need to properly align this as well so the holes of the disk match with each of the holes for the photo resistor housing. If this is off my more than a couple millimeters, the song may not play.

That's that! assuming you got a disk that works, you can go ahead and try it out!

Step 7: How It SHOULD Be Functioning

At this point, we have our components, our code, and our printed parts ready to go. So theres isn't much more manual labor left other than setting it all up for testing.

As the late Bob Marley once said, turn the lights down low, and set the stepper and the disk in the appropriate place so the holes line up, and let it rip. If its not making any sounds, there are a few things you might want to check:

  • Are the lights able to make direct contact with the photo resistors? (check the alignment of the disk and the photo resistors.)
  • Are the wrong combinations of the resistors being activated? (check the serial print window for the resistance values.)
  • Is the breadboard wired correctly? (Check all the wires and make sure there aren't any loose wires that got unplugged or fried. Do the same for all the resistors.)
  • Does it sound like poo? (try putting some tape over the top of the piezo and poke a little hole in it so it can oscillate properly. This should make the sound less grainy.)
  • Not getting a reading from the photo resistors? (If you're using the wires that stick onto the surface of the bread board like I did, make sure if you're plugging in the photo resistors on the other half somewhere, that you get the wires to go completely across to the other side. For some reason I thought my breadboard was wired all the way across, but it only worked if you sent the wire from one side to the other where the resistor was. Its weird.)

Step 8: My Last Minuet Flute Mod

We have established the primary goal of this project. But now its time to make something a little more interactive. I'm just going to give a brief break down of how to turn your music box into a playable instrument. This may require you to create a different top mount than before. I have attached the .STL file of a simple flute design in step 5 so you can get an idea of what might be a good place to start.

All I've done for this is take the arrangement of the photo resistors and made the space between them greater. For this mod, we're gonna have to tape the wires to the side of the "flute" so the photo resistors do not fall out of the holes. It might not be pretty but it functions just fine. All you have to do to make it work is perform the patterns that the disk would normally do by itself in the music box.

I'll also attach my "sheet music" so you guys can see how I planned out the music in the first place. Honestly, you can alter the fingerings to whatever you desire, I just had no interest in making my fingerings any easier so I left it.

The blue things sticking out the top of the flute are rolls of blue painters tape I used to lodge in the holes. Its a great method to make sure the photo resistors stay inside without a bunch of interference with its playability. Just make sure its a real snug fit, and that its not causing the two bare wires of the photo resistor to touch and cause interference. That can happen if you're rough with it.

This thing is dope! However I would suggest the use of a visible laser if you ever have the opportunity! Then you'll be able to see the lasers come down into the box, and you won't have to worry about surrounding light. You'd probably need laser specific light sensors to do the job though.<br><br>Great work over all!!! :)
<p>Great work on the code, must have been tricky to figure out all by yourself!</p><p>Also, 6 analog sensors = 2^6 = 64 possible notes.</p>
Thank you mysterious stranger. I am quite proud of my work. It is the best out there. Good enough to get into MIT. Maybe I'll see you there some day. Roflroflroflcopter
<p>This is a really neat project! </p>
Thanks man this took me forever to get done. Hey if you have any questions at all please let me know. I want to make this instructable as straight forward as possible. And if anything is unclear let me know.

About This Instructable




More by Kyle Fitzsimmons:LED Music Box / Light Instrument 
Add instructable to: