Introduction: Looping Music Synthesizer

Picture of Looping Music Synthesizer

This project was based off of an instuctable by Amanda

Hassaei at the following link:

https://www.instructables.com/id/Electronic-Instrum...

Thank you for your insight on this project!

Also note that I used some photos from her instuctable.

This music box allows you to create music by pressing buttons! Each of nine buttons will play a stored sound—a note, chord, drumbeat, or whatever else you can think of. Also, at the flip of a switch, you can record and play loops. Thus, you could also use this as a metronome, or a loops station, or whatever you want! A knob controls the tempo of the loop, and beats are synchronized with a blinking LED. The box has two different modes—a normal mode and a record mode, indicated by different color LEDs. There is also a volume knob, on-off switch, mute switch. Music is output into headphones, or a built-in speaker. Super cool, right!

Here are the parts that you will need(what I used):

1. Arduino Uno

2. Aduino ProtoShield

3. Small PC Board

4. 9 button switches- any momentary switch will work!

5. 10KOhm Audio Control Potentiometer

6. 3 Toggle switches- any small switch that disconnects and connects two ends

7. 50KOhm Linear Potentiometer

8. 2 220microF 35V Electrolytic Capacitors

9. 2 100 nF capacitors

10. 9 n914/4148-Type Diodes

11. 5 2KOhm resistors

12. 10 10KOhm resistors

13. 8 20KOhm resistors

14. 4.7KOhm resistor

15. 1KOhm resistor

16. 5KOhm resistor

17. 9V battery

18. 9V battery snap connectors

19. Amber Super-bright LED

20. White Super-bright LED

21. 1/8” Stereo In-Line Audio Jack

22. LM386 Low Voltage Audio Power Amplifier

23. 8 Pin Socket 276-1995

24. speaker

25. headphones

Other stuff you’ll find handy:

Wire

Solder

Drill

Plastic box (or any box to hold all the stuff)

Electrical tape

Ohm-meter

Wire cutters

Label Maeker

Step 1: Buttons

Picture of Buttons

First, lets start with the buttons. To read 9 buttons, we will make the Arduino check if each button is pressed using a multiplexing technique so that we only need 3 (well, actually 6) pins. Here’s how it works in English:

- One of the three digital pins turns off, and the other two are set high

- This one pin connects to three different buttons, and each button goes to a different analog in. Diodes are used to make sure current only flows in one direction.

- If a button is pressed, then current will flow from the 5V across the resistor to ground, and all the voltage will drop across the resistor. Therefore, the analog in corresponding to that button will read zero voltage, so this button will be triggered as “on.” If the button is not pressed, then no current will flow through, thus there will be no voltage drop across the resistor. In this case, the analog in reads 5V and remains set to “off.”

- The same thing happens with a different digital pin off and the other two on.

- Then it does this once more with the last digital pin.

- The Arduino does this so fast, that it’s essentially simultaneous to us humans!

For this part, you will use:

- 2 2KOhm resistors

- all the buttons

- all the diodes

- Arduino pins A0,A1,A2, 8,9,and 10

Note that my buttons are flipped across the y-axis compared to the circuit diagram. But it works the same way.

Troubleshooting:

- Make sure diodes are facing the right way! The line on the diode should be pointed towards the digital pins.

- Be sure that the analog pins are on the correct side of the resistors

- Be sure that wires that aren’t suppose to be touching aren’t touching.

- Be sure that you wire the buttons correctly (use an Ohm meter to check)

Step 2: LEDs

Picture of LEDs

Next, lets put in the LEDs. LEDs are diodes, so make sure they are facing the right way! Note that you don’t need to use the same colored LEDs I used, but different LEDs will want different-sized resistors. For my box, I used a white LED with a 4.7KOhm resistor, and an amber LED with a 1KOhm resistor. The positive (long) end of the white LED goes across the resistor to digital pin 12, and its negative side goes to ground. The other LED is wired in the same way, but to digital pin 11 instead of 12.

