Electronic Music Box Powered by Arduino (sort of)

Box Powered by Arduino

Music is the most universal means of expression. Regardless cultural language or age the idea conveyed though music would not differ much. It is safe to say everyone loves music, one type or another. When one’s favourite piece is played there is a overwhelming desire to get involved and turn on one’s Air Guitar.

Box Powered by Arduino

Not being familiar with any type of musical instrument myself. Moving my hand insanely in the air and imagining my virtual tone lines up perfectly along the music was the best I could do.
Why not put my engineering degree to use. Design something able to play music without any training, minimal music knowledge but still get that person highly involved.
Music box seems like a good start. The music is actually ‘played’ in real time, unlike mp3 music player which merely convert a string of data to time varying voltages. However the music storage method has to be changed, a drum with pins poking out does not allow much customization. If the music is stored on file we are back to the mp3 player, but if the music is on a piece of paper…..Now we are talking.
Hence the Electronic Music Box was conceived.
What you will need:

2 proto boards or PCBs
LM7805 5V regulator
ATmega328 or Atmega168 microcontroller
16 MHz crystal with 2x22pF cap
Or forget about the two above if you use an Arduino
3 X LM324 opamp
14 X IR LEDs
14 X IR photodiodes
10K potentiometer
50k potentiometer
3.5mm headphone jack
MCP4911 10bits DAC
20 ways Right angle male heading connector
20 ways Female header connector
Various capacitors and resistors
Optional, mechanical:
6V motor with gearbox ~ 30RPM
Rollers, more on that later 

Youtube link here

Step 1: Preliminary Design

Preliminary Design

How is the music stored on a piece of paper?
The simplest way is to divide a piece of paper, a certain width, into equal width columns and each represents a musical note of some sort. Kind of like musical notes on sheet music.
Notes are marked by pen and the duration of the note, or break, is controlled by the length of that mark.
The paper with music notes should look something like the photo below.
How does the unit read this paper?
A simple vision would be useful. Infrared, less likely to be distorted by our normal lighting is a great solution. Like visible light the dark mark on the sheet absorbs IR light while the blank passes most of IR through.
With this in mind the only thing we need to do to differentiate the two is a level comparison on the IR photodiodes.
How do we generate musical tone?
Since is fully electronics, the best tone generation method is that employed by mp3 players. Using a fast DAC or digital to analog converter to create the right voltage at a given moment, we can get a pretty smooth analog tone.
This method also allows any kind of waveform to be generated. It opens the possibility of polyphony.

Step 2: Circuit theory

The actual circuit design is not complex at all, only a lot of repetition. My design is split into two parts: Infrared sensor array and the main board.
The IR gate array is pretty simple. It’s just made up of a roll of 14 IR LEDs with a roll of 14 IR photodiodes facing each other. Why 14? Well it covers 2 Octaves and that is all I can manage to fit on that protoboard.
The IR sensors array provides 14 voltage levels according to the sheet and the circuit has to identify the marked notes. Thus we will need voltage comparators and that is where LM324 comes in. Strictly speaking LM324 is operational amplifier not voltage comparator but it can do the job just fine.
The choice of this IC is not based on its performance. Single supply, from 3V, having 4 amplifiers in one package is the main driving reason for the choice. Low power and low cost are also great bonus.
After the LM324 arrays convert the 14 IR gate signals to the simple HIGH or LOW digital signals. Then microcontroller takes over and does what it does best – calculation.
Based on the incoming signal, the microcontroller looks up on the waveform tables stored in its flash and grab the right voltage level appropriating to the moment in time. Since everything is software achieving polyphony is fairly easy. It is simply addition of all the voltage data.
The micro then passes this information to MCP4911 10bits DAC for the analog signal generation.

Step 3: Construction – IR gate arrays

This is a very simple part of the build but absolutely essential. The spacing between the IR LEDs must be kept constant. I am using a proto board with a standard pad spacing of 2.5mm, thus each LED is 5mm apart. A slot of 75mm is milled between the LEDs and photodiodes. This slot will allow the music sheet to pass through and be read. This board will be connected to the main board via header connectors. A row of 20 way right angle male header, not those straight ones in the photo, should be soldered and connected to the LEDs and photodiodes as shown in the circuit diagram. There is a reason I didn’t specify the value for the resistor R1 – R14. The value of these resistors will be our tuning points later on, at the moment use 100Ω for every one of them.

Step 4: Construction – Main Circuit Board

Building the main board has no drama. You can choose to have an ATmega328/168 with Arduino bootloader on the main PCB, like the one I have. Or you can build the circuit without the microcontroller and its crystal to suit the Arduino board of your choice.
I have included the EAGLE files of the project, schematic and PCB layout is all done using the free version. You can make any change to the design as you want.

Tune the circuit
Since these cheap IR LEDs and photodiode are not made to the tightest tolerance, the variation will be significant enough to cause some false detection.
To correct this you will need a multimeter. Connect the IR gate arrays to the main board and power the system up through the power jack socket J1. Use your multimeter to check the voltage across the resistors R7 – R20. Their voltage should be more or less the same. If one is higher than the majority by about 100mV the resistor value for the according IR LED should be increase to offset the difference. If one is lower, then lower the corresponding resistor value should equalize it.

Read more: Electronic Music Box Powered by Arduino (sort of)

Leave a Comment

Your email address will not be published. Required fields are marked *