How to Build a Simple DIY USB MIDI Controller Using Teensy

Teensy is similar to Arduino, but perhaps better suited to making a USB MIDI controller. Liam Lacey shows how to make your own DIY MIDI controller using Teensy with 8 retro arcade push buttons.  

When teaching DIY MIDI controller development I usually recommend using the Arduino platform due to its large user community and the extensive amount of learning resources. However there is a similar hardware platform that is actually better suited and easier to use for building USB-MIDI controllers, which is also more powerful at a cheaper price; the Teensy platform. The only downside of using Teensy compared to Arduino is that there just aren’t as many examples or tutorials in regards to MIDI controller development, therefore I’ve written this tutorial to help overcome this shortcoming and aid in highlighting Teensy as a great hardware platform for the audio/MIDI maker community.

A Teensy microcontroller board 

A Teensy microcontroller board 

In this tutorial I’m going to show you how to build a simple MIDI controller that consists of 8 retro arcade push buttons for sending MIDI message, as well as a toggle switch for choosing whether the arcade buttons send note message or CC messages. It may seem like this controller has limited functionality compared to commercial MIDI controllers, however this project will serve as a good introduction for developing more complex controllers but without throwing you in at the deep end. Here is a video example of what you’ll be building: 

A Teensy-based DIY USB-MIDI controller demo. First the buttons are sending note messages to trigger drums samples, and then the toggle switch is used to set the buttons to send CC messages to trigger effects. This demo uses Ableton Live and the Sugar Bytes Turnado plugin.

Parts list

  • A Teensy board. If you’re on a budget get the Teensy LC, else if you think you may want to do more complex Teensy projects in the future I recommend the more powerful Teeny 3.2. Make sure you get a Teensy with pins, unless you fancy soldering them on yourself.
  • 8 arcade push buttons (though any large push buttons will work).
  • 1 SPST toggle switch 
  • A solderless breadboard
  • An enclosure. This could be any small sturdy box around the house, or a multipurpose project box.
  • Hookup wire. Stranded 7/0.2mm would be best, though solid core 1/0.6mm or something of a similar size would also work. Preferably of different colours, but not essential.
  • USB Micro-B cable
  • Led-free solder (optional)
  • 28 pin 0.6” IC socket (optional)
  • Stripboard (optional)

Tool list

  • Wire cutters
  • Wire strippers or scissors
  • A tool for making holes in the enclosure. Scissors/craft knife will be fine for cardboard enclosures, however you’ll probably need a Dremel (or something similar) for plastic or wood enclosures.
  • Soldering iron (optional)
  • Safety glasses (optional)
  • Stripboard cutter (optional)

Step 1—Connecting Wire to the Buttons and Switch

First you need to cut 18 pieces of wire; each of a length that will allows buttons inserted into the top of your enclosure to be connected to a place in the bottom of the enclosure, but with a lot of slack so that the inside of the enclosure can be accessed without the buttons being disconnected. It would be preferable for half of the wires to be black and the other half to be of various other colours to make wiring the circuit less confusing, however this is not essential. Then strip about 1-2 cm of plastic off each end of each wire; wire strippers are best to use here however it can also be done with scissors. If you are using stranded wire twist the ends to stop them from fraying.

Stripped wire

Stripped wire

Next you need to connect a pair of wires to each button and switch so that they can be connected to the Teensy. Each button/switch should have two pins/connectors on the bottom, and this is where the wires need to be connected. If your switch has three pins just ignore one of the side pins. You want to connect one black wire and one coloured wire to each button/switch; the orientation doesn’t matter. To connect them simply twist the metal wire securely around the pin, threading it through the hole if there is one. 

Wire connected to a pin of an arcade push button

Wire connected to a pin of an arcade push button

Finally I strongly recommend that you solder these wires into place. If you are unable to get hold of a soldering iron and the wires are firmly twisted and connected you may be able to skip this part, however the only way to ensure that the connections won’t become disconnected throughout this project is to solder them. If you’re new to soldering I recommend watching this video to learn how to solder, however it is fairly simple and main involves the following process:

  1. Add a small amount of solder to the iron tip
  2. Place and hold the iron tip on the connection/joint you want to solder (in this case the button/switch pin and the wire)
  3. Touch the end of the solder reel onto the joint, but not the iron tip.
  4. When the joint is hot enough the solder will melt onto it.
  5. Lift the solder reel and iron off of the joint a give it a few seconds to dry

Please solder in a well-ventilated area and use safety glasses!

Wires soldered to the pins of an arcade push button

Wires soldered to the pins of an arcade push button

Step 2—Building the Circuit

First lay your breadboard horizontally and place the Teensy on either side but with the USB port facing outwards. Make sure the Teensy is over the middle divider of the breadboard. Next cut and strip a short bit of black wire that is long enough to reach from the Teensy to the blue/black/negative strip along the side of the breadboard. Connect this wire from anywhere on the negative strip to the terminal strip connected to the ground pin on the Teensy—this is the bottom far-left pin if the USB port is on the left, or the top far-right pin if on the right (labeled ‘G’ on the Teensy LC).

A Teensy LC on a breadboard with the ground pin connected to the breadboards negative terminal 

A Teensy LC on a breadboard with the ground pin connected to the breadboards negative terminal 

Lastly you need to connect all the push buttons and the switch to the Teensy. The toggle switch needs to be connected to digital pin 0 which is next to the ground pin, and then the push buttons to digital pins 1 to 8 that are the following pins on the same side. Connect the coloured wires to the breadboard terminals connected to these pins, and then connect all the black wires to the breadboards negative strip (see below photos).

The toggle switch and push buttons connected to the breadboard 

The toggle switch and push buttons connected to the breadboard 

And that’s the circuit complete. Simple, huh? If you’ve done some electronics before you may have expected that we would need a resistor between each button/switch and the microcontroller, however Teensy boards have built-in pullup resistors on each pin which means no external resistors are needed. This makes circuit building simpler, and is one of the lesser-known advantages of Teensy over Arduino. 

Step 4—Writing, Compiling and Testing Code 

Now the circuit is complete, it’s time to get the software-side working. To develop for Teensy you need to download and install two pieces of software:

  1. The Arduino application
  2. The Teensyduino Arduino software add-on

Once both bits of software have been installed complete the following steps:

  1. Connect the Teensy board to your computer via the USB cable. If it is a brand new Teensy the onboard LED may now be flashing.
  2. Launch the Arduino application
  3. Go to File -> New to open a new Arduino project
  4. Replace all the text in Arduinos text editor with this code
  5. Go to Tools -> Board and select the specific Teensy board you are using. If you cannot see the Teensy board section go back and make sure you correctly installed Teensyduino.
  6. Go to Tools -> USB Type and selected ‘MIDI’.
  7. Go to Sketch -> Verify/Compile, or instead just click on the tick icon on Arduinos toolbar.
  8. If no errors appear in the console pane at the bottom, the Teensy software window should pop up. If this did not happen and errors appeared, go back to point 1 and carefully follow the instructions again.
  9. As stated in the Teensy software window, press the button on the Teensy board to put it into Program mode. The LED should no longer be flashing.
  10. In the Arduino software go to Sketch -> Upload, or instead just click on the arrow icon on Arduinos toolbar.
  11. If the upload was successful the Teensy software would have shown a progress bar followed by ‘Reboot OK’, and no errors would have appeared in the Arduino console pane. 

If you are having trouble getting things working, see the official Teensy ‘getting started’ guide. Also note that when re-uploading code to the Teensy you can skip point 9.

The Arduino software configured for Teensy USB-MIDI development

The Arduino software configured for Teensy USB-MIDI development

You are now ready to test the circuit. Open up your DAW/MIDI software of choice, connect to the MIDI device called ‘Teensy MIDI’ (or something similar), and start pressing the arcade buttons. Each button should send a different MIDI note or CC message, and when you flip the toggle switch they should start sending the opposite type of message. If some or none of the buttons are working go back over the circuit and make sure all the connections are correct, as well as checking that the wires are securely connected to the buttons. 

Step 5—Inserting Electronics into Enclosure 

