Midi controller with Arduino
I made a MIDI controller by connecting potentiometers to an Arduino's analog inputs and mapping their readings to values from 0 to 127.
I used the Arduino IDE to upload the program. The examples below show a button and a potentiometer.
There are multiple types of Arduino boards of different sizes. The most common one is the Arduino uno.
Here is the list of pins on the Arduino:
- D0 to D13: Digital I/O pins for general-purpose digital input/output.
- A0 to A5: Analog input pins for reading analog signals from sensors or other devices.
- TX (D1) and RX (D0): Serial communication pins for transmitting and receiving data.
- PWM (D3, D5, D6, D9, D10, D11): Pulse Width Modulation pins for analog-like output.
- Interrupt (D2, D3): Pins capable of triggering interrupts for time-sensitive tasks.
- 5V: Output for 5-volt power.
- 3.3V: Output for 3.3-volt power.
- GND: Ground pins for connecting to the ground of external components.
- A4 (SDA) and A5 (SCL): Pins for I2C communication.
- D2 (SDA) and D3 (SCL): Alternative pins for I2C on the Uno.
- MISO, MOSI, SCK, RESET, 5V, GND: Pins for In-Circuit Serial Programming.
Analog pins on an Arduino can read continuous voltage levels and are typically used for analog sensors, while digital pins deal with binary signals (0 or 1), suitable for tasks like reading switches or controlling LEDs. Analog pins are labeled with 'A' (e.g., A0), and digital pins are labeled with 'D' (e.g., D2) on Arduino boards. The main distinction is in the type of signals they handle: analog for continuous values and digital for discrete values.
To make a midi controller with an Arduino board, I connected some potentiometer into analog pins. This allowed me to read the variable voltage from the potentiometers to translate to a midi value from 0 to 127. I could also have used some buttons too.

Example circuit for a midi controller
The examples use MIDIUSB.h. Native USB MIDI requires a compatible board, not a standard Uno's serial USB connection. The samples are kept as historical examples rather than a complete controller implementation.
Here is a sample code for a single button midi controller.
#include <MIDIUSB.h>
#define BUTTON_PIN 2
void setup() {
pinMode(BUTTON_PIN, INPUT_PULLUP);
}
void loop() {
if (digitalRead(BUTTON_PIN) == LOW) {
midiEventPacket_t noteOn = {0x09, 0x90 | 1, 60, 127}; // Note On, channel 1, note 60 (Middle C), velocity 127
MidiUSB.sendMIDI(noteOn);
delay(100); // Adjust delay as needed
midiEventPacket_t noteOff = {0x08, 0x80 | 1, 60, 127}; // Note Off, channel 1, note 60, velocity 127
MidiUSB.sendMIDI(noteOff);
}
}
Now let's make a small example for a potentiometer midi controller.
#include <MIDIUSB.h>
#define POTENTIOMETER_PIN A0
#define MIDI_CC_NUMBER 1 // Change this to the desired MIDI CC number
int previousPotValue = 0;
void setup() {
// No need to set up anything specific for the potentiometer
}
void loop() {
int potValue = analogRead(POTENTIOMETER_PIN) / 8; // Scale the analog input range to MIDI values (0-127)
// Check if the potentiometer value has changed
if (potValue != previousPotValue) {
// Create a MIDI control change message
midiEventPacket_t ccMessage = {0xB0, 0, MIDI_CC_NUMBER, potValue};
// Send the MIDI message
MidiUSB.sendMIDI(ccMessage);
// Update the previous potentiometer value
previousPotValue = potValue;
}
}
The code can then be uploaded to the Arduino board with the IDE.
Check out this page for a good tutorial on MIDIUSB.

Pictures of the project