Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Johan van Vugt
Published © GPL3+

Turn an Arduino Uno into a MIDI Controller: Guitar Pedals

This foot controller with a Wah pedal, a preset switch and a few extras acts as a regular MIDI controller that works in all DAWs and VSTs.

IntermediateFull instructions provided4 hours30,557
Turn an Arduino Uno into a MIDI Controller: Guitar Pedals

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Stereo Jack Female 6.35mm
×2
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×3
SPST Switch (On-Off)
×1
M-Audio EX-P Expression Pedal
×1
Lead Foot FS-2 - double foot switch
×1

Software apps and online services

Arduino IDE
Arduino IDE
Atmel Flip
HiDuino hex files

Story

Read more

Schematics

MIDI Controller Wiring Diagram

Code

MIDI Controller Sketch

C/C++
#include <MIDI.h>

MIDI_CREATE_DEFAULT_INSTANCE();

int analogExpression = A0; //expression pedal
int analogPots[] = {A1, A2, A3}; //pots on top of pedal
int analogPotsOld [] = {0, 0, 0};
int analogPotsNew[] = {0, 0, 0};

int readSwitchNew; //footswitches
int readSwitchNew2;
int readSwitchOld;
int readSwitchOld2;
int readExpressionPedalOld;
int readExpressionPedalNew;

int singleSwitchNew; //single switch on top of pedal
int singleSwitchOld;

//MIDI Control Numbers
#define expPedalCC 50

#define footSwitch1CC 51
#define footSwitch2CC 52

int potsCC [] = {53, 54, 55};
#define singleSwitchCC 56

#define defaultChannel 14

void setup() {
  MIDI.begin (MIDI_CHANNEL_OFF); //start midi
  
  Serial.begin(9600);
  //configure pin 2 as an input and enable the internal pull-up resistor
  pinMode (analogExpression, INPUT);

  for (int x = 0; x <= 2; x++) { //pots
    pinMode (analogPots[x], INPUT);
  }

  pinMode(2, INPUT_PULLUP); //connect to tip //gnd to sleeve. footswitch 1
  pinMode(4, INPUT_PULLUP); //connect to ring footswitch 2

  pinMode (7, INPUT_PULLUP); //connect singleswitch
}

void loop() {

  //read expression pedal
  readExpressionPedalNew = analogRead (analogExpression);
  readExpressionPedalNew = (map (readExpressionPedalNew, 0, 1015, 0, 127));
  readExpressionPedalNew = constrain(readExpressionPedalNew, 0, 127);
  if (readExpressionPedalNew == 126) {
    readExpressionPedalNew = 127; 
  }
  if (readExpressionPedalOld != readExpressionPedalNew) { 

    readExpressionPedalOld = readExpressionPedalNew;

    // send serial value (ControlNumber 1, ControlValue = analogValue, Channel 1)
    // more info: http://arduinomidilib.sourceforge.net/a00001.html
    MIDI.sendControlChange(expPedalCC, readExpressionPedalNew, defaultChannel);
    Serial.println (readExpressionPedalNew);
  }

  //read the Footpedal Switches value into a variable
  readSwitchNew = digitalRead(4);
  readSwitchNew2 = digitalRead(2);

  if (readSwitchNew != readSwitchOld) {
    readSwitchOld = readSwitchNew;

    MIDI.sendControlChange(footSwitch1CC, 127, defaultChannel); 
    Serial.print("Left: ");
    Serial.println("Change");
  }
  if (readSwitchNew2 != readSwitchOld2) {
    readSwitchOld2 = readSwitchNew2;
    MIDI.sendControlChange(footSwitch2CC, 127, defaultChannel);
    Serial.print("Right: ");
    Serial.println("Change");

  }
  //read Pots
  for (int y = 0; y <= 2; y++) {
    analogPotsNew[y] = analogRead (analogPots[y]);
    if (analogPotsNew [y] - analogPotsOld[y] >= 10 || analogPotsOld [y] - analogPotsNew[y] >= 10) {
      analogPotsOld[y] = analogPotsNew[y];
      analogPotsNew[y] = (map (analogPotsNew[y], 0, 1023, 0, 128));
      analogPotsNew[y] = (constrain(analogPotsNew[y], 0, 128));
      MIDI.sendControlChange(potsCC [y], analogPotsNew[y], defaultChannel);
      Serial.print ("pot: ");
      Serial.println (analogPots[y]);
      Serial.print ("potread: ");
      Serial.println (analogPotsNew[y]);
    }
    //read singleSwitch
    singleSwitchNew = digitalRead (7);
    if (singleSwitchNew != singleSwitchOld) {
      singleSwitchOld = singleSwitchNew;
      if (singleSwitchNew ==1) { // is aan
        Serial.println ("On");
        MIDI.sendControlChange(singleSwitchCC, 127, defaultChannel); 
      }
      else {
        Serial.println ("Off");
        MIDI.sendControlChange(singleSwitchCC, 0, defaultChannel); 
      }
         
    

    }
  }

  delay (5);
}

Credits

Johan van Vugt
3 projects • 11 followers

Comments