Arduino MIDI Controller: Build a USB MIDI Device with a Leonardo
Build an Arduino MIDI controller: MIDIUSB on Leonardo and Pro Micro, notes and CC from buttons and pots, Ableton and FL Studio setup, serial MIDI on Uno, Pico.
An Arduino MIDI controller is a DIY instrument interface that sends notes and control commands to the music software on your computer as you press buttons and turn potentiometers. If you use a board with an ATmega32U4 chip, such as the Leonardo, Micro or Pro Micro, your computer sees it as a real USB MIDI device without installing any driver, and you use it in Ableton Live or FL Studio just like a store-bought controller.
In this article we explain step by step how MIDI messages are built, which boards can do USB MIDI, a 4-button, 2-pot controller with the MIDIUSB library, the filter that stops pots from jittering, and mapping in your DAW. If all you have is an Arduino Uno, we show the serial MIDI bridge, and if you have a Raspberry Pi Pico, USB MIDI with MicroPython.

What is MIDI and how does it work?
MIDI carries commands, not sound: "press this note this hard", "turn this knob to this value". A message is usually 3 bytes. The first byte is the status byte; its upper 4 bits give the message type and its lower 4 bits the channel (0–15, i.e. channels 1–16). The next two bytes are data bytes, each with a value from 0 to 127. The virtual instrument on the computer makes the sound; the Arduino only says what to play and when.
| Message | Status byte | Data 1 | Data 2 | Example |
|---|---|---|---|---|
| Note On | 0x90 + channel | Note (0–127) | Velocity (1–127) | 0x90 60 100: middle C on channel 1 |
| Note Off | 0x80 + channel | Note | Release velocity (usually 0) | 0x80 60 0: release the note |
| Control Change (CC) | 0xB0 + channel | Controller no. (0–127) | Value (0–127) | 0xB0 7 90: volume |
| Program Change | 0xC0 + channel | Program no. (0–127) | None | 0xC0 5: switch to sound 6 |
| Pitch Bend | 0xE0 + channel | Lower 7 bits of value | Upper 7 bits of value | 8192: centre |
Note number 60 is middle C, but programs name it differently: Ableton calls 60 C3, FL Studio C5 and many sources C4. Drum pads use the General MIDI layout: 36 kick, 38 snare, 42 closed hi-hat, 46 open hi-hat. Some CC numbers have a fixed meaning: 1 modulation, 7 volume, 10 pan, 64 sustain pedal. Picking the undefined numbers 20–31 for your own knobs keeps the software from tying them to something else.
Which Arduino boards can do USB MIDI?
| Board | Chip | USB MIDI | What to do |
|---|---|---|---|
| Leonardo, Micro, Pro Micro | ATmega32U4 | Yes (native USB) | MIDIUSB library |
| Due | SAM3X8E | Yes | MIDIUSB library |
| Zero, MKR series, Nano 33 IoT | SAMD21 | Yes | MIDIUSB library |
| Uno R4 Minima / WiFi | Renesas RA4M1 | Hardware capable | MIDIUSB doesn't list this architecture; you need a USB MIDI library that supports the R4 |
| Uno R3, Mega 2560, Nano | ATmega328P / 2560 | No (USB on a separate chip) | Serial MIDI bridge or 5-pin DIN MIDI |
| ESP32 (classic) | ESP32 | No | MIDI over serial, Bluetooth or Wi-Fi |
| Raspberry Pi Pico / Pico 2 | RP2040 / RP2350 | Yes | MicroPython usb-device-midi or CircuitPython |
The difference comes down to where the USB lives. On the Leonardo, USB is built into the main chip, so your sketch itself can tell the computer "I'm a MIDI device". On the Uno R3, a separate chip (ATmega16U2) handles USB and the computer always sees the board as a serial port. For the same reason the Leonardo can also be a keyboard and mouse, which we covered in Arduino Leonardo Keyboard and Mouse. The Uno R4's chip does have native USB, but version 1.0.5 of the MIDIUSB library only supports the avr, sam and samd architectures.
Parts and wiring
| Part | Leonardo / Pro Micro pin | Note |
|---|---|---|
| Buttons 1–4 | 2, 3, 4, 5 | Other leg to GND; INPUT_PULLUP is used |
| Potentiometer 1 (10 kΩ) | A0 (middle leg) | Outer legs to 5V and GND |
| Potentiometer 2 (10 kΩ) | A1 (middle leg) | Outer legs to 5V and GND |
| 100 nF capacitor (optional) | Between A0–GND and A1–GND | Reduces pot noise |
| USB cable | Board's USB port | Must be a data cable |
A potentiometer works like a voltage divider: as you turn it, the middle leg gives a voltage between 0 and 5 V, which the Arduino reads as a number from 0 to 1023. You can try out the ratio with the voltage divider calculator and read about pot types in What Is a Potentiometer. The buttons need no external resistor; thanks to the internal pull-up they read LOW when pressed and HIGH when released. A linear (B-type) pot feels more natural for MIDI control than a logarithmic (A-type) one.
Step by step: your first USB MIDI test
- In the Arduino IDE open the Library Manager, search for MIDIUSB and install the library published by Arduino.
- In the Tools menu select Arduino Leonardo (or Micro) as the board; most Pro Micro clones also work with the Leonardo setting.
- Upload the test sketch below; no wiring needed.
- Open your DAW, enable the Arduino Leonardo device in the MIDI inputs and arm an instrument track; you should hear a C major arpeggio every second.
1// Leonardo / Micro / Pro Micro: devre kurmadan USB-MIDI testi
2// Leonardo / Micro / Pro Micro: USB-MIDI test without any wiring
3#include <MIDIUSB.h>
4
5const byte CHANNEL = 0; // 0 = MIDI kanal 1 / MIDI channel 1
6const byte NOTES[] = { 60, 64, 67, 72 }; // Do majör arpej: C4 E4 G4 C5 / C major arpeggio
7
8void noteOn(byte note, byte velocity) {
9 midiEventPacket_t p = { 0x09, (byte)(0x90 | CHANNEL), note, velocity }; // 0x09 = Note On paketi / packet
10 MidiUSB.sendMIDI(p);
11}
12
13void noteOff(byte note) {
14 midiEventPacket_t p = { 0x08, (byte)(0x80 | CHANNEL), note, 0 }; // 0x08 = Note Off paketi / packet
15 MidiUSB.sendMIDI(p);
16}
17
18void setup() {
19}
20
21void loop() {
22 for (byte i = 0; i < sizeof(NOTES); i++) {
23 noteOn(NOTES[i], 100);
24 MidiUSB.flush(); // paketi hemen gönder / send the packet now
25 delay(250);
26 noteOff(NOTES[i]);
27 MidiUSB.flush();
28 }
29 delay(1000);
30}In USB MIDI every message is a 4-byte packet. The first byte is the code index number (CIN) and tells the USB side the message type: 0x09 Note On, 0x08 Note Off, 0x0B Control Change. The remaining three bytes are the familiar MIDI message. sendMIDI puts the packet in a buffer and flush sends the buffer right away. If you hear the test arpeggio, the USB side is ready and you can add buttons and pots.
Code for a 4-button, 2-pot MIDI controller
1// Leonardo / Pro Micro: 4 butonlu, 2 potlu USB MIDI kontrolcü
2// Leonardo / Pro Micro: USB MIDI controller with 4 buttons and 2 pots
3#include <MIDIUSB.h>
4
5const byte CHANNEL = 0; // MIDI kanal 1 / MIDI channel 1
6const byte BUTTON_PINS[] = { 2, 3, 4, 5 }; // buton diğer ucu GND / other leg to GND
7const byte BUTTON_NOTES[] = { 36, 38, 42, 46 }; // davul: kick, snare, kapalı hi-hat, açık hi-hat / drums
8const byte POT_PINS[] = { A0, A1 };
9const byte POT_CC[] = { 20, 21 }; // tanımsız CC'ler, eşlemeye uygun / undefined CCs, good for mapping
10const int BUTTON_COUNT = sizeof(BUTTON_PINS);
11const int POT_COUNT = sizeof(POT_PINS);
12
13bool lastPressed[BUTTON_COUNT];
14unsigned long lastChange[BUTTON_COUNT];
15long smooth[POT_COUNT]; // filtrelenmiş değer x16 / filtered value x16
16int lastRaw[POT_COUNT]; // son kabul edilen ham değer / last accepted raw value
17int lastSent[POT_COUNT]; // son gönderilen CC değeri / last CC value sent
18
19void sendNote(byte note, bool on) {
20 midiEventPacket_t p = { (byte)(on ? 0x09 : 0x08), (byte)((on ? 0x90 : 0x80) | CHANNEL), note, (byte)(on ? 110 : 0) };
21 MidiUSB.sendMIDI(p);
22}
23
24void sendCC(byte cc, byte value) {
25 midiEventPacket_t p = { 0x0B, (byte)(0xB0 | CHANNEL), cc, value }; // 0x0B = Control Change
26 MidiUSB.sendMIDI(p);
27}
28
29void setup() {
30 for (int i = 0; i < BUTTON_COUNT; i++) {
31 pinMode(BUTTON_PINS[i], INPUT_PULLUP); // basılınca LOW / LOW when pressed
32 lastPressed[i] = false;
33 lastChange[i] = 0;
34 }
35 for (int i = 0; i < POT_COUNT; i++) {
36 smooth[i] = analogRead(POT_PINS[i]) * 16L;
37 lastRaw[i] = -100; // ilk turda mutlaka gönder / always send on the first pass
38 lastSent[i] = -1;
39 }
40}
41
42void loop() {
43 for (int i = 0; i < BUTTON_COUNT; i++) {
44 bool pressed = digitalRead(BUTTON_PINS[i]) == LOW;
45 if (pressed != lastPressed[i] && millis() - lastChange[i] > 15) { // 15 ms sıçrama filtresi / debounce
46 lastPressed[i] = pressed;
47 lastChange[i] = millis();
48 sendNote(BUTTON_NOTES[i], pressed);
49 }
50 }
51
52 for (int i = 0; i < POT_COUNT; i++) {
53 int raw = analogRead(POT_PINS[i]); // 0-1023
54 smooth[i] += raw - smooth[i] / 16; // üstel ortalama, 1/16 ağırlık / exponential average
55 int filtered = smooth[i] / 16;
56 // ölü bant: 6 adımdan küçük değişimi yok say, uçları (0 ve 1023) her zaman al
57 // dead band: ignore changes under 6 steps, but always accept the ends (0 and 1023)
58 if (abs(filtered - lastRaw[i]) >= 6 || filtered == 0 || filtered == 1023) {
59 lastRaw[i] = filtered;
60 int value = filtered >> 3; // 0-1023 -> 0-127
61 if (value != lastSent[i]) {
62 lastSent[i] = value;
63 sendCC(POT_CC[i], value);
64 }
65 }
66 }
67 MidiUSB.flush();
68 delay(2);
69}The buttons send Note On when pressed and Note Off when released; the notes follow the General MIDI drum layout, so they play a drum instrument directly. The 15-millisecond debounce stops double notes caused by bouncing mechanical contacts. The pots are read from 0 to 1023, divided by 8 with >> 3 to get 0–127 and sent as CC 20 and CC 21. The code only sends a message when a value changes; sending the same value over and over keeps the DAW busy for nothing.
Pot noise: why it jitters and how to filter it
The Arduino's analog input reads values that wander by a few steps even when the pot doesn't move; this comes from supply ripple and measurement noise. When 1024 steps are reduced to 128 MIDI values, each MIDI value covers 8 raw steps. If the pot sits right on the border between two values, even a tiny wobble sends 63, 64, 63, 64 non-stop and the knob in the DAW twitches. The fix in the code has two layers: first an exponential average smooths sudden jumps, then a dead band ignores changes smaller than 6 raw steps. The ends (0 and 1023) are always accepted, so the pot reliably reaches 0 and 127 when turned all the way. You'll find a comparison of filtering methods in Filtering Sensor Data.
Setting it up in your DAW: Ableton Live and FL Studio
| Software | Enable the device | Map to a knob |
|---|---|---|
| Ableton Live | Settings > Link, Tempo & MIDI > MIDI Ports: Track and Remote on for the Arduino input | Press Ctrl+M (Cmd+M on Mac) for MIDI Map mode, click the knob, turn the pot |
| FL Studio | Options > MIDI settings > select the device in the Input list and Enable | Right-click the knob > Link to controller, then turn the pot |
| Other DAWs | Select the Arduino as an input in the MIDI settings | Turn on MIDI Learn and turn the pot |
The buttons need no extra setup: an armed instrument track plays the notes directly. The pots can be mapped to any knob, such as filter cutoff, volume or effect amount. On most Windows setups only one program can open a MIDI device at a time; if your DAW doesn't see the Arduino, close any other music software holding the device and restart the DAW. On macOS you can check that the device shows up in the MIDI Studio window of the Audio MIDI Setup app.
Serial MIDI bridge with an Arduino Uno R3
The Uno R3 can't appear as a USB MIDI device, but it can send MIDI bytes over the serial port. A serial-to-MIDI bridge program running on the computer (for example Hairless MIDI) reads those bytes and passes them to a virtual MIDI port, which your DAW listens to. On Windows a tool like loopMIDI provides the virtual port; on macOS you use the built-in IAC driver. There's no MIDIUSB in the code; the three bytes are written directly with Serial.write.
1// Arduino Uno R3: seri port üzerinden MIDI (köprü programı ya da 5 pinli DIN)
2// Arduino Uno R3: MIDI over the serial port (bridge software or a 5-pin DIN jack)
3const long BAUD = 115200; // köprü programı için / for a bridge app; DIN MIDI: 31250
4const byte CHANNEL = 0; // MIDI kanal 1 / MIDI channel 1
5const byte BUTTON_PIN = 2; // buton diğer ucu GND / other leg to GND
6const byte POT_PIN = A0;
7const byte NOTE = 60; // C4 (orta Do / middle C)
8const byte POT_CC = 20;
9
10bool lastPressed = false;
11int lastValue = -1;
12
13void midiSend(byte status, byte data1, byte data2) {
14 Serial.write(status); // durum baytı / status byte
15 Serial.write(data1); // nota ya da CC numarası / note or CC number
16 Serial.write(data2); // hız ya da değer / velocity or value
17}
18
19void setup() {
20 Serial.begin(BAUD); // Serial.print KULLANMA: köprü bozulur / DO NOT use Serial.print
21 pinMode(BUTTON_PIN, INPUT_PULLUP);
22}
23
24void loop() {
25 bool pressed = digitalRead(BUTTON_PIN) == LOW;
26 if (pressed != lastPressed) {
27 lastPressed = pressed;
28 if (pressed) midiSend(0x90 | CHANNEL, NOTE, 100); // Note On
29 else midiSend(0x80 | CHANNEL, NOTE, 0); // Note Off
30 delay(15); // basit sıçrama filtresi / simple debounce
31 }
32
33 int value = analogRead(POT_PIN) >> 3; // 0-1023 -> 0-127
34 if (abs(value - lastValue) >= 2) { // küçük titremeyi yok say / ignore small jitter
35 lastValue = value;
36 midiSend(0xB0 | CHANNEL, POT_CC, value); // Control Change
37 }
38 delay(5);
39}This route has two rules: the speed in the bridge program must match the speed in the code (115200 here), and the code must not use Serial.print, because any text byte in between breaks the MIDI stream. If you want to connect to a real synthesizer with a cable, set the speed to 31250 and wire a 5-pin DIN socket like this: TX pin through a 220 Ω resistor to socket pin 5, 5V through a 220 Ω resistor to pin 4 and pin 2 to GND. A more advanced route is reprogramming the Uno R3's USB chip (16U2) with special firmware that acts as a MIDI device; it requires DFU mode and isn't recommended for beginners.
USB MIDI with a Raspberry Pi Pico
The Pico's RP2040 chip has native USB, so like the Leonardo it can be a USB MIDI device directly. With the runtime USB support in MicroPython 1.23 and later, you install the usb-device-midi package with mpremote mip install usb-device-midi. The code below sends a note from a button on GP15 and a CC from a pot on GP26; since the Pico's ADC returns a 16-bit scale, the value is shifted right by 9 bits to get 0–127.
1# Raspberry Pi Pico: MicroPython ile USB MIDI / USB MIDI with MicroPython
2# Önce / first: mpremote mip install usb-device-midi (MicroPython 1.23+)
3import time
4import usb.device
5from usb.device.midi import MIDIInterface
6from machine import Pin, ADC
7
8CHANNEL = 0 # MIDI kanal 1 / MIDI channel 1
9NOTE = 60 # C4 (orta Do / middle C)
10POT_CC = 20
11
12midi = MIDIInterface()
13usb.device.get().init(midi, builtin_driver=True) # REPL de USB'de kalsın / keep the REPL on USB too
14while not midi.is_open(): # bilgisayar aygıtı tanıyana kadar bekle / wait for the host
15 time.sleep_ms(100)
16
17button = Pin(15, Pin.IN, Pin.PULL_UP) # GP15, buton diğer ucu GND / other leg to GND
18pot = ADC(26) # GP26 = ADC0
19last_pressed = False
20last_value = -1
21
22while True:
23 pressed = button.value() == 0
24 if pressed != last_pressed:
25 last_pressed = pressed
26 if pressed:
27 midi.note_on(CHANNEL, NOTE, 100)
28 else:
29 midi.note_off(CHANNEL, NOTE)
30 time.sleep_ms(15) # sıçrama filtresi / debounce
31
32 total = 0
33 for _ in range(16): # 16 ölçümün ortalaması / average of 16 readings
34 total += pot.read_u16()
35 value = (total // 16) >> 9 # 0-65535 -> 0-127
36 if value != last_value:
37 last_value = value
38 midi.control_change(CHANNEL, POT_CC, value)
39 time.sleep_ms(5)The builtin_driver=True parameter keeps MicroPython's serial console (REPL) open as well, so you can keep updating the code. The Pico's ADC input is 3.3 V; connect the pot's outer legs to 3V3 and GND and never apply 5 V. If you use CircuitPython, the usb_midi module comes built in; if you program the Pico from the Arduino IDE, the TinyUSB support in the Arduino-Pico core can also do USB MIDI. To get to know the Pico, see What Is a Raspberry Pi Pico.
Arduino MIDI controller project ideas
- A 16-button drum pad: wire the buttons as a matrix like a keypad to read many keys with few pins.
- A controller with endless knobs: use a rotary encoder instead of a pot and send increment/decrement messages.
- A theremin with a distance sensor: send your hand's distance as CC or pitch bend; see HC-SR04 for the sensor.
- A light-sensitive effect knob: map room light from an LDR to the filter cutoff.
- Move the button-and-buzzer piano to MIDI; for a start, look at the Arduino Piano project.
Common mistakes and how to fix them
| Symptom | Cause | Fix |
|---|---|---|
| "MIDIUSB can only be used with an USB MCU" error | Uno R3, Nano or Mega selected | Use a Leonardo/Pro Micro or switch to serial MIDI |
| DAW doesn't see the device | Another program holds the device or the cable is charge-only | Close other programs, use a data cable |
| Pot keeps sending values | ADC noise wobbles a value on the border | Use averaging + dead band, add a 100 nF capacitor |
| Note hangs and doesn't stop | Note Off isn't sent | Send Note Off with the same note on release |
| One press plays two notes | Button bounce | Add a 10–20 ms debounce |
| Pro Micro disappeared after upload | Port renumbered or the sketch locked up USB | Double-reset into the bootloader and select the port again |
With a Leonardo, a few buttons and two pots, you can finish your first MIDI controller in an evening. In the BlueGrays app you can open the button-and-buzzer piano, potentiometer control and melody projects with step-by-step wiring diagrams and ready code, and build the MIDI logic from this article on top of those circuits.
Frequently asked questions
Can an Arduino Uno be used as a MIDI controller?
The Uno R3 can't show up directly as a USB MIDI device because a separate chip handles its USB. You can send MIDI bytes over the serial port and pass them to your DAW with a serial-to-MIDI bridge program, or build a 5-pin DIN MIDI output at 31250 baud. For driverless USB MIDI, use a Leonardo, Micro or Pro Micro.
Which Arduino is best for a MIDI controller?
The most practical choices for a start are the ATmega32U4 boards: Leonardo, Micro and Pro Micro, which work directly with the MIDIUSB library. The Pro Micro is small and cheap, while the Leonardo is comfortable for breadboard experiments. If you need lots of pots and buttons, SAMD21 boards offer more memory and speed.
How do I install the MIDIUSB library?
In the Arduino IDE open Tools > Manage Libraries, type MIDIUSB and install the library published by Arduino. It only compiles on avr, sam and samd boards with native USB. Make sure you've selected Leonardo or Micro as the board before compiling.
How do I set up an Arduino MIDI controller in Ableton?
In Ableton open Settings > Link, Tempo & MIDI and turn on Track and Remote for the Arduino input. The buttons play notes directly on an armed instrument track. To map the pots, enter MIDI Map mode with Ctrl+M (Cmd+M on Mac), click a knob and turn the pot.
Why does my potentiometer MIDI value jitter?
Analog readings always carry a few steps of noise, and when the pot sits on the border between two MIDI values that noise looks like constant change. Averaging the readings and adding a dead band that ignores small changes fixes it. A 100 nF capacitor between the pot's middle leg and GND helps as well.
Can you make a MIDI controller with a Raspberry Pi Pico?
Yes, the Pico has native USB, so it can act as a USB MIDI device directly. In MicroPython 1.23 and later, install the usb-device-midi package and send messages with commands such as note_on and control_change. In CircuitPython the usb_midi module is built in.
Projects to build after reading this
See all projects
Simple Piano with Buzzer and Button
Build your own little piano with eight buttons. Each button is one note, from low to high: do, re, mi, fa, sol, la, ti and high do.

Using a Buzzer
Ever wondered how a doorbell or an alarm makes its sound? The Arduino makes a small buzzer beep at short intervals: beep, pause, beep, pause.

Frequency Setting with Buzzer
You control the sound of a buzzer with four buttons: one starts the sound, one silences it, and the other two make it higher or lower.

Turkish National Anthem with Buzzer
Press the button and a small buzzer starts playing the Turkish National Anthem, note by note.

Playing Melodies with an IR Remote and Buzzer
Build a music box that plays tunes with the buttons of a TV remote. An infrared receiver catches the remote's signal; one button plays a lively video game tune through the buzzer, another a familiar…

ESP32 Melody Playback with Buzzer
Playing a simple melody (Twinkle Twinkle Little Star) with a passive buzzer. We play notes with tone() and noTone() functions like in Arduino - ESP32 works with the same syntax as Arduino Core 3.0+. Passive buzzer must be used (active buzzer does not play melody).

Servo Motor Operation with Potentiometer
As you turn the potentiometer knob, the servo motor's arm turns right along with it: one end of the knob means zero degrees, the other end means half a turn.
More articles
BlueGrays app
Build this circuit step by step on your phone
Wiring diagram, code and parts list on one screen. 500+ Arduino, ESP32, ESP8266, Pico, mBot and micro:bit projects ready to build.
Scan with your phone
Point your camera at the code and your phone's app store opens.
or open the store

