[tutorial] MUX74HC4067

MUX74HC4067 Tutorial from codebender on Vimeo.

This is a tutorial on the MUX74HC4067 library.


The name of the library refers to the IC that is on the Analog/Digital MUX Breakout from Sparkfun. This IC is a 16-channel analog multiplexer/demultiplexer. You can think of it as an SP16T switch that is digitally controlled. You position the switch by writing to the control pins and then you let the data flow in either direction.


You can use this module to increase the number of inputs and outputs on your Arduino, since it only needs 6 or 5 pins to provide access to 16 data lines. You could connect to these 16 lines… sensors, buttons, transistors to control relays, or even serial lines from other Arduinos.


The SIG pin connects to any of the 16 channels, C0C15. S0 to S3 are the control pins. You write to these pins a binary code, and the corresponding channel is selected. For example, by writing 1010 to S3 S2 S1 S0, the C10 channel gets connected to the SIG pin.


There is also the EN pin that if driven HIGH, it disables the connection of the SIG pin with any of the 16 channels.

The maximum current that can go through a channel is 25 mA. If you need to power things like relays, solenoids, or motors, you will need to use transistors, and pass through the channels only the control signals.


This example assumes there are push buttons with pullup 10 kOhm resistors connected to the 16 channels like in the following figure.


The code reads the input from all the channels, one after the other, and prints on the serial monitor a statement about whether a push button is pressed or not.

All you have to do is declare a MUX74HC4067 instance, configure as a DIGITAL INPUT the Arduino pin to which the SIG pin connects, and you are ready to read from the channels. Just call read with argument the channel number and read will return either LOW or HIGH.


This example assumes there are potentiometers connected to the 16 channels like in the following figure.


The code takes measurements of the potentiometers’ values and prints on the serial monitor a statement about that value.

By configuring the signal pin as an ANALOG INPUT and then calling read, you get back the value measured by the A/D converter. It’s an integer from 0 to 1023.


This example assumes there are 16 LEDs with current limiting 150 Ohm resistors and the positive leads of the LEDs are connected to the 16 channels like in the following figure.


The code just lights up the LEDs, one after the other. You configure the signal pin as a DIGITAL OUTPUT and then you write to a channel by calling the write method and providing as arguments the channel number and a LOW or HIGH value.


The circuit for this example is identical to the previous one. The difference here is that the output to the LEDs is a PWM signal.

You can output a PWM signal, by configuring the signal pin as an ANALOG OUTPUT and then calling the write method and providing as arguments the channel number and a value (0 to 255) for the duty cycle of the PWM signal.

That’s all folks. We hope you enjoy this library, and if you have any comments or suggestions you can contact us at girder [at] codebender [dot] cc

Sounds are from freesound.org. Schematics were based on Fritzing.


  1. Ammirmohammad

    05 Dec 2014 08:52:11

    Hi Nick,
    Your article was very nice!. I simulated the multiplexer with 14 logicstates in proteus. I wrote a program in codevision avr that checks the bits that comes from output pin and it shows the bits on LCD 2*16.
    I want to make a line follower with this multiplexer and command to motors when start to spin. I took a screenshot out of my project. as an example if 2 sensors in the middle are 1, then the motors turn on and so on. I can’t sync with multiplexer(4067).
    I hope you can help me.

    • Nick Lamprianidis

      05 Dec 2014 14:49:44

      Hey Amir,

      Sadly you are not giving me much with your problem description (“I can’t sync with multiplexer(4067).”). Would you care to elaborate?


      • Ammirmohammad

        05 Dec 2014 17:05:37

        Hi again,
        My problem is that i cant make an if statement in my codes.
        i tried this code by giving it address:
        if(D==1&&C==1&&B==1&&A==1) {
        //do something
        OR (out pin is set to PINA.0 and 15th sensor named sensor15)
        if(sensor15==1) {
        //do something
        if(PINA.0=sensor15) { //even PINA.0==sensor15 didn’t work
        //do something

        PLZ help me…

        • Nick Lamprianidis

          16 Dec 2014 18:45:45

          Hey Amir,

          Sorry for the delay, I hadn’t noticed your reply.

          From what you’ve mentioned, I understand that you have problems running your program. There could be a few things that are going wrong, I’ll try to give some hints:
          * If you’d like know more about if statements please read here.
          * You can’t have variables with dots in their names, so PINA.0 is not valid.
          * Make sure that before you use any variable, you have defined it.

          And then, what are all those variables? Have you assigned them any values from the multiplexer? Are you using my library, MUX74HC4067? Please provide as much information as possible, so I can help you.


  2. Mayank Gulati

    17 Mar 2015 22:08:58

    Hi Nick, you say that the diagrams are based in Fritzing, but I am unable to locate any frtizting file for the mux74hc4067 part… would you be able to share yours?

    • Nick Lamprianidis

      17 Mar 2015 23:01:06


      Only parts of my diagrams are borrowed from Fritzing. In this case, the MUX74HC4067 is an actual photo of the module from Sparkfun.

  3. benjamin

    22 Dec 2015 12:37:17

    Hello, very nice post,
    i got some question for you, on your readDigitalSignals example did you manage cases of multiple impultion (i.e. if you press at the same time on the button 1 and 2)?

    thanks Nick.

    • Nick Lamprianidis

      24 Feb 2016 18:19:26

      Hey Benjamin,

      In order to read the value on a channel, you call the read(<channel>) method (as in the example). So, as long as you call this function fast enough (or your presses are slow enough), you can sample all your buttons at a specific moment. But, there is no real “at the same time” capability here, since you poll only one channel at a time.


  4. David

    23 Feb 2016 04:37:29

    Hi Nick,

    How could I use 3 of these boards together to read analog pots with this library? I have the example working well for 1 board, but what about using multiple boards?


    • Nick Lamprianidis

      24 Feb 2016 18:36:28

      Hello David,

      The easy way would be to just connect any additional modules in parallel, the same way you connected the first one. This means you’ll need 6 pins for each module. So, as long as you have enough pins on your uC, you connect as many as you want (although I’m guessing it won’t be practical if you’ll want to do frequent sequential accesses).
      The other way would be to use similar mux/demux modules to pick which MUX74HC4067 module to use each time, and basically share the 6 pins required on the arduino. But that’s not trivial to implement (neither easy for me to describe in a few sentences).


  5. Fynx

    20 Mar 2016 23:59:32

    Hi Nick,

    Your Tutorial is very useful. Does your library support connecting 2-3 of this MUX chips? If so, do you also have a diagram that support’s this?

    Thanks a lot.

Leave a Comment

Stay tuned:

* we promise that we won´t spam you, never.