DIY USB Midi Controller With Arduino: a Beginner's Guide
by dolcewang in Circuits > Arduino
81777 Views, 276 Favorites, 0 Comments
DIY USB Midi Controller With Arduino: a Beginner's Guide
I love MIDI Controllers! They are some of the coolest yet most powerful devices for controlling mixed media - traditionally used to connect to music software (like Ableton Live) to play virtual instruments as well as control effects - but can also be used with VJ software (like Resolume), and even lighting control programs (like Lightjams)!
If you haven't already, check out the above video to see the finished DIY MIDI controller in action with Ableton! ☝️☝️ And as a bonus, here's me VJ'ing using the controller.
The exercise of completing this project helped me to gain the skills to grow from a Novice Tinkerer to at least an Intermediate one. It really got my feet wet in the world of Arduino, electronics, and even some product design. I hope that it would do the same for you!
This project is great for anyone who…
- … wants to understand what's under the hood for MIDI Controllers
- … is getting started with Arduino, and looking for a fun project to grow your skills
- … is on a budget, but still want to build a cool piece of gear (MIDI Controllers can be pretty expensive)
- … wants to learn more about electronics
- … would like to learn how to customize your own MIDI Controller layout
- … is curious about how electronics can make music, effect video, etc...
- … simply loves MIDI Controllers as much as I do!
So let’s dive in!
Setup
I've broken down the process into several smaller steps below - mostly so that I could also provide more photos and video to fit the Instructables layout.
But firstly, I wanted to just say that building the MIDI Controller comes down to 3 basic categories:
- The Enclosure
- The Circuit
- The Code
Some of you will have strengths in certain categories more than others, so feel free to skip around based on your goals. However, I will be writing this tutorial to an audience who may only have a basic tinkering knowledge of each one, but hopes to grow just as I did!
--
Secondly, it's always a good idea to prototype first. I won't detail all the steps for prototyping to save redundancy, but in reality, I did several prototypes with a breadboard before actually putting it together. This helped me to understand the Circuit and Coding better because those were my areas of weakness. In fact, I started off with a 2 Button, 1 Knob, 1 Fader prototype and worked my way up!
--
Lastly, which Arduino should you choose??
With the wealth of options out there, it can get overwhelming. After testing and analyzing several different Arduinos, I finally decided on the Pro Micro (designed by Spark Fun) for the following reasons:
- It uses the atmega32u4 microcontroller (Pro Micro, Micro, Leonardo…), which allows for:
- Easier Programming - right out of the box, it is set up as an “HID device” aka USB keyboard
- I wanted to use USB for communication rather than the old-school 5-pin MIDI jack, which is the standard setup for UNO and other boards using the atmega328p processor (like Mega, Nano, Bluno…)
- After you upload your Arduino sketch (the code) to your board, it works right away!
- The UNO and other atmega328p boards can work through USB via Serial communication... but that means either 2 extra programs are running in the background to translate these different digital languages, which adds more room for error while eating up a bit of your CPU 🙁
- ...OR you can hack the board, but that method seems even more trouble than it’s worth to even type out. 🙁🙁
- The Pro Micro is still cheaper than the other options, even with the better microcontroller
- The size is super compact
- The number of Analog / Digital pins still suited my design requirements, even while being tiny!
-
I would actually have preferred the Arduino Micro (also atmega32u4), but it’s slightly larger and I didn’t need all the extra pins
For a more thorough comparison of boards, you can check out this link.
With all that said, most beginners use the Arduino UNO for learning, and don’t have access to other boards - so I will add a few notes on how to get the UNO working as well. Although I don’t recommend it for the final product, it is certainly adequate for prototyping and you don’t need to squint as much!
Ok, so now let’s scavenge for some supplies...
Stuff You Will Need
Luckily, the Required tools and materials actually needed for this project are pretty basic! However, there are several recommended Optional items that would make your life much easier if you happen to have or want to add your collection.
Also, I found a lot of materials in mom & pop electronics stands while being stranded in Taiwan due to COVID-19 (that is a whole other story!), or at the dollar store. I tried my best to find equivalent Amazon links appropriate items, but please note that I used whatever I could find since there’s no Amazon here. Feel free to adapt as well!
SUPPLIES
- Required
- B10K Potentiometers (B = Linear); aka "Pots"; aka fancy word for Knobs and Faders
- (4) Knobs and Caps
- (4) Sliders/Faders and Caps
- (4) Momentary Push Buttons
- (2) Small Wooden Trays (or whatever you would like to use for your Enclosure)
- "Arduino" / Development Board
- Electrical Wire 20-30 AWG, Solid Core
- Small Zip Ties
- B10K Potentiometers (B = Linear); aka "Pots"; aka fancy word for Knobs and Faders
- Optional
- (1) 5mm LED Indicator light + Resistor (330 Ohm is just fine)
- Alternatively, this kit seems cool - comes with the above, including other prototyping items for about the same price
- (1) 5mm LED Mount
- Wood Stain (water-based to reduce odor)
- Velcro with Adhesive
- Rubber Footpads
- Small Screws for mounting
- Spare Blocks of Wood
- Breadboard
- (1) 5mm LED Indicator light + Resistor (330 Ohm is just fine)
TOOLS
- Required
- Soldering Iron + Solder
- Wire Strippers
- Drill and Drill Bits
- Sandpaper
- X-Acto Knife
- Metal Ruler
- Screwdriver
- Monkey Wrench
- Needle Nose Pliers
- Glue
- Patience!
- Optional
- Digital Caliper
- Helping Hands (they really help!)
- Heat Shrink Tubing (1-3mm is ok depending on your wire size)
- Step Drill Bit
- Tweezers
- File
- Hacksaw
- Clamps
- Basic Woodcarving Kit
- Soldering Flux Paste
Enclosure - Design and Prep
Designing how you want to lay out all your components in advance will save you a ton of headache later on when trying to fit everything into a small Enclosure.
As a prelude to the CAD drawing, I prepped the box with wood stain so I could do the design while it was drying. Water-based stain is really nice so that it doesn't overwhelm you with fumes (unless you like that sort of thing), and it is easier on the skin. Brushing lightly and giving it 2 coats did the trick. Then I let it dry for 24 hours.
Ok, back to the layout!
Here are the steps I took for Design and Prep:
- Simply place all the components on the box just to give a visual sense of spacing. You can then roughly measure their locations with a ruler to give you a starting point.
- Measure some more! This time with more accuracy. The two main purposes are:
- Figure out what size holes you need to cut (Measure all the barrels of the Knobs, Buttons, and LED; and also the Fader slots)
- Determine if you can fit everything inside (Measure the outer dimensions of all the components as well as the Pro Micro)
- Draw!
- I used Sketchup to do my layout, but you can easily use Paint or other software... or better yet, draw it by hand!
- Again the two most important views are the Overall Layout (how it all fits), as well as the Cut Holes (where to drill/cut into the box)
- Get it on paper to create a pattern ✏️
- If you already drew it by hand, awesome! If you did a digital sketch, you can either print it to scale... or be lazy like me and zoom in to scale, then trace the center points of each hole directly on my monitor.
- Note: For the Faders, I planned to drill a small hole on the top and bottom of each slot as well, so I only had to mark those center points
- Then I did a quick sketch of the hole outlines and wrote in the dimensions
- If you already drew it by hand, awesome! If you did a digital sketch, you can either print it to scale... or be lazy like me and zoom in to scale, then trace the center points of each hole directly on my monitor.
- Cut out the pattern, tape it to the top of your enclosure, and then push through each of the center points with a pointy object (in my case, I used tweezers). This will easily mark the placement of where you need to drill directly onto the box!
As a shortcut or reference, you can also download a PDF of my Cut Holes layout from this Instructable. My box was 14x14cm with a 5mm wall. If you have a different sized enclosure, you can do the scale and trace trick according to your dimensions since you only really need the center points. Just make sure everything still fits and that you still write down the hole diameter sizes.
Now on to the drilling!
--
Note: For UNO users, you will be limited to 6 Potentiometers (combination of Knobs and Faders) because the UNO only has 6 Analog pins. Definitely keep this in mind as you design, and especially before you start to drilling... otherwise you will have some gaping holes! Buttons are ok since they use Digital pins. If you are using a different board, double check the number of Analog / Digital pins as well to see your limitations. Here is the pinout diagram for the UNO.
Downloads
Enclosure - Make Some Holes!
Hope you are ready to do some damage... but very carefully of course. 😉
- The Holes
- After using your nifty pattern to locate each center point of the holes, you can use a small drill bit to make pilot holes. I used a 2mm drill bit. This helps to prevent much fraying when using a larger drill bit.
- You have some room for error with the holes because the Knobs, Buttons, and LED all have mounting screws that will hide a little of your edge if it's not perfect
- When making the larger holes, I used a step drill bit for the same reasons. You can also work your way up to the appropriate diameter
- It's important to drill from the top of the Enclosure because the back end will have more fraying after you drill through. That's why we traced the pattern from the top as well.
- The Slots
- Cutting Fader Slots requires much more precision because the edges will be exposed
- My fader slots measured out to be 3mm wide so I used a 3mm drill bit
- I then used an X-Acto knife and Metal Ruler to carve out the slots along the tangent of the holes. The thickness of the wood was only 1mm so this worked out great
- If you have a thicker piece of wood, then you could be really careful with the hacksaw -- or if you have access to a lasercutter, then you are golden!
- USB Hole
- You can use the same method of making the Fader Slots to make the USB hole for the Pro Micro - use the 3mm drill bit and X-Acto Knife method.
- One tricky thing though, is that the USB port probably won't be long enough to reach the USB cable head on the other side. You could make a larger hole to fit the entire head, but then it would expose the inside of the Enclosure if the cable wasn't plugged in.
- Instead, I roughly carved out a slot from the inside, so that the Pro Micro could be pushed into the Enclosure wall, just enough to reach the USB plug.
- Definitely check out the photos, as it will illustrate this better!
- Sand all the edges
- If you cut a small piece of course sandpaper (I used P220) and roll it up, it works really well to get these edges nice and smooth
- Touch it up
- You can touch up the edges using a small paint brush and wood stain, or even a brown permanent marker if the tone matches
- You only need to touch up the fader slots, but I did the holes as well because... why not?
- Test the size
- Insert one of the components (like a Knob) to check the sizing. If all the steps were taken carefully, it should fit like a glove!
Enclosure - Assembly
Ready to place everything in? Here are some guidelines:
- It was helpful to draw the components on the inside of the box to remind myself of where everything should go
- Mounting the Knobs, Buttons and LED were very simple because they just use hex screws. Nothing like a good Monkey Wrench to get them nice and tight. Just make sure they are the correct orientation!
- I added wooden blocks to either side of the Knobs to keep them from rotating if they got loose.
- Fader Mounting was the hardest because I was trying to make the design so that it could also be disassembled
- If you don't mind the permanence, you can simply hot glue the faders on!
- If you want more flexibility in the future, or just like a challenge, you can easily make some shims with scrap wood and I even used old SIM cards for more precision
- Pro Tip: I found a fake baby Jenga set at the dollar store, and have used these wooden pieces for many DIY projects. In this case, I cut them into small blocks with a clamp and hacksaw.
- Normal white glue worked well for the wood pieces and SIM cards to lock down the placement of the Faders.
- In order to keep it secure from behind, I used small screws and brackets that I found laying around. You can totally be flexible here on the method - just make sure that both the top and bottom are even secure. If they are metallic, it is also a good idea to wrap it in electrical tape or heat shrink tubing for insulation.
- Snapping Feature
- The wooden blocks also work very well to snap the Top and Bottom halves of the Enclosure in place. Since they are glued flush against the inner perimeter of the box, it keeps the two halves nice and snug. Four of the previously glued pieces used to secure the Knobs and Faders already double as snapping blocks as well (2 on both Left and Right sides)
- Then on the Bottom half of the Enclosure, I added a single piece on both the top and bottom edges (see photo)
- You can round off the corners of these blocks so that the halves can align more easily
- Pro Micro Mounting
- Stick some velcro on the back of the Pro Micro as well as its designated area in the Enclosure!
- I added a wooden block to secure it into place so it wouldn't get pushed in when the USB cable was plugged in. To make it detachable, I filed out a small rounded groove so that it could also be snapped out of the case as well (see photo)
- Add some Rubber Feet!
Now it's time to get a snack before we move on... to... the... Circuit!!
Circuit - Wire It Up!
Since I personally get dizzy looking at electrical diagrams, I made several of my own visual diagrams to help break up the wiring process into bite-sized chunks. Please take a look at them, as I think the visuals provide a clearer map to the wiring strategy - better than I could do in writing.
I will also start calling Knobs and Faders: "Pots” (aka Potentiometers). For electronics and coding, they behave the same way, so they have this fancy name.
If you weren't confident in soldering before, this will definitely get you up to snuff!
Here are some helpful tips for this process:
- Pro Micro Header Pins
- You could solder directly to the board without header pins if you are confident that this Pro Micro will be dedicated to your controller. It can also save space in your Enclosure.
- If you want flexibility, solder the header pins onto the side that has all the electronics (usually they are soldered to the other side with pins going down underneath so that you can use it with a breadboard)
- Stick the longer end of the header pins into a breadboard
- Place the Pro Micro upside down (electronics facing down)
- Solder the corners first
- Then solder the rest of the pins
- Wiring
- Follow the visual diagrams to map out your circuit
- Start with the Ground (black wire) - what's cool is they can be daisy-chained
- Next solder the +5V Power (red wire) - these can also be daisy-chained!
- Solder all the Signal wires last - they go directly to your Arduino
- Pots go to Analog Pins
- Buttons go to Digital Pins
- Usually, colors follow the rainbow or from lightest to darkest
- Leave some slack so they can be reorganized
- It's a good idea to use heat shrink tubing at the soldered joints to prevent shorting out. They can shrink from the heat of your soldering iron.
- I used colored jumper wires so I could connect to the header pins easily. Unfortunately, the bare wires inside have a stranded core (hairy), which breaks much easier when soldered. I ended up shortening the wires to length so that they still had female and male tips, and making a loop with the male tip to solder to the components
- LED
- Don't forget the 330 Ohm Resistor so your LED doesn't burn out! Add to the side of the long leg
- Short leg goes to Ground
- Long leg goes to Power
- Make Your Life Easier With...
- Soldering Flux Paste - add a glob with a toothpick, apply it to the joint, get some solder on your iron, and wipe the solder on the flux. It will absorb the solder so you only need one hand!
- Helping Hands. Enough said.
- Fitting into the Enclosure
- If you use header pins, they may be too long for the Enclosure to fit tightly. I bent the pins on one side of the Pro Micro at a 45 degree angle and it worked great!
- If you are using jumper wires, you also may need to cut some of the back ends of the plastic female tip to fit better.
- Close the Enclosure
- Close the two halves and listen to that baby snap in place!
- Add the Knob and Fader Caps
- Ok, this is not part of the circuit, but better to add them afterward to avoid scratching
- Moment of Truth
- Plug in your USB cable and see if your LED lights up. If it does, that's a GREAT sign!
Can you believe it? Your MIDI Controller is nearly complete!!
--
Note: For UNO users, Pots will go to Analog Pins A0-A5
Coding
Get ready to complete your MIDI Controller!
Fortunately, you won't have to do much programming since I already created the sketch for you! In the best case scenario, you would just need to download the attached file (use the one that says "Atmega32u4" in the name) as well as the MIDIUSB.h library... and you are good to go!
I would like to thank Gustavo Silveira (aka Music Nerd), as the sketch is heavily modified from his version.
If you are new the Arduino environment, then follow these guidelines:
- Make sure you have installed the Arduino IDE to upload sketches (code) to your Arduino
- Download and Open the sketch I provided: "midi_controller_Micro_Atmega32u4_DW_v2.ino" and Save it to the proper location on your computer
- Add the Pro Micro board to your listGo to Arduino < Preferences... (File < Preferences... for PC)
- Paste this URL to the Additional Boards Manager URLs text field "https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json"
- Add the MIDIUSB.h LibraryGo to Tools < Manage Libraries...
- Search for "MIDIUSB" by Gary Grewal
- Install the latest version
- Assign the Pro Micro boardGo to Tools < Boards < Sparkfun AVR Boards... Select Sparkfun Pro Micro
- Go to Tools < Processor... Select ATmega32U4 (5V, 16 MHz) -- **Make sure you select the correct voltage, otherwise you will need to reset your Pro Micro
- Go to Tools < Port... Select the correct port (mine says /dev/cu.usbmodemMID1, PC will probably say COM)
- Click Upload (the Arrow on the top Left corner)
- Wait until the bottom status bar shows Upload Complete!
CONGRATULATIONS! YOU MADE IT!!! 🎉🎉🎉🎉🎉
---
If you feel courageous 💪 you can also start changing parameters in the Code, such as Number of Buttons / Pots, Digital / Analog Pin assignments, and even MIDI Notes! (See photos)
---
Note: For UNO and other atmega328 users (Nano, Mega, Beetle...), follow the remaining steps by scrolling down to the Appendix 👇👇👇
Bonus: Map to Ableton and Resolume!
Now that you are technically done building the MIDI Controller, of course you want to start playing right away!
Many of you are doing this project to use with Ableton Live for music... and some may even want to use with Resolume Arena for VJ'ing! They both have trial versions if you are interested in checking out.
The layout of each software is slightly different so please reference the images attached if needed - however, what's great is the MIDI mapping logic is nearly identical!
Here's how to map the controller if you don't know how:
- Open up Ableton or Resolume with your MIDI Controller connected
- In Ableton, you should see the yellow MIDI light flicker (top right corner) when you press the buttons or turn / slide the Knobs / Faders!
- Go to Live / Arena < Preferences... (File < Preferences... on PC)
- On the MIDI Tab, you should see your Pro Micro listed under as "SparkFun Pro Micro"!
- Ableton - Under Input, Turn ON both the Track (for instruments) and Remote (for mapping)
- Resolume - Turn on Input
- On the MIDI Tab, you should see your Pro Micro listed under as "SparkFun Pro Micro"!
- Map the Controller
- Close the Preferences window
- Open the MIDI Map Mode
- Ableton - Click "MIDI" on the upper right corner to start mapping
- Resolume - Go to Shortcuts < Edit Midi...
- Purple (Ableton) or Green (Resolume) areas indicate parameters you can map the controller to
- Click on any parameter (like a Clip, an Effect, Volume, etc), then move a Knob or Fader, or push a Button -- whichever control you would like to map the parameter to
- The control is now mapped!
- Repeat until all the controls are mapped
- Close MIDI Map Mode (Same as Opening)
Now you can use your controller to make music AND be a VJ!!!!
Final Thoughts
A BIG pat on the back for everyone who has made it this far. It really takes some diligence to get all the details finished, but it's well worth it in the end! 👍🎊🎊🎵
I hope you can expand on this tutorial and really make it your own. Can't wait to see what you all come up with! As for me, I am already chomping at the bit to turn this into a Bluetooth controller... 😃
Until next time!
- Dolce
APPENDIX
Here you will find a few more resources, including the final steps of how to get the Arduino UNO working!
--
Coding for Arduino UNO (and other atmega 328 boards)
UNOs and other atmega328 boards (like Nano, Mega, Bluno...) can only use Serial Communication via the USB port, rather than direct MIDI communication. That adds a few more steps... but never fear! It still works!
- Download the "Midi_Controller_Atmega328_Uno_DW_v2.ino" File (attached)
- I have already modified the sketch for 6 Pots and 4 Buttons
- Install the MIDI library (different from Pro Micro!)
- Upload the Sketch!
- Go to Tools < Boards < Arduino AVR Boards... Select Arduino UNO (or your board)
- Go to Tools < Port... Select the correct port (mine says /dev/cu.usbmodem14621, PC will probably say COM)
- Click Upload (Arrow icon on Top Left corner)
- Wait until the bottom status bar shows Upload Complete
- Install Hairless MIDI to Serial Bridge - Mac + PC friendly - allows Serial <-> MIDI to talk back and forth
- Update: Looks like this app won't work with Mac Catalina+ anymore... found a potential Python alternative
- Install / Setup a Virtual MIDI Bus - essentially a digital MIDI cable to connect different software on your computerFor Mac, this is already a default feature! It's called IAC Driver (see attached image)
- Search and Open your Audio MIDI Setup Application
- If the MIDI Studio window isn't already open, go to Window < MIDI Studio
- Double click the IAC Driver icon - the uploaded image says "IAC Dude" because I had renamed it 😎
- Check off "Device is Online" to enable it; You can also change the Device Name
- For PC, Install LoopMidi
- Open Hairless MIDICheck off Serial <-> MIDI Bridge On
- Under Serial Port, Select USB ACM
- Under MIDI Out, Select your IAC Driver (Mac) or LoopMidi (PC) virtual bus
- You should see the green lights flickering - that means it's working!
- *Note, you will need to disable Hairless if you want to upload a sketch to your Arduino again
- Now your IAC Driver (Mac) or LoopMidi (PC) bus will show up as the MIDI input device on Ableton or other software you may be using!!
- Have fun!!!
--
MIDI Monitor - for Mac users, this is a really handy software that just lets you visually see what your controls are doing
--
If would like to assign specific MIDI notes to your controller (say you wanted to build keyboard instrument instead), I also attached a useful MIDI Note Chart