Thursday, 17 March 2016

Arduino MIDI Controller: Potentiometers

Take Control


In this installment of the MIDI for the Arduino series, we will apply the knowledge we have gained from previous chapters and begin the construction of a MIDI controller. This lesson deals specifically with potentiometers. But have no fear, we will cover buttons in the next installment.

Before You Start

This tutorial will ONLY work with the Arduino UNO. (Please don't ask if it will work on other Arduino models.) I am using some direct port manipulation in the code that is currently specific to the UNO. I'll let you know if this changes in the future.

The potentiometers I am using in the video are ALPS RK09L12D0A1W. Other types will work but they may not fit in your breadboard as nicely. You can simply solder some wires to them to make them work. Slide pots (faders) will also work if that's what you're into.

If you are planning to make a permanent version of this circuit, think about how you will mount the potentiometers and the size of knobs you will use before you buy your pots.

Buying An Arduino

As you may have heard, Arduino LLC (the company that created the brand) had a falling out with the manufacturing company that produced the original boards. There are now two entities, Arduino.cc and Arduino.org. Both make their own version of the UNO. The version produced by Adafruit for Arduino.cc is considered to be the official version. The Arduino.org board should also work (although the Arduino IDE may complain a bit when you plug it in).

The Software

To make things simple, I have created a plug and play program that will allow you to customize your controller. All you need to do is tell the software the number of controls you will be using and how these controls should behave and the software will take care of the details. The video explains how to configure the software for your project.

Download the software HERE

Part List (With Amazon links)

Here are the parts you will need to complete this tutorial:

Arduino UNO or Arduino UNO (Official Adafruit Version)

6 x 10K Potentiometers (Linear taper) - Inexpensive
or model used in video (RK09L1140A66)

Breadboard (63 pin width)

MIDI Jack

2 x 220 Ohm Resistors

Jumper Wires

MIDI Cable

Build It!

Watch this video for a step by step guide.

83 comments:

  1. Hello, I would like to make a MIDI controller with an arduino uno, but i ask me how connect the MIDI jack to my computer, it's a laptop so i haven't MIDI port above it, i know it's above PC for keyboard and mouse but how connect to a laptop ?
    This video was very good and very well explain, good job ;)
    PS: sory for my bad english, i'm french ^^

    ReplyDelete
    Replies
    1. You can go to your local tech/computer store, or go online and purchase a "midi to USB" cable.

      Delete
    2. puedes usar un software virtual ...virtual serial midi

      Delete
  2. can this progamme be modified to work with a arduino mega 2560

    ReplyDelete
    Replies
    1. Yes, just make sure you tell the program they type of board, and edit the pins accordingly.

      Delete
    2. Hi Thomas. Yes it could be modified. It has some direct port manipulation routines that are custom to to the UNO that would have to be re-written for other boards though.

      Delete
    3. hey Psykotek876, how do you do that? i am sufferieng man! help. i need to recode for 16 potentiometer with arduino mega 2560 and this is giving me problems. help.

      Delete
    4. I have the same problem !

      Delete
    5. Any solution for the MEGA 2560? I need more analog imputs (multiplexer is not a solution for me, I want to use only a simple board). Somebody has the code (maybe modified) working in the MEGA 2560? Thanks.

      Delete
    6. Arduino Pro Micro

      https://wiki.eprolabs.com/index.php?title=Arduino_Pro_Micro

      He modificado en Controler.cpp

      pinMode(15, OUTPUT); //antiguo pin2
      pinMode(16, OUTPUT); //antiguo pin3
      pinMode(14, OUTPUT); //antiguo pin4
      if (numPins > 8) pinMode(8, OUTPUT); //antiguo pin5

      y mas abajo...

      void Button::muxUpdate()
      {
      byte temp = _muxpin;
      temp = temp << 1; //antiguo 2
      if (_numMuxPins > 8) PORTB = PORTB & B11100001; //antiguo PORTD & B11000011
      else PORTB = PORTB & B11110001; //antiguo PORTD & B11100011
      PORTB = PORTB | temp;
      }

      Y...

      void Pot::muxUpdate()
      {
      byte temp = _muxpin;
      temp = temp << 1;
      if (_numMuxPins > 8) PORTB = PORTB & B11100001;
      else PORTB = PORTB & B11110001;
      //PORTB = PORTB & B11000011;
      PORTB = PORTB | temp;
      }

      Parece que funciona.
      Probaré para Mega 2560.
      gzk187@hotmail.com

      Delete
    7. Hola...

      Para Arduino MEGA2560....

      pinMode(24, OUTPUT);
      pinMode(25, OUTPUT);
      pinMode(26, OUTPUT);
      if (numPins > 8) pinMode(27, OUTPUT);

      mas abajo...

      void Button::muxUpdate()
      {
      byte temp = _muxpin;
      temp = temp << 2;
      if (_numMuxPins > 8) PORTA = PORTA & B11000011;
      else PORTA = PORTA & B11100011;
      PORTA = PORTA | temp;
      }

      Y...

      void Pot::muxUpdate()
      {
      byte temp = _muxpin;
      temp = temp << 2;
      if (_numMuxPins > 8) PORTA = PORTA & B11000011;
      else PORTA = PORTA & B11100011;
      //PORTA = PORTA & B11000011;
      PORTA = PORTA | temp;
      }

      Tambien parece funcionar.
      gzk187@hotmail.com

      Delete
    8. He usado los arduinos con 2 multiplexores analogicos 74hc4067 conectando los pines S0, S1, S2, S3 en los pines modificados anteriormente en su mismo orden

      micro:
      S0 ---- pin2 ------> pin15
      S1 ---- pin3 ------> pin16
      S2 ---- pin4 ------> pin14
      S3 ---- pin5 ------> pin8

      mega2560:
      S0 ---- pin2 ------> pin24
      S1 ---- pin3 ------> pin26
      S2 ---- pin4 ------> pin27
      S3 ---- pin5 ------> pin28

      gzk187@hotmail.com

      Delete
  3. Another nice build Mr. NoteVolts! I am gearing up for this. I also am curious to the code which makes this only work on the Uno...bcuz of course im going to try it on these Mini-pros i have over here heheh, so if it works BOOM! I'll post what ever happens. So glad you have the energy so I can learn some more stuff!! Thx Dave!

    ReplyDelete
    Replies
    1. Hi Ben. Thanks for the encoragement! The reason that this code is currently for the UNO only is due to the direct port manipulation routine I am using to speed up the read times. This would have to be changed to make it work on different Arduino models.

      Delete
  4. Nice tutorial, I think that 10k pots is only optimum when one pot is used, and is the recommended optimum value for arduino input ports (though it works with much higher values it is a matter of speed of conversion to use near to 10k values) but:
    When more than one pot is used, there is going to be less resistance between the gnd and vcc pins of each pot, resulting in equivalent use 1.5kohm pots !
    And while it will still work ; it will just make you source more current from the arduino and might be dangerous for the board. To solve that problem, you need to increase the resistance value of the pot according to the number of pots you have. As an example if you plan to use 6 pots, anything between 50k and 100k will do and will results in less current consumption.
    I think this especially matters if you get the current from the arduino directly and you plan to use it for other devices as well and if you plan to use a battery power source.

    ReplyDelete
    Replies
    1. Hi FF. This is actually incorrect. The ATmega328P chip on the arduino Uno only has one ADC input. The six analog inputs on the board a read one at a time through a multiplexer so only one pot is active at any given time. Even then, the ADC actually draws very little current.

      According to the spec sheet for the ATmega -"The ADC is optimized for analog signals with an output impedance of approximately 10k or less.".

      The ADC works by charging a capacitor through the resistance of the pot. Adding a higher value pot in the range of 100k will slow down this charging time and could result in less accurate readings.

      Delete
    2. He wasn't talking about the ADC :) He was saying all the pots are in Parallel and connected to the Arduino's 5V output, decreasing the total Parallel resistance of the circuit, which will put more load on the Arduino's voltage regulator. The total resistance of the parallel of the pots is around 1600 Ohms. The current the circuit will draw is I = U/R = 5 / 1600 = 0.003A = 3mA. It is not much, and the regulator will probably handle it well, but as said above, if you have the circuit battery powered, it might make a difference.
      Also I have been using 100K Pots with arduino without a problem. Normally Guitar Volume pedals use around that value. at least mine does.. :)

      Delete
  5. This comment has been removed by the author.

    ReplyDelete
  6. can i make this with "Arduino Mega" using this programming code ?

    ReplyDelete
    Replies
    1. i am using a mega and the buttons work but am having an issue with the pots,,,

      Delete
  7. I am also looking for Mega2560 program . Please if anyone has the solution , that I would be of great help.

    ReplyDelete
    Replies
    1. sorry for my english, i'm french!

      Delete
  8. hi dave,,
    i got the pot to work but it sends a cc message in 1 line only then if i continue to turn the pot it sends notes,,,using mega bd,,,thx

    ReplyDelete
  9. hi dave,,in regards to the pots sending out notes ,do you think its a mega bd issue,,i can simply get a uno bd if you think that is the problem.thx

    ReplyDelete
    Replies
    1. Hi Terry. This code on;y works with the Arduino Uno. See the section under "Before you Start" for details.

      Delete
    2. I try it first with my arduino uno adeept the pots doesn't work then with arduino mega it does the same can you help us?

      Delete
  10. hey there i am trying to run this code using 16 pots connected through analogue mux and it just will not compile i get this from the dude ..MIDI was not declared in this scope on the line that begins,, if (potmessage != 255.. in the void muxpots section the create_mdi_instance lines not working either so i tried to comment it out i am noob to this any help much appreciated

    ReplyDelete
  11. Arduino: 1.6.13 (Windows 10), Board: "Arduino/Genuino Uno" MIDI_Controller_v1-2:54: error: 'PO1' was not declared in this scope Pot *POTS[] {&PO1, &PO2, &PO3, &PO4, &PO5,}; ^ MIDI_Controller_v1-2:54: error: 'PO2' was not declared in this scope Pot *POTS[] {&PO1, &PO2, &PO3, &PO4, &PO5,}; ^ MIDI_Controller_v1-2:54: error: 'PO3' was not declared in this scope Pot *POTS[] {&PO1, &PO2, &PO3, &PO4, &PO5,}; ^ MIDI_Controller_v1-2:54: error: 'PO4' was not declared in this scope Pot *POTS[] {&PO1, &PO2, &PO3, &PO4, &PO5,}; ^ MIDI_Controller_v1-2:54: error: 'PO5' was not declared in this scope Pot *POTS[] {&PO1, &PO2, &PO3, &PO4, &PO5,};

    ReplyDelete
  12. hi guys,

    i was wondering if i would be able to get away without making the midi jack circuit but just connecting the uno with the normal usb 2 port.

    what do you think?


    ReplyDelete
    Replies
    1. Hay varios programas para lograr dicha conversión, y tendrías que modificar el código en el Voip setup serialmidi

      Delete
  13. Does it work with the midi mapping of VoiceMeeter Banana?

    ReplyDelete
  14. Hello, nice work!! Thank you for sharing. I need to dig into the code but quick question --- does the current implementation support sending SysEx messages and not CC? Thanks!

    ReplyDelete
    Replies
    1. is there an update on sysex potentiometer?

      Delete
  15. This doesn't only just work with the UNO. I got it working with the Pro Mini.

    ReplyDelete
  16. Hi - Thanx for a very nice job ;-)

    I would like to use your project for a box to use with 1 to 6 expression pedals through a stereo jack input. I have tried it out with one expression pedal so i suppose it will work with 6 as well when you do the correct setup in the software - is this correct ?

    Anyway when i dont attach an expression pedal, then the box put´s random midi messages. Is there a way to use maybe a resistor on the analoge inputs in order to keep the unused inputs "silent" when no expression pedal is connected ?

    I would also like to make 4 other inputs for the digital inputs (for note, sustain and other simple midi commands) using momentary switches - i belive there would the same problem if no switch is connected - is this correct ?

    Last i would like to use a midi input which would be merged to the midi out, in order to insert the box and not needing an extra midi input - can i use your midi input hard and softwaere soloution and add the code to the potentiometer software ?

    nice regards

    Henning Flintholm

    ReplyDelete
  17. This comment has been removed by the author.

    ReplyDelete
  18. If anyone is wanting usb MIDI without the extra wiring (MIDI output/input) I had success with using hairless MIDI with loop MIDI.

    I modified my version of the script so hat the setup now reads

    void setup() {
    MIDI.begin();
    Serial.begin(115200);
    }

    Then set up hairless MIDI accordingly. Hope this helps.

    ReplyDelete
  19. hi
    where do you buy the knobs for your product.

    I am having an hard time in finding them

    ReplyDelete
  20. im got error, help me :

    Arduino: 1.8.3 Hourly Build 2017/03/23 09:33 (Windows 7), Board: "Arduino/Genuino Uno"

    E:\Study Room\Programming\Tutorials Library\Video Tutorials\arduino\MIDI Controller\MIDI FILE\MIDI_Controller_v1-2\MIDI_Controller_v1-2.ino:1:18: fatal error: MIDI.h: No such file or directory

    #include

    ^

    compilation terminated.

    exit status 1
    Error compiling for board Arduino/Genuino Uno.

    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.

    ReplyDelete
    Replies
    1. hey i got solution for yr problem ...dont change the midi library file name ..leave the names as you download it..if you change the Midi Library files name...fatal error: MIDI.h: No such file or directory will occur ..hope it will help

      Delete
  21. This comment has been removed by the author.

    ReplyDelete
  22. This comment has been removed by the author.

    ReplyDelete
  23. hello is there a way to get this with a midi input?
    So I can connect this from my pc to my synth using the arduino as a CC controller?

    ReplyDelete
  24. Hello Dave, excellent project, I already mounted mine and it was great, congratulations and thanks for sharing with us, I would like to know if it is possible to modify the code to change the midi channels direct by the controller. Since I thank you (sorry my English, I am Brazilian and is translated).

    ReplyDelete
  25. First off all thank you for providing such a detailed video with step to step instructions. great thing!

    I am curious if somebody in the end modified the code to use it with the Mega 2650? Because I saw there where some discussions about it. Or @Dave can you provide a code form the mega yet?

    ReplyDelete
  26. Hi, i wonder if there is a way how increase read of difference between old and new value on pots. So the pot will not react on small changes. the thing is that i have used cca 30 pots on mixconsole but some of them keep sending messages with very small change. I would like to make all of knobs bit less sensitive so when i want to learn midi knob in software it would not get milions of noise signals. I belive that has to do something with sheet controller.cpp but i am not sure witch part is it. Thank you for any idea

    ReplyDelete
  27. Hi, I really appreciate the tutorials. I'm a complete beginner but I managed to set up the circuit. The problem is I'm trying to make a midi controller with pitch bend and I'm unsure how to modify what you've done to make that work. I'm eventually going to get a photo interrupter and encoder strip from a printer to control pitch bend but for now I'm sticking with your tutorial and using a POT. It looks like you left room for the command parameter to be customized but I don't know how. Any advice? Thanks!

    ReplyDelete
  28. Hi everyone. First sorry for my English,but I'm from Poland. I was bulid a Midi interface on Arduino Nano and if I used max 2 potentiometers with 74hc4051 they works good. But if I connected two multiplexer and 16 potentiometers - this project doesn't work good. Only first and 8nd a little work. Can U help to solve my problem?

    ReplyDelete
  29. Hi, Dave, I got a keyboard to control and it was great. I would like to include an octave up and down octave. Would it be possible to add this in your code?

    ReplyDelete
  30. Hi Dave,
    I downloaded your Arduino MIDI Controller program. Thank you for sharing it!
    Instead of a potentiometer I use a pressure sensor to control the Breath Controller CC Messages. But there is one little problem, in my MIDI Monitor I get low values even when i don’t blow in the sensor.
    Is it possible to write some kind of threshold in the code? How can i do this?

    ReplyDelete
  31. Hi! I am making a system in wich i use your midi controller with two potenciometers to send signals to another arduino using your MIDI CC code, but a little changed, the result was fantastic and i wanted to know if there is a way to record the cc messages in a software using a midi interface in order to play them back to the arduino using the servos. Thank you very much

    ReplyDelete
  32. Hi, Is there anybody has tried connect this to DAW software via USB MIDI cable? I have connected it by USB MIDI cable. The MIDI cc signal became none continued, CC signal only transmit one data each time I turn the knob. But it worked correctly when I connect it to my Synthsizer. I want to use it to control my able tone live. Is there any suggestion to connect PC which has no MIDI port?

    I mentioned USB MIDI cable that is I bought it from China. The cable is USB to MIDI 5pin. I connected the 5 pin MIDI to the Arsuino. The USB to my computer.

    ReplyDelete
  33. Hello how can I modify the code, so Pot1 will send the message to few channels? Thank you, one of the best projects for Arduino!

    ReplyDelete
  34. Hi, is this gonna work for the arduino uno I mean?
    tks for your help
    Seby

    https://www.amazon.ca/Elegoo-Project-Starter-Tutorial-Arduino/dp/B01D8KOZF4/ref=sr_1_2?s=electronics&ie=UTF8&qid=1543529352&sr=1-2&keywords=arduino+uno+kit

    ReplyDelete
  35. I have done everithing like it´s in the video but for some reason it doesn´t work. I have connected the arduino with a usb cable, and the midi with a USB/MIDI cable. I dont know why it doesn´t work. Can someone please help me?

    ReplyDelete
  36. hi Dave. i am a super DIYer person. But i have never been so excited by making something by myself like this. Thanks a lot. for sharing software and tutorial. That was my dream to making my midi devices. İ d like to make a giant midi controller which has 128 potansiameters. Is that possible by using 8 multiplexer(8*16=128)?

    And second, as many guys said before, please show us usb hub midi controller. Because most of us has only 1 midi in port on the sound card. and we can use many midi devices.

    i ll be glad if u answer me.

    ReplyDelete
  37. Hi i'm currently using this project to help me get a grips on arduino midi and was wondering what purpose the "void newValue()" serves. any help and advice would be appreciated thanks.
    J

    ReplyDelete
  38. Hello,

    Please explain how to add LED indication, when moving the pots...

    ReplyDelete
  39. What are the lines of code that limit it to the UNO?

    Thanks

    Robin

    ReplyDelete
  40. everything works perfect until I connect potentiometer number 4, which sends midi signals constantly, even if I do not touch it.
    What could be the problem?.

    ReplyDelete
  41. The potentiometer I'm using doesn't need to rotate 360 degrees, only about 180. Is it possible to 'calibrate' the code in some way to use the full 1024 MIDI steps, but only from half the pot rotation?

    ReplyDelete
  42. Wow, I was trying to modify some of the plans for the groove sizer red for my own synth project because I thought that was a good starting point for what I wanted to accomplish. Hit many snags and had trouble following their code but with your tutorials I feel much more confident I will be able to build what I am wanting. Thank you so much for all the time you spent putting this together!!!

    ReplyDelete
  43. Before i begin with my Question i want to thank you for your encouragement the website and oppertunity for us few nerds that want to build something like this on our own.

    I want to build myself a Midi Controller with 6 Potentiometers and want to use your code. IS IT POSSIBLE to add a rotary switch so i can add 6 Banks. So i will be able to control 36 Knobs in my DAW? Do i need to use digital rotary encoders or is it possible to use my analog Potentiometers and still be able to change the address?

    Thank you and Best regards Michael!

    ReplyDelete
  44. When i try t upload the code on a nano, it won't load, and states no file or directory MIDI.h, any pointers greatly appreciated

    ReplyDelete
  45. Hi there how to make this project with more than 6 pot ?

    ReplyDelete
  46. Hola.. es posible agregar a este código un lcd 16x2 para modificar los comandos, cc y ch midi?

    ReplyDelete
  47. hello, any code to include encoder?
    thank you

    ReplyDelete
  48. how could I modify the code to add a pitchbend control? (it would be a pot). thx!!

    ReplyDelete
  49. Hi there, amazing work and website.
    I was wondering if you had a project/code for a simple midi controller (Arduino Uno) using only 12 potentiometers (CC 1 to 127)

    ReplyDelete
  50. Please I have seen people writing different code on this page for mega 2560. I haven't start my project but I have some fears that Dave's code wouldn't work with my mega2560. So please if there is any solution so that we can use this code on atnega 2560 then make it a file and share it to as please.

    THANK YOU.

    ReplyDelete
  51. Hello, this mod worked better for me, since it works on any track selected, I have 8 sliders and had assigned them to 1-8, but can’t do anything to tracks 8 and over, I thought it could move like scenes, 1-8, 9-16, 17-24 etc, but couldn’t make it work, any suggestions? Thanks.

    ReplyDelete
  52. ola, projeto muito bom, porem estou com oscilaçoes nos pots, ja soldei capacitores, me ajuda por favor.

    ReplyDelete
  53. hank you for all your explanation.
    I would like to go further in your code to use encoders which would control cc's. I do not know how to do. THANKS

    ReplyDelete
  54. Thanks for your great teaching! You inspired me to learn this stuff, I just finished my first controller using your code? Works solidly!

    ReplyDelete
  55. Hi, any help getting this to work on Arduino nano Every, I only want to use one pot. Help appreciated!

    ReplyDelete