Introduction: Arduino MIDI Foot Pedal Keyboard

About: I'm an Electrical Engineer working out of Northern California with a never ending interest in repairing and creating.

The Origin

My dad is a musician. He can play a multitude of instruments. However, he only has two arms, BUT he also has legs! That's when we decided that we would reuse the foot pedals from an old organ and convert them into an arduino powered MIDI keyboard. Now he can easily play electric guitar and fill the empty sound with excellent bass notes produced from his QS8 Quadrasynth.

An Introduction to MIDI

MIDI stands for Musical Instrument Digital Interface. As you can guess, it conducts all operations digitally. MIDI doesn't send sound frequencies as instruments do. MIDI works generally with two parts: a controller and a synthesizer. The controller is what is manipulated by the musician and sends serial data to the synthesizer.

The MIDI controller does not make any sound on its own. It REQUIRES some form of a synthesizer. The synthesizer decodes the serial data and produces sound based on the given data.

MIDI data is commonly sent in three parts: the MIDI channel (up to 16 channels can be used at once), the note, and the velocity (basically the volume of the note or how loud you want it to be).

Step 1: Materials

Materials

-Organ (to salvage foot pedals from)
-Two ATmega328 ICs with arduino boot loader
-Seats to place the ICs in once soldered.
-Two 16 MHz crystals
-Four 22pF ceramic capacitors
-Perf board
-Power supply and adapter for ATmega ICs
-220 Ohm resistor
-Pull down resistors for the Pedals
-MIDI cable or Female MIDI connector
-Arduino and USB cable (for programming the IC.  A separate programmer can be used in its place)
-Computer for programming
-Solder and Soldering Iron
-Wire Strippers and cutters
-Potentiometer (Potentially the volume pedal salvaged from organ [see what I did there?])
-At least twenty six pin connector (salvaged from organ)
-Wire

I ordered my arduino parts, crystals, powersupply, and capacitors from http://cutedigi.com.  Use a common 12V power adapter to power the powersupply.  I can't imagine this project drawing much current, so I'm sure a 500mA power adapter will suffice.

Step 2: Obtaining the Foot Pedals

What a steal!

The organ used in this instructable is a Wurlitzer organ.  My dad found it on craigslist and picked it up for $25!!  Everything worked, but he didn't care for the tone.  The pedals, however, were perfect.  There are twenty five keys and the switches are built into the pedals instead of mounted inside the organ with the pedals hitting the switches.  Also note how the switches use magnets to connect the switch.  These switches will be almost impossible to wear out!  Consider taking the volume pedal as well.  It controls a potentiometer, which is pertinent to our interests!

This organ has an interesting version of a Leslie speaker.  That might be used for another project on another day.

Step 3: Making a Dual Stand-Alone Arduino

The foot pedals chosen in this project has twenty-five notes.  The ATmega 328 (the one I use) has at MOST 20 digital inputs (including using the analog inputs as digital inputs.)   One is used for sending the MIDI data.  This leaves 19 digital inputs for the pedals.  Instead of using an AVR that has more inputs, I found it easier to buy two ATmega 328s and run them together.  The inputs were split 13 in one and 12 in another.

The 16 MHZ crystal is connected to pins 9 and 10 of the IC.  One capacitor is also connected to pin 9 and then to ground, while the other to pin 10 and then to ground.

Solder the IC seats, powersupply, crystals, capacitors, and connector down to the perf board.  Print out the picture of the ATmega Arduino pinout.  Write whatever you used to label the pedal wires down on each.  My dad simply labeled them like the notes: C, C+, D, D+, E, etc. (+ meaning #) This will help with the programming step.    Send a +5V wire to one side of all the pedal switches.  The returning wires from the pedals are wired to the digital inputs of the IC.  Be sure to include pull down resistors on the inputs for the pedals.

When the MIDI cable is being wired to the board, only three pins are used of the five: +5V, GND, and a serial transmit on digital pin 1 (pin 3 on the IC).  A 220 Ohm resistor needs to be wired between the +5V and MIDI output to prevent damage to the synthesizer or MIDI sequencer.

Analog pin 5 on both ATmegas are wired to the middle pin of a potentiometer. In my case, the potentiometer was in the volume pedal of the organ.  The other two pins of the potentiometer are wired to +5V and GND.

The following list depicts the schematic. Please excuse the redundancy of re-listing the parts.

----------------------------------------------------------------------------------------------------------------------------------------
C1 	Ceramic Disk Capacitor 	package THT; rated voltage 200V; capacitance 22pF; capacitor type Ceramic
C2 	Ceramic Disk Capacitor 	package THT; rated voltage 200V; capacitance 22pF; capacitor type Ceramic
C3 	Ceramic Disk Capacitor 	package THT; rated voltage 200V; capacitance 22pF; capacitor type Ceramic
C4 	Ceramic Disk Capacitor 	package THT; rated voltage 200V; capacitance 22pF; capacitor type Ceramic
DIN1 	DIN-5 jack (MIDI) 	package THT; form jack (female); pins 5
J1 	Generic double row male header - 28 pins 	package THT; hole size 1.0mm,0.508mm; row double; form ♂ (male); pins 28; pin spacing 0.1in (2.54mm)
R1 	220 Ω Resistor 	package THT; tolerance ±5%; bands 4; resistance 220Ω; pin spacing 400 mil
R3 	390 Ω Resistor 	package THT; tolerance ±5%; bands 4; resistance 390Ω; pin spacing 400 mil
R4 	390 Ω Resistor 	package THT; tolerance ±5%; bands 4; resistance 390Ω; pin spacing 400 mil
R5 	390 Ω Resistor 	package THT; tolerance ±5%; bands 4; resistance 390Ω; pin spacing 400 mil
R6 	390 Ω Resistor 	package THT; tolerance ±5%; bands 4; resistance 390Ω; pin spacing 400 mil
R7 	390 Ω Resistor 	package THT; tolerance ±5%; bands 4; resistance 390Ω; pin spacing 400 mil
R8 	390 Ω Resistor 	package THT; tolerance ±5%; bands 4; resistance 390Ω; pin spacing 400 mil
R9 	390 Ω Resistor 	package THT; tolerance ±5%; bands 4; resistance 390Ω; pin spacing 400 mil
R10 	390 Ω Resistor 	package THT; tolerance ±5%; bands 4; resistance 390Ω; pin spacing 400 mil
R11 	390 Ω Resistor 	package THT; tolerance ±5%; bands 4; resistance 390Ω; pin spacing 400 mil
R12 	390 Ω Resistor 	package THT; tolerance ±5%; bands 4; resistance 390Ω; pin spacing 400 mil
R13 	390 Ω Resistor 	package THT; tolerance ±5%; bands 4; resistance 390Ω; pin spacing 400 mil
R14 	390 Ω Resistor 	package THT; tolerance ±5%; bands 4; resistance 390Ω; pin spacing 400 mil
R15 	390 Ω Resistor 	package THT; tolerance ±5%; bands 4; resistance 390Ω; pin spacing 400 mil
R16 	390 Ω Resistor 	package THT; tolerance ±5%; bands 4; resistance 390Ω; pin spacing 400 mil
R17 	390 Ω Resistor 	package THT; tolerance ±5%; bands 4; resistance 390Ω; pin spacing 400 mil
R18 	390 Ω Resistor 	package THT; tolerance ±5%; bands 4; resistance 390Ω; pin spacing 400 mil
R19 	390 Ω Resistor 	package THT; tolerance ±5%; bands 4; resistance 390Ω; pin spacing 400 mil
R20 	390 Ω Resistor 	package THT; tolerance ±5%; bands 4; resistance 390Ω; pin spacing 400 mil
R21 	390 Ω Resistor 	package THT; tolerance ±5%; bands 4; resistance 390Ω; pin spacing 400 mil
R22 	390 Ω Resistor 	package THT; tolerance ±5%; bands 4; resistance 390Ω; pin spacing 400 mil
R23 	390 Ω Resistor 	package THT; tolerance ±5%; bands 4; resistance 390Ω; pin spacing 400 mil
R24 	390 Ω Resistor 	package THT; tolerance ±5%; bands 4; resistance 390Ω; pin spacing 400 mil
R25 	390 Ω Resistor 	package THT; tolerance ±5%; bands 4; resistance 390Ω; pin spacing 400 mil
R26 	390 Ω Resistor 	package THT; tolerance ±5%; bands 4; resistance 390Ω; pin spacing 400 mil
R27 	390 Ω Resistor 	package THT; tolerance ±5%; bands 4; resistance 390Ω; pin spacing 400 mil
U1 	atmega328 	package DIP28 (Dual Inline) [THT]; version Atmega328-20PU; type ATMEGA328
U2 	atmega328 	package DIP28 (Dual Inline) [THT]; version Atmega328-20PU; type ATMEGA328
XTAL1 	Crystal 	package THT; frequency 16 Mhz; type crystal; pin spacing 5.08mm
XTAL2 	Crystal 	package THT; frequency 16 Mhz; type crystal; pin spacing 5.08mm

Step 4: Writing the Code

First, I researched all over the internet about MIDI communication and commands.  Luckily, I had experience from my previous project: my Arduino MIDI drum set.  I used the same set of code for the bass drum pedal that is used on all the organ foot pedals.

When a pedal is pressed, the command is sent to turn on the note at a certain velocity.  The potentiometer (volume pedal) is used to determine that.  It gives values from 0-1023.  The map function is used to proportionally map that number to another number between 0-127.  To turn a note off when the pedal is not pressed, the same command for that note is sent, except the velocity is 0.

Having the arduinos send that command when a pedal is pushed using an "if" statement in the loop would work except it would send that command every time the loop repeats when the pedal is down.  If the "else" statement is also used to send the command to stop the note (velocity 0), then the arduinos would send that command for every pedal that's not pressed every time the loop repeats.  The arduinos and synthesizer couldn't handle sending or receiving all that data.

To fix this, the arduinos must send the command to play a note ONCE after the pedal is pressed.  They must also do the same for when the pedal is released.  In order to do this, the arduinos must "remember" the last state (pressed or not-pressed) the pedals were in the last time the loop repeated.

To add that feature, I made a "last state" variable.  The first thing the arduinos do after sensing when a pedal has been pressed is compare the last state they were in to the state they are now.  This makes it possible for the arduinos to send the command for a note ONCE when it has been pressed and ONCE when it has been released.

Because there are two Arduinos, there are two programs that are written.  It's simply copying the first one and pasting it into a new project and changing all the notes.  Remember that one program will use one more note than another!

BOTH Arduinos need to send commands on the SAME MIDI channel.  I used MIDI channel 1.

To get the arduinos to send MIDI data read over this guide: http://arduino.cc/en/Tutorial/Midi.  I don't send the notes or velocity in hexadecimal.  Decimal works perfectly because the Serial.write(); command sends it as a byte.

There are two programs attached in the zip file; one for one ATmega, another for the other.

Step 5: Programming the ATmegas

Insert one of the ATmega ICs into the Arduino to program it.  Try not to press it into the seat all the way or else it will be hard to remove.  After it's programmed, use a small screwdriver to pry it loose slowly, starting on one end, then the other, back to the other end, etc. until it is removed.  Place it onto the newly made circuit board.  Be sure you put the IC that is programmed for 13 notes in it's place and not in the 12 note place IC seat.  After both ICs are programmed and placed on the board, it should be ready to connect to the foot pedals!

Step 6: Hook It Up! Try It Out!

Wire the other end of the connector to the pedals and plug it into the circuit board and the foot pedals together.  Also, plug the MIDI wire into the synthesizer and the power adapter into the power supply on the circuit board.  Power up the synthesizer and start playing!

Step 7: Enclose and Finalize the Project

You may use whatever you desire to enclose the exposed electrical parts.  We used some scrap wood that remained from the organ.  Also, we used the power switch and power indicator light from the organ.  Using the volume pedal from the organ was a thought that occurred after realizing how much of a pain it is to turn a potentiometer with your feet.  It's recommended that the volume pedal is used.

Step 8: Video Demonstration

Here is a video demonstrating the Arduino MIDI Foot Pedal Keyboard's functionality.  Don't mind me trying to get the potentiometer to budge! The bare potentiometer was later replaced with a volume pedal.

Thanks for reading! Happy Building!