If you keep using single IO ports of the Arduino for your controls you reach the limits pretty quickly. In terms of analog IO that is six inputs for an Uno and eight for a Nano. The solution is relatively straightforward however, use a multiplexer.
This project inserts a 74HC4051 eight port multiplexer into the Arduino MIDI Step Sequencer to allow the use of eight potentiometers with an Arduino Uno.
- In part 2 I use an off-the-shelf module for a neater result.
- And here I show how to extend it to multiple multiplexers.
Warning! I strongly recommend using an old or second hand keyboard for your MIDI experiments. I am not responsible for any damage to expensive instruments!
These are the key Arduino tutorials for the main concepts used in this project:
If you are new to Arduino, see the Getting Started pages.
Parts list
- Arduino Uno
- 8x 10k potentiometers
- 1x 74HC4051 (or similar) eight port multiplexer chip or breakout module
- MIDI out module (for examples, see Arduino MIDI Interfaces)
- Breadboard and jumper wires
The Circuit

You can get multiplexers as single devices or breakout boards. Sparkfun do both 8-port and 16-port multiplexers for example based on the 74HC4051 and 74HC4067 respectively, which makes them very easy to use.
Don’t forget to wire in the extra three pots – in the diagram I’ve not fully connected up the bottom row of potentiometers as it would obscure the other wiring.
For this example, I’m using a 74HC4051 directly in the “dual in-line” (DIP) format which is easily inserted into a solderless breadboard as shown below.

The basic principle is that the multiplexer acts as a set of digital switches, connecting a single input on the Arduino (in this case, although it can work the other way round) to up to eight input sources (in this case eight potentiometers).
There are three control lines to the device which allow you to choose which of the input sources you wish to be connected at any one time.
There are additional control lines for the multiplexer (an enable pin and a pin that allows its use with negative supplies) but these are simply connected to GND.
The only remaining connection is the output of the multiplexer which needs connecting to one of the Arduino analog input pins – I’m simply using A0.
For a great tutorial on the use of multiplexers as MIDI control devices, see this Notes and Volts video.
The Code
The basic idea is the same as the Arduino MIDI Step Sequencer but instead of cycling through each Arduino input pin directly, we cycle through the input sources on the multiplexer instead.
The basic code structure is thus something like this:
setup () Configure the MUX control pins as outputs loop () Set the control pins on the MUX for one of the input sources Read the Arduino's analog input pin Play the appropriate MIDI note Move on to the next input source on the MUX Do it all again
When it comes to selecting which input on the multiplexer to use as the input source, for the eight port device there are three control pins. For the sixteen port device there are four.
The simplest way of thinking about this is to treat these as a three or four bit binary number. So, for example, for the eight port device, the control pins choose the input port as follows:
Input source S2 S1 S0
0 0 0 0
1 0 0 1
2 0 1 0
3 0 1 1
4 1 0 0
5 1 0 1
6 1 1 0
7 1 1 1
Which means I can keep using my “playingNote” counter as the indicator of which input source to use – I just need to map the number to the appropriate digitalWrite() calls to set the output pins accordingly.
if (playingNote & 1) { digitalWrite(MUX_S0, HIGH);
} else { digitalWrite(MUX_S0, LOW);
}
if (playingNote & 2) { digitalWrite(MUX_S1, HIGH);
} else { digitalWrite(MUX_S1, LOW);
}
if (playingNote & 4) { digitalWrite(MUX_S2, HIGH);
} else { digitalWrite(MUX_S2, LOW);
}
There are more compact ways of achieving this (for example, see the tutorial on the Gammon Forum), but this will do for now. Each IF statement basically says “if the bit in the playingNote number is set, then set the corresponding output pin to HIGH, otherwise set it LOW.
To extend to a sixteen port device, just add a fourth control pin hanging off (playingNote & 8).
Everything else in the code is basically the same as before.
Closing Thoughts
Adding more multiplexers is relatively trivial too – they can share the same control pins but just need another input pin at the Arduino end to use. So in principle we could stack up six of these eight-port devices for a total of 48 inputs using A0 to A5. If we used sixteen port devices (needing a fourth control pin of course) we could have up to 96 inputs on A0 to A5 or 128 with an Arduino Nano using A0 to A7.
With anything more than a single device though, we really need to commit it to stripboard.
There is a “MUX shield” which apparently supports up to 48 devices, but it isn’t easily available to me to try (or buy). But it might be interesting to make a simple shield for one of the Sparkfun modules.
A multiplexer can also be used to add more digital inputs, so it could be used for buttons too, but there are possibly better ways to scan a lot of buttons…
There are also some interesting possibilities if I hook up an array of LDRs instead of potentiometers.
Kevin