Congratulations! You have just built a working DIY MIDI controller! However right now it is probably a sprawling mess of wires over your desk making it not very playable. To fix this you need to move the circuit into an enclosure and insert the buttons/switch into the top of it.

First you need to make 9 holes in the top of your enclosure to hold the arcade buttons and switch. Arrange the holes for the arcade buttons in two horizontal lines of four with the toggle switch on either side of this. You also need to make a small hole on either side for the USB port. 

My enclosure – a painted corrugated cardboard box with holes cut out for the buttons, switch, and USB port.

My enclosure—a painted corrugated cardboard box with holes cut out for the buttons, switch, and USB port.

Next you need to remove the buttons/switch from the breadboard (but remember where they connect to) and insert them into the holes. Your particular arcade buttons will either have a nut or two springy tabs to fasten them to the enclosure, though your switch will most probably have a nut and washer.

The push buttons inserted into the enclosure

The push buttons inserted into the enclosure

Finally you need to insert the breadboard into the enclosure and reconnected the buttons and switch. From left to right and looking at the top of the enclosure, connect the top row of buttons to digital inputs 1–4 and the bottom row to 5–8.

The breadboard inserted into the enclosure 

The breadboard inserted into the enclosure 

Now close up your enclosure, making sure no wires become disconnected in the process, and your DIY MIDI controller is finished! 

The finished DIY USB-MIDI controller 

The finished DIY USB-MIDI controller 

Step 6—Moving to Stripboard (optional) 

If your new controller is just going to stay on your desk it will be fine to leave it how it is. However, if you plan to take it on the road with you, you may find wires will start becoming disconnected from the breadboard. To prevent this from happening you will need to replace the breadboard with a piece of stripboard that requires all connections to be soldered. See this guide on how to use stripboard. I recommend connecting the Teensy board to the stripboard via an IC socket (28 pin, 0.6” wide) so that the Teensy can be easily removed from the circuit, which allows you to easily replace it if it breaks or remove it for another project if needed.

Moving the circuit onto stripboard

Moving the circuit onto stripboard

Conclusion 

So that’s how you can make a simple DIY USB-MIDI controller with Teensy and a really simple circuit. With Teensy you can connect a large number of different controls and sensors and create highly complex and customizable MIDI controllers—just take a look at the Teensy projects page to see all the amazing Teensy-based audio and MIDI devices that people have made.

Liam is the Head Of Development specialising in software development at Modal Electronics, the company behind the 002, 008, CRAFT and SKULPT synthesisers, and was previously the lead software developer at nu desine, the developers of the AlphaSphere MIDI controllers. He was also an Associate Lecturer at UWE, Bristol, UK where he gradua... Read More

Discussion

Chris
Can this code be modified to use more than 8 buttons if so how many could be used. I think I see a total of 24 digital lines, one is of course used for the toggle. I could be reading it wrong though.

Can a dual color LED be hooked up so you know what mode you are in (CC or Note) or can a small LCD display be hooked up to do the same thing?

Liam Lacey
Yes the Teensy LC and 3.2 has 24 digital pins, so you could have up to 23 arcade buttons and 1 toggle switch.
You'll then need to change the NUM_OF_BUTTONS value in the code as well as other places that this value is used.

The simplest way to use an LED would be to use a single colour LED where 'off' is one mode and 'on' is another, where only 1 digital pin would be needed. A bi-colour or RGB LED could also be used, but involves a more complicated circuit. An LCD display could also be used - see https://www.pjrc.com/teensy/td_libs_LiquidCrystal.html.