Troubleshooting:

- LEDs must be facing the right way

Step 3: Digital to Analog Converter, Amplifier, Headphone Jack, and Battery

Picture of Digital to Analog Converter, Amplifier, Headphone Jack, and Battery

Now, lets tackle the digital to analog (DAC) converter, the amplifier, the headphone jack, and the battery. These are all connected, so I think its best to look at them all together. To understand how this works, we must look at what the code is doing. At a frequency of 8000Hz, the Arduino, based on any buttons that were pressed, takes a number between 0 and 255,inclusive, and converts that to an 8-digit binary number(e.g. 182 = 10110110). This binary number gets output, in terms of 5V=1 and 0V=0, to the digital pins 0-7. The DAC effectively sums up the readings and sets the output voltage, between 0 and 5V, proportional to 0-255. We will call the “middle” voltage 127, corresponding to the output of 2.5 V, which allows the fluctuation to be both positive and negative. Now every 1/8000 of a second, the Arduino changes this voltage, and this change in voltage is passed through low-pass and high-pass filters (capacitors) to filter out some noise. Finally, the waveform is amplified and converted into the vibrations that are heard in the earbuds.

For this part, you’ll need:

- all the 20KOhm resistors

- all the 10KOhm resistors

- the 5K resistor

- the 2 100nF capacitors

- the two 220microF capacitors

- the 9V battery and its snap connectors

- the amplifier

- the 10KOhm potentiometer

- a switch

- earphones or a speaker

I also added a speaker in addition to my headphone jack. The headphone in jack I used had an out connection when nothing is plugged into it, so I attached these to an small speaker, and fed the other end of the speaker into ground. However, this “speaker” doesn’t get very loud. If you plan on installing a speaker to your box, you’ll have to use a bigger amplifier, and in that case, be careful that you do not blow out your headphones.

Troubleshooting:

- make sure your capacitors are the right size

- make sure all the resistors are the right size

- make sure the volume pot is attached correctly- the high end should go to pin 5 on the amplifier, the middle should go to the earphones, and the low should go to ground.

- Make sure pins on the amplifier are attached correctly—pin 2 to ground, pin 3 between the voltage divider of 20kOhms and 5kOhms, pin 4 to ground, pin 5 to the capacitor, and pin 6 to 9V.

Step 4: Switches and Tempo Potentiometer

Picture of Switches and Tempo Potentiometer

All right, now lets wire the switches and tempo potentiometer.

You will use:

- 2 toggle switches

- 2 2KOhm resistors

- The 10KOhm potentiometer

For the switches, connect a 2kOhm resistor to 5V, and then the other end of the resistor to BOTH one end of the switch and A3/A4 on the output. The mute switch goes into A4, and the record switch goes into A3. Connect the other end of the switch to ground. For the tempo pot, connect the high end to 5V, and the low end to ground. Send the middle pin on the potentiometer to A5 on the Arduino. It’s probably a good idea to understand how these work. When the switch is open, no current flows through the circuit, therefore, no voltage drops across the resistor, meaning the analog pin reads 5V. However, when a switch is closed, current flows through, and all voltage drops across the resistor. This makes the reading at the analog pin 0V. The potentiometer can be thought of as a “voltage divider;” turning the knob changes the amount of resistance that’s on each side of the middle pin leading out to A5. The Arduino will read a voltage, between 0 and 5V, which will change depending on the position of the potentiometer.

Step 5: Put It in a Box

Picture of Put It in a Box

Once everything is attached to the protoshield, attach the Arduino into the correct pins. Now, you are ready to put your circuitry into a case. I used this small grey plastic box that was lying around. The layout of all your switches and knobs is really up to you. I drilled holes in the top of the box for the LEDs and the buttons. I also cut out a hole for the speaker. On the front of the box, I put the mute switch, record switch, and tempo pot. On the back of the box, I put the audio out jack, the volume pot, and the on/off switch. I also cut out a hole in the back, so that I could plug in my Arduino to the computer without taking it out of the box. I would suggest using a box that’s a little bigger than the one I did, because I barely made everything fit. I also used electrical tape to make the box a little sturdier, and add some design. Be creative here! I also labeled all my switches, knobs, and jacks with a label maker.

