Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Arduino to MIDI

From I/M/D Wiki
Revision as of 12:31, 19 January 2026 by Nikilia (talk | contribs) (Created page with "# Arduino to MIDI guide ## Setup 1. Install MIDIUSB library https://docs.arduino.cc/libraries/midiusb/ 2. Add the MIDIUSB.h Library: Go to Tools < Manage Libraries... 3. Search for "MIDIUSB" by Gary Grewal 4. Install the latest version 5. Select your board: Tools > Board > Arduino Leonardo (or Pro Micro) ## πŸŽ›οΈπŸŽšοΈ Potentiometers / Sliders ### What you need: - 1 potentiometer or slider - 3 wires ### How to connect: ``` Potentiometer: β”œβ”€ Left pin / GND...")
(diff) ← Older revision | Latest revision (diff) | Newer revision β†’ (diff)
  1. Arduino to MIDI guide
    1. Setup

1. Install MIDIUSB library https://docs.arduino.cc/libraries/midiusb/ 2. Add the MIDIUSB.h Library: Go to Tools < Manage Libraries... 3. Search for "MIDIUSB" by Gary Grewal 4. Install the latest version 5. Select your board: Tools > Board > Arduino Leonardo (or Pro Micro)

    1. πŸŽ›οΈπŸŽšοΈ Potentiometers / Sliders
      1. What you need:

- 1 potentiometer or slider - 3 wires

      1. How to connect:

``` Potentiometer: β”œβ”€ Left pin / GND β†’ GND β”œβ”€ Middle pin / Signal β†’ A0 (or A1, A2, A3...) └─ Right pin / VCC / Power β†’ 5V ```

      1. Code

```cpp

  1. include <MIDIUSB.h>

int lastValue = 0;

void setup() {

 pinMode(A0, INPUT);  // ← Change A0 to your pin

}

void loop() {

 int value = analogRead(A0) / 8;  // ← Change A0 to match setup
 if (valueΒ != lastValue) {
   midiEventPacket_t event = {0x0B, 0xB0, 1, value};
   //                                      ↑ ← CC number
   MidiUSB.sendMIDI(event);
   MidiUSB.flush();
   lastValue = value;
 }
 delay(10);

} ```

    • To customize:**

- Change A0 to A1, A2, A3 etc. for different pins - Change the CC number 1 a different one for every input


    1. πŸ”˜ Note button
      1. What you need

- 1 push button - 2 wires

      1. How to connect

``` Button: β”œβ”€ One side β†’ Pin 2 (or 3, 4, 5...) └─ Other side β†’ GND ```

      1. Code

```cpp

  1. include <MIDIUSB.h>

int lastState = HIGH;

void setup() {

 pinMode(2, INPUT_PULLUP);  // ← Change 2 to your pin

}

void loop() {

 int state = digitalRead(2);  // ← Change 2 to match setup
 if (stateΒ != lastState) {
   if (state == LOW) {
     // Button pressed
     midiEventPacket_t noteOn = {0x09, 0x90, 60, 127};
     //                                       ↑   ↑
     //                                    note velocity
     MidiUSB.sendMIDI(noteOn);
   } else {
     // Button released
     midiEventPacket_t noteOff = {0x08, 0x80, 60, 0};
     //                                        ↑
     //                                      note
     MidiUSB.sendMIDI(noteOff);
   }
   MidiUSB.flush();
   lastState = state;
 }
 delay(10);

} ```

    • To customize:**

- Change pin `2` to `3`, `4`, `5` etc. - Change note number `60`:

 - `60` = C (middle C)
 - `62` = D
 - `64` = E
 - `65` = F
 - `67` = G
 - `69` = A
 - `71` = B
 - `72` = C (one octave higher)

- Change velocity `100` (0-127, higher = louder) -


    1. πŸ“πŸͺ’ Pull sensor / distance sensor
      1. What you need:

- Any sensor with analog output - Wires as needed for your sensor

      1. How to connect:

``` Sensor: β”œβ”€ VCC/Power β†’ 5V β”œβ”€ GND β†’ GND └─ Signal β†’ A0 (or A1, A2, A3...) ```

      1. Code to copy:

```cpp

  1. include <MIDIUSB.h>

int lastValue = 0;

void setup() {

 pinMode(A0, INPUT);  // ← Change A0 to your pin

}

void loop() {

 int sensorValue = analogRead(A0);  // ← Change A0 to match setup
 int midiValue = map(sensorValue, 0, 1023, 0, 127);
 //                               ↑   ↑
 //                         adjust these if needed
 if (abs(midiValue - lastValue) > 1) {  // Ignore tiny changes
   midiEventPacket_t event = {0x0B, 0xB0, 74, midiValue};
   //                                      ↑ ← CC number
   MidiUSB.sendMIDI(event);
   MidiUSB.flush();
   lastValue = midiValue;
 }
 delay(10);

} ```

      1. To customize:

- Change `A0` to your sensor pin - Change `0, 1023` in the `map()` function if your sensor gives different values - Change CC number `74` to control different parameters


      1. ☎️ CC on/off / Momentary
    1. πŸ“ Common Pin Reference
      1. Analog Pins (for sensors & potentiometers):

`A0`, `A1`, `A2`, `A3`, `A4`, `A5`

      1. Digital Pins (for buttons):

`2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `10`, `11`, `12`, `13`

      1. Don't use:

- Pin `0` and `1` (used for USB communication)

    1. Sending notes

```cpp C4 = 60 (Middle C) C#4 = 61 D4 = 62 D#4 = 63 E4 = 64 F4 = 65 F#4 = 66 G4 = 67 G#4 = 68 A4 = 69 A#4 = 70 B4 = 71 C5 = 72 ```

Each octave adds or subtracts 12:

- C3 = 48 (one octave lower) - C5 = 72 (one octave higher)

    1. CC

You can use any CC from 0-119, but these are the most common!