charnjit
Hello sir , do you know about FL studio ???? I want to make my own very small usb midi contoller for FL studio with your help. I want to tell you about functioning of my device by a picture(i draw) ,,,,how can i post comment with picture??? Thank you
Liam Lacey
I don't think you can post pictures here unfortunately. I would recommend uploading the picture to an image hosting website such as imgur or photobucket and posting a link to the image here.
Daniel6610
Hello.
Great article. I have created a smaller version of this to control vMix software on my Windows 10 laptop. The buttons work great but I would like to have the LEDs light up using the Tally light outputs in the software. Is it possible to modify this code to receive the tally signals? I am a total newbie when it comes to coding for midi control so any help with code would be awesome....
Thanks in advance.
Liam Lacey
Hey, sorry I don't know anything about Tally light systems. Does the vMix software allow light signals to be converted into MIDI messages? If so the MIDI messages could then be forwarded to the Teensy and easily processed in the code.
Gace95
Hello.
First of all thank you very much for this awesome tutorial and sorry for my English. I´ve built a 16 arcade button controller and I have upload the code in to my Teensy++ 2.0 but I have a problem. I´m using FL Studio but I´m not getting any sound I don´t know what´s wrong. The programme recognizes the "Teensy MIDI" but it hasn´t any port asigned. I really need some help because I´m a total noob whith DAW programmes.
Again, thank you for the tutorial and for your time.
Roger
Hi, Liam!

Thank you for this tutorial.

What I want to do is only two button midi controller.

Scenario:
Talkback controller (SPL 2381) & Logic Pro X.

When I switch ON the Mix button on the SPL, it would enable the certain plugin in Logic and when the Mix button is OFF, it would bypass the plugin. The same goes for 2Tr A button on the SPL controller.

I tested it with other midi controller and it works as expected.

Is Teensy LC enough for my project?
I would also like to know if it is possible to switch between MOMENTARY and TOGGLE mode, or is it Momentary only? (this mode is what I need for my project)

Thank you

Regards,
Roger
Liam Lacey
Hey Roger,

A Teensy LC will be more than powerful enough to build a two-button MIDI controller.

As long as you use push buttons (as opposed to toggle switches), the buttons can behave as both momentary and toggling - see https://www.arduino.cc/en/tutorial/switch for an example of how you could implement this in code.
Roger
Hey Liam,

Thank you for explanation.

What is the maximum capacity for buttons on Teensy (In case I will change my mind and also connect other buttons)?

Can't wait to assamble my first micro controller project, though still waiting for Teensy.

Regards,
Roger
Liam Lacey
Hey Roger,

The Teensy LC has 27 Digital I/O pins, meaning you can directly connect up to 27 buttons, however there are methods (e.g. multiplexing) of connecting more buttons if needed. Most of the other Teensys contain more pins - see https://www.pjrc.com/teensy/techspecs.html for more information.
Roger
Hey Liam,

Great!
27 buttons will be more than enough.

Thnx.
Erin
Hello! Thanks for the tips. How would I go about changing the code or even set up if I wanted to make this using LDRs rather than buttons. It should be simple but I'm just not too familiar with the code requirements.

Cheers
Erin
Liam Lacey
Hey Erin,

As Teensy is an Arduino-compatible platform, do a Google search for "Arduino LDR" and you'll find plenty of existing tutorials and examples that will show you how to do this. The main difference from this project is that you'll need to use analog pins to read the LDR inputs.

Hope that helps!
Honza
Het Liam,

I'm working on my master's thesis right now and part of it is creating a MIDI controller for a software guitar looper made in Pure Data. My concern is that I want it as cheap as possible, so I'm thinking about buying Teensy LC. Question I want to ask is. I want to have 12 buttons that will have basically the same functionality as yours (sending a MIDI value of a note), that would be OK, but also with this I want to have 4 extra rotary potentiometers for adjusting volume. That makes a total of 17 inputs. I read that Teensy LC has 13 analog inputs and plenty of other digital I/O pins (in total around 27 I guess). So fimally my question is. Will Teensy LC be enough for this project or do I need Teensy 3.2 which has 21 analog inputs? I'm new to this and would appreciate any comments on this. Thanks a lot!

Honza.
Liam Lacey
Hey Honza,

You'll be able to use a Teensy LC for your project.

If you have a look at the LC pinout diagram at https://www.pjrc.com/teensy/card6a_rev2.pdf, you could use pins 0-11 for your buttons and pins 14-17 (referred to as pins A0-A3 when using them as analog pins) for your pots.

Hope that helps!
Erwan
Hello great article!
I've been trying by my own to make à similar controller.
I just have a problem, once I program the teensy, if I unplug and replug the teensy, impossible to get thé midi messages fromage the teensy.
Have you a solution to solve it?
Bill
Liam!