That’s it for the hardware! Now, upload the code to your Arduino. The code is posted below. Once this is uploaded, everything should work! Here are some things to note:

1. The
sound quality isn’t the best. The sound wave is getting generated at a frequency of 8000Hz, which is not very clear, but sounds should be recognizable. At first, my sound was coming out really messy, but I fixed this by putting in the right sized capacitors.

2. Make sure switches are wired the right way, as I noted in the step. At first, I wired the ground end straight into the analog in, which doesn’t work.

3. Be careful with the all the wire connections, especially wherever you solder and bend wires. If one connection is broken, something won't be working right.

4. Don’t turn the tempo pot too fast. Your Arduino will need time to update.

5. Don’t try recording too much—the length you can record depends on the tempo you have set. If you try recording more than it can handle, the Arduino will play the first sound you recorded once, and that’s it. You will need to reset the Arduino (by turning it off and on) if you’d like to try recording again.

Step 6: Upload the Code

Upload the code onto the Arduino. To do this, download one of the attached programs, and click the "upload" button in the top left corner. All of these files are essentially the same, just with different audio samples in each. You can hear what each code has in the videos I made that are on the intro page. Besides the audio samples, the code I used is written by Amanda Ghassaei.

Ukebox: I recorded audio samples of common ukulele chords in the key of C.

BillyJeanbox: This has guitar notes to play the loop in Michael Jackson's "Billy Jean."

Reggaebox: Here, you can loop a reggae beat in F, and make up a riff with a few brass notes.

Step 7: Creating Your Own Audio Samples

Picture of Creating Your Own Audio Samples

Create your own audio files!

1. Download Audicity

I was working on a mac, but I’m sure there is a similar download for windows if you google it. I got it from this site:

http://audacity.sourceforge.net/download/mac

2. In the bottom left corner of Audicity, set the “Project Rate (Hz)” to 8000. Also, in the top right corner, set the input (next to Built-In Microphone) from “2 (Stereo) Input Channels” to “1 (Mono) Input Channel.”

3. Record your audio in audacity. Be sure to keep it short—the Arduino can only hold up to about 4 seconds of total sound, so each audio recording should be less than half a second if you want to utilize all 9 buttons.

3. After you’re happy with your sample, go to FileàExport. Save the file as an mp3 in a place you can easily find. Before finishing the export, Audicity might tell you to find certain folder. Follow the link, download the folder, click browse, and find the folder to point Audicity to its location in your computer. The link I used to get this folder is below:

http://lame.buanzo.org/#lameosxdl

4. Now that you have your recording in an mp3 file, you’ll need to convert it to a byte array. To do this, I used a program downloaded from the following link called “Encode Audio”

http://highlowtech.org/?p=1963

Follow the instructions on the website to download the program.

5. Run Encode Audio, and choose the audio file you created. After a second or two, a window should open that says “Audio data copied to clipboard.” This means the code has been stored into the memory you use to copy and paste.

6. Go to the your code in the Arduino window. Near the top of the code, you’ll see:

byte sample0[] PROGMEM = { number, number, number,…} ;

byte sample1[] PROGMEM = {number, number, number, …};

etc...

highlight all the numbers within the { }, and replace it with the numbers stored in your clipboard by going to “Edit Paste.”

Be sure the end of your array has ", } ;". If not, you will get an error.

That’s it! Have fun! Happy looping!

Comments

craftclarity (author)2014-05-28

Nice small package too! Is it set up for stage performances?

About This Instructable

2,891views

37favorites

More by scotttan808:Looping Music Synthesizer
Add instructable to: