Sunday, 10 July 2016

Arduino MIDI Controller: Multiplexers

More, More, More!!

Over the last couple of tutorials we have been building up a MIDI Controller using a trusty Arduino UNO board. So far, we've learned how to connect buttons and potentiometers to the controller and generally had a lot of fun.

"But Dave!! I want to build a custom controller with a zillion pots and buttons! The UNO only has six measily analog inputs and a handful of digital ports! What can I do????"

Never fear! We can add lots of controls to our project with the help of Multiplexers.

Watch This!

What is a Mux?

A Multiplexer is a chip with multiple inputs that can be individually connected to a single output. By sending different combinations of signals to some control pins, each button or pot connected can be read by a single pin on the Arduino. The video explains this in detail.

We will be looking at two popular multiplexers in this lesson. The first is the 74HC4051 which has 8 inputs. The second is the 74HC4067 which has a impressive 16 inputs.

The Software

The Midi Controller program we have used in previous lessons can handle either type of multiplexer with some simple configuration. The video will show you how. Download the software HERE if you don't have it yet.

Stuff you need (With Amazon links)

Here are the parts you will need to do the experiment:

Arduino UNO or Arduino UNO (Official Adafruit Version)

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

2 x Push Button Switch

74HC4051 Multiplexer (8 Input)
74HC4067 Multiplexer (16 Input)

Breadboard (63 pin width)


2 x 220 Ohm Resistors

Jumper Wires

MIDI Cable


  1. Hi!
    How to install leds for the buttons, if i want that when I push the button the led is lightning?
    Thanks You! :)

  2. This comment has been removed by the author.

  3. How do I put 2 74hc4067? They are connected in series or parallel?

  4. I can not use more buttons in ... Y2... Y7 imputs. I need to change something to use only buttons?

  5. I used buttons Yo, Y1, Y2, Y3 but not get in the other Imputs.

  6. Can I use Analog and Digital at the same time with this Program?

  7. Hi. Many Tks for this blog and this prog.
    May I share my experiment.
    Yes you can use analog and digital at the same time but it has to be one DEMUX board for each.
    I have manage to use up to 3 full DEMUX board but the arduino won't cope a fourth full used board due to lack of memory.
    My project is a 30 fader midi interface for a lighting program.

  8. FYI modified Controller.cpp for the MEGA on pin 22-25:
    #if defined(__AVR_ATmega2560__)
    void Button::muxUpdate()
    // set S pins on MUX in correct value to read value : eg read Y2: S2-S1-S0 = B010
    // pins used on MEGA: 22 (PA0), 23 (PA1), 24 (PA2), (25 (PA3))
    // set MUX S-pins LOW
    if (_numMuxPins > 8) PORTA = PORTA & B11110000;
    else PORTA = PORTA & B11111000;

    // add value of temp to PORTA (= add value of the required channel, so set the correct pins)
    PORTA = PORTA | _muxpin;

    #elif defined(__AVR_ATmega328P__)

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

  9. This comment has been removed by the author.

  10. Thanks for this well-explained video tutorial! I don't know enough about C to figure out whether your controller library can be modified to allow "coarse" (7-bit) NPRN parameters to be assigned to pots / buttons on this shield project.

    However, it seems if an NRPN flag is added to the "command" variable, and if the "note number" / "byte command" variables can hold a 14-bit value for the number of the NRPN parameter to change, then a routine could be added to issue the 9 bytes that make up the NPRN parameter change command (CC / #99 / MSB of NPRN parameter / CC/ #98 / LSB of NPRN parameter / CC/ #6 / 7-bit parameter value to send).

    Is this possible?

  11. Thanks notesandvolts for this tutorial! and thanks again!

  12. hi, i dont understand why but i can't manage to get more pots on multiplexer going right. I use Arduino atmega2560 i did everything as in the tutorial and when i connect more than one pot to it, change program, and suddently it does not work. The first one what was working like a charm when was single on multiplexer after connecting second one start giving random CC number and channel too, the second one does not react at all.

    1. Hi Neytal Dub,

      Kind of have the same problem with the Arduino Uno. The Mux seems to send a lot of noisy data. Did you manage to solve that issue ? Dave, have you ever encountered such situation ?

      Thank you for the great tutorials btw !

    2. Hi,
      I have the same issue with the signal out of the multplexer. I don't know how to correct it. I tryed resistors IN or OUT, nothing works.
      I have 2 midi signals, one when I push and one when I released the button. I don't understand that too.
      If you have informations, I take !

      Thanks a lot for the tutorials Dave

  13. This has been the tutorial I have dreamed of for midi on arduino. The only issue I'm having is it doesn't appear the arduino is storing the sketch. I can upload the sketch and it functions correctly. Once I disconnect the USB cable and reconnect, the sketch does not boot. Google says I have a bad bootloader, however any arduino example sketch uploads and stores like normal. The program doesn't appear to be too big. What am I missing? Thanks in advance and love the channel!

    1. Fácil de solucionar ese problema, tienes que convertir tu Arduino en un dispositivo HID, BUSCALO EN GOOGLE 'HIDuino' , a mí me funciona excelente.