Home > Ideas > Sensor – Transducer – Detector Project Ideas > Muxing Around With The CD74HC4067 + Arduino

Muxing Around With The CD74HC4067 + Arduino

Summary of Muxing Around With The CD74HC4067 + Arduino


This article explains how to use the CD74HC4067 analog multiplexer with an Arduino to read 16 analog sensors using only four digital pins. By configuring the mux in binary mode, users can switch between channels to read multiple potentiometers efficiently. The tutorial covers hardware connections, including the enable pin and breakout board options, along with a code function that translates channel numbers into pin states for reading analog values.

Parts used in the CD74HC4067 Multiplexer Project:

  • CD74HC4067 Analog Multiplexer/Demultiplexer
  • Arduino or other microcontroller
  • SparkFun breakout board SSOP version (optional)
  • 16 Potentiometers
  • Breadboard
  • Digital pins (S0, S1, S2, S3)
  • Analog pin 0 (SIG)
  • Enable (EN) pin
Have you ever found yourself running out of pins to read an array of analog sensors? Don’t worry, you’re not alone, it happens to the best of us, and there is something you can do about it. An analog / digital multiplexer like the CD74HC4067 (mux for short) can help multiply the amount of pins you have, and it is insanely easy to connect to your arduino or other microcontroller

The CD74HC4067 is a 16-Channel Analog Multiplexer/Demultiplexer. It is available in a breadboard-ready DIP package, or, if you are as addicted to breakout boards as I am, SparkFun offers a breakout board SSOP version. What it allows you to do is use 4 digital pins, to control the flow of one pin to 16 others. It can actually be used in either direction, and even with serial or other digital interfaces. For this tutorial we are just going to read the value from 16 pots because buying 16 analog sensors for this would have been overkill.

A multiplexer of this sort really just acts as a 16 to one 1 switch. The 4 digital pins are used to set HIGH or LOW, in a binary fashion (0-15) to determine what pin “SIG” is connected to. So bringing all 4 pins LOW would switch the CD74HC4067 to channel 0 (so SIG and C0 would be connected), bringing them all HIGH would switch it to 15 (so SIG and C15 would be connected). It is simple binary, but in the off chance you are one of the 99.8% of the world who doesn’t know binary, here is a simple table on the right.

The schematic may seem complicated, but it is not. Not at all. And to prove it, look at the version on the left with out the pots; Much easier, right? The potentiometers are just connected with to ground and 5v, and the middle pin connected to one of the 16 channels on the CD74HC4067. 16 pots is just enough to make anything look scary little scary. Also of note is the EN, or enable, pin. The EN pin is a kill switch: pull it up to 5v to disable all channels, and ground it to enable them. Im just going to leave it at ground so we can use it and simplify things, but feel free to connect it to a digital pin, and control when the mux is enabled or disabled.Schematic Muxing Around With The CD74HC4067 + Arduino

Nice and simple right?

For the code example I just took the binary table, made it into a simple array, and put it in a function that does this: You give the function a number 0-15. It looks up that number in the binary array, then it loops through those 4 numbers and sets S0, S1, S2, and S3 appropriately. (In the arduino software HIGH is the same as1 & LOW is the same as 0). After it sets the pins so that SIG is connected to the correct channel, it then reads analog 0 (where SIG is connected to) and returns that value. So all you need to do is something like this

For more detail: Muxing Around With The CD74HC4067 + Arduino

Quick Solutions to Questions related to CD74HC4067 Multiplexer Project:

  • How many digital pins are required to control the CD74HC4067?
    Four digital pins are used to set HIGH or LOW in a binary fashion to determine which channel is connected.
  • Can the CD74HC4067 be used to read analog sensors?
    Yes, it acts as a 16 to one switch allowing you to read values from 16 analog pots using one analog input.
  • What is the purpose of the EN pin on the CD74HC4067?
    The EN pin acts as a kill switch; pulling it up to 5v disables all channels while grounding it enables them.
  • Does the CD74HC4067 work in both directions?
    Yes, it can be used in either direction and even with serial or other digital interfaces.
  • How do you select channel 0 on the CD74HC4067?
    You bring all four digital control pins LOW to switch the mux to channel 0 connecting SIG and C0.
  • What package options are available for the CD74HC4067?
    It is available in a breadboard-ready DIP package or a SparkFun breakout board SSOP version.
  • How does the provided code function select a specific channel?
    The function takes a number 0-15, looks it up in a binary array, and sets S0 through S3 accordingly.
  • Is the schematic complicated to build?
    No, the schematic is described as simple, with potentiometers just connected to ground, 5v, and the channels.

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter
Scroll to Top