This project is fantastic. I followed the instructions, and all worked beautifully right away! I know nothing about code, but what you provided was great.

I built a single button version with the toggle switch. I’m using this to control a Leslie speaker effect in my music software.

To expand upon this project, can one use a 3-way blade switch instead of the arcade push button? This type of switch simply connects different circuits together, I think. These are found on electric guitars to switch between the various pickups. Just wondering...

Thanks again.

Bill Congdon
Liam Lacey
Hi Bill,

Glad to hear the tutorial was useful to you!

It would be possible to replace the arcade button with a 3-way switch, however the type of switch you use will affect how you need to change the circuit and code. The most common method would be to instead use an analogue input/pin (instead of a digital one) on the Teensy where each switch position creates a different analogue value - do an online search for '3-way switch and Arduino' to see how this can be done with Teensy.

I hope this helps!
bobby
Thanks loads for this article. I'm going to attempt to make a simple two button version, with a view to creating a box that I can plug a couple of 1/4 jack foot switches into, for example keyboard sustain pedals in the organ style, the idea is then to trigger simple bass drones/tones with my feet while I play instrumental guitar. Let me know if you have any tips for this setup! Thanks
Bruce
I found this article while searching for Teensy LC examples for MIDI projects. I keep hearing that the Teensy is better suited to MIDI than the Arduino. However, at the end of Step 3 you say that the Teensy has an advantage of internal pull-up resistors compared to the Arduino. I believe many if not most microcontrollers have internal pull-up resistors and the Arduino is no exception.
Dimas
Hi Liam..
Thanx for your good work..
I really need your help,
i’m using Teensy LC for Midi Controller, i uploaded the Sketch, and do = Tool USB > MIDI
And when I’m using MIDI Monitor, looks good, work well,
But when I’m hooking it to a Device (USB or MIDI pin), it’s not working, i mean I think the device doesn’t recognize the Teensy as a Midi controller

What did i do wrong, and what should i do?

Thanx
Geo
Is it possible to add a midi connector, in order to control external devices via midi?
And if yes, how?
Costa
Hi Liam. Great article. I'm new to the arduino world and this was very helpful. I was able to convert my, 5 pedal, korg ec5 to midi! My question is, can I send CCS on both modes? It would turn my 5 pedal into 10 with a use of a switch. Thanks!
fispol01
Is it possible to send MSC message instead of send note message ?
David M
I'm quite new at this. Building a virtual pipe organ and have wired a could of boards for certain functions. I successfully completed this project and it worked. Then when I disconnected it and plugged it back in it wouldn't work. Do I have to run the Arduino software are upload the software every time I want to use it? And does the Arduino software and all the compiled code have to be on another computer to use it there?

I'm obviously missing some basics here....
Richard
Hi Liam,
Many thanks for a great tutorial - you've given me the confidence to try something similar!
Is it possible to use the toggle switch to change the set of MIDI CC messages rather than switching between CC & note messages? How would I alter your code to achieve this please?
Many thanks!
Stuart
Marvelous, so simple. I've just adapted this project to make "The world's smallest 8 octave MIDI keyboard" - 70x30x15mm! My use is to ease developing VST synth patches when I'm out and about - without a physical MIDI keyboard you're usually forced to use software keyboards, which are often SUCH a pain: Stealing focus, disabling keyboard shortcuts etc. One octave keyboard layout, 7 octave-shift buttons (+ a button to output CC codes). The Teensy really is easy to use for things like this, thanks for showing us all how.
karinathill
With the use of https://crackcut.com/output-arcade-crack/ all kinds of errors and defects are removed. With this all kinds of major software are supported. It provides the user a useful output.


karinathill
CrackCut.com
Adam Worth
Hi, I came across your project and seems to be a good starting point to what I am trying to do. I have an old harpsichord that I am trying to midify. It has two manuals 64 keys each plus I plan on adding a 32 note pedal board. My plan is to use 3 teensy boards, one for each manual and one for the pedal board. My question is, would a teensey board be able to support 64 buttons? In my case the ‘buttons’ will actually be Hall effect sensors instead. Any feedback is much appreciated and thanks for the great post!

Want to join the discussion?

Create an account or login to get started!