Components · 9 min read

CD74HC4067 Arduino: 16-Channel Multiplexer for More Analog Pins

CD74HC4067 Arduino guide: read 16 sensors from one analog pin, S0–S3 select bits, signal direction, Uno, ESP32 and Pico code, a MIDI controller, vs 74HC4051.

Pairing a CD74HC4067 with an Arduino is the cheapest way to read 16 different sensors or potentiometers from a single analog pin. The CD74HC4067 is a 16-channel analog multiplexer: it closes just one of its 16 electronic switches and connects the channel you pick to the common SIG pin. Four digital pins (S0–S3) decide which channel is selected. So when the Arduino Uno's 6 analog inputs aren't enough, you spend 5 pins and get 16 analog inputs.

In this article you'll learn how the chip works, its pins, how the channel select bits are built from binary numbers, and that the signal can flow in both directions. Then you'll read 16 potentiometers with an Uno, build a 16-knob USB MIDI controller with the same circuit, set up a multi-sensor project on an ESP32 that reads soil moisture, light and potentiometers from one pin, and do the same job on a Raspberry Pi Pico with MicroPython. The last sections compare it with the 8-channel 74HC4051 and cover common mistakes.

Potentiometer
With a CD74HC4067 you can read 16 potentiometers from one analog pin

What is the CD74HC4067 and how does it work?

You can think of the chip as a rotary switch with 16 positions. The LOW and HIGH levels you put on S0, S1, S2 and S3 form a binary number from 0 to 15; the chip connects the matching channel to SIG and leaves the other 15 disconnected. The switches aren't mechanical but CMOS transistors, so changing channels takes tens of nanoseconds and nothing wears out. There's one cost: each switch has a small on-resistance (Ron). At a 5 V supply it's about 70 Ω, which doesn't matter when reading potentiometers or sensors, because the Arduino's analog input draws almost no current. Since the chip is an analog switch, it doesn't amplify or change the signal; whatever voltage is on the channel arrives at SIG unchanged.

FeatureValue
Channels16 (C0–C15), bidirectional
Supply voltage2–6 V (5 V with the Uno, 3.3 V with the ESP32 and Pico)
Signal rangeBetween 0 V and VCC
On-resistance (Ron)Typically 70 Ω at 4.5 V, higher at lower supply
Current per channelUp to ±25 mA
Select pinsS0–S3 (4 bits), EN active LOW
Channel switching timeTens of nanoseconds
Package24 pins (DIP, SOIC, SSOP); usually on a ready-made breakout board

Pins and wiring

CD74HC4067 pinFunctionArduino Uno / LeonardoESP32Raspberry Pi Pico
VCCSupply (2–6 V)5V3.3V3V3 (pin 36)
GNDGroundGNDGNDGND
SIG (COM)Common signal pinA0GPIO 34 (ADC1)GP26 (ADC0)
S0Select bit 0 (lowest)D4GPIO 25GP2
S1Select bit 1D5GPIO 26GP3
S2Select bit 2D6GPIO 27GP4
S3Select bit 3 (highest)D7GPIO 14GP5
ENLOW = chip on, HIGH = all channels offGNDGNDGND
C0–C1516 channel inputs or outputsSensor output or potentiometer wiperSameSame
The voltage on the channels must never exceed the chip's VCC. On the ESP32 and Pico, power the module from 3.3 V; if you power it from 5 V, a 5 V sensor signal goes straight from SIG to the 3.3 V ADC pin and can damage the board. On the Uno, a 5 V supply is correct. Connect the ends of the potentiometers to the same voltage as the module's VCC.

Channel select bits table

When you convert the channel number to binary, each bit matches one select pin: S0 is the lowest bit (1), S1 the second (2), S2 the third (4) and S3 the highest (8). For example, to select channel 11, since 11 = 8 + 2 + 1, you set S3, S1 and S0 HIGH and S2 LOW. In code you do this in one line with (ch >> bit) & 1: it shifts the channel number right by bit places and takes the rightmost bit. For binary numbers and bit operations, see the number systems and bitwise operations article.

ChannelS3S2S1S0
C00000
C10001
C20010
C30011
C40100
C50101
C60110
C70111
C81000
C91001
C101010
C111011
C121100
C131101
C141110
C151111

Signal direction: input, output and digital use

The CD74HC4067's switches are bidirectional: the signal can pass from Cx to SIG or from SIG to Cx. That's why the chip works both as a multiplexer (choosing one of 16 inputs) and as a demultiplexer (routing a single output to one of 16 channels). But only one channel is connected at a time, and the unselected channels float and hold no value. That shapes how you can use it.

  • Analog input (most common): Connect analog outputs such as potentiometers, LDRs, soil moisture or force sensors to the Cx pins, connect SIG to an analog pin and read the channels one after another.
  • Digital input: Connect buttons between Cx and GND, set the SIG pin to INPUT_PULLUP and read it with digitalRead. A pressed button reads LOW and a released one HIGH; 5 pins are enough for 16 buttons.
  • Output (demultiplexer): Put a PWM or digital signal on SIG and it passes to the selected channel. You could light one of 16 LEDs, for example, but the previous LED goes off when the channel changes. If you need several outputs on at once, use a 74HC595 shift register or a PCF8574.
  • Sharing a signal line: It can also route a UART or another slow signal between several devices; because of the switch's 70 Ω resistance and capacitance, it isn't suitable for high-speed data.

Reading 16 potentiometers with an Arduino Uno

  1. Connect the module's VCC to 5V, GND to GND and EN to GND.
  2. Connect S0, S1, S2 and S3 to D4, D5, D6 and D7, and SIG to A0.
  3. Connect one end of each potentiometer to 5V, the other to GND and the wiper to one of C0–C15. Sixteen 10 kΩ potentiometers draw only about 8 mA in total.
  4. Upload the code, open the Serial Monitor at 115200 baud, or open the Serial Plotter to watch all 16 lines at once.
C++ (Arduino IDE)
1// CD74HC4067 ile Arduino Uno: tek analog pinden 16 potansiyometre okuma
2// CD74HC4067 with Arduino Uno: read 16 potentiometers from one analog pin
3const int PIN_SIG = A0;                       // ortak sinyal ucu / common signal pin
4const int SELECT_PINS[4] = {4, 5, 6, 7};      // S0, S1, S2, S3
5// EN pini GND'ye bağlı: çip hep açık / EN tied to GND: chip always enabled
6
7void selectChannel(byte ch) {
8  for (byte bit = 0; bit < 4; bit++) {
9    digitalWrite(SELECT_PINS[bit], (ch >> bit) & 1);   // kanal numarasının bitleri / bits of the channel number
10  }
11}
12
13int readChannel(byte ch) {
14  selectChannel(ch);
15  delayMicroseconds(5);         // anahtar ve kondansatör otursun / let the switch and capacitance settle
16  analogRead(PIN_SIG);          // ilk okumayı at / discard the first reading
17  return analogRead(PIN_SIG);
18}
19
20void setup() {
21  Serial.begin(115200);
22  for (byte i = 0; i < 4; i++) pinMode(SELECT_PINS[i], OUTPUT);
23}
24
25void loop() {
26  for (byte ch = 0; ch < 16; ch++) {
27    Serial.print(readChannel(ch));
28    Serial.print(ch < 15 ? '\t' : '\n');      // sekmeyle ayır, Seri Çizici'de de çalışır / tab separated, works in the Serial Plotter
29  }
30  delay(100);
31}
32

The two most important lines in the code are the short wait after switching channels and throwing away the first reading. The Arduino's ADC has a small sampling capacitor; when the channel changes, it still holds the previous channel's voltage. It charges quickly if the source resistance is low, but a 10 kΩ potentiometer's wiper can reach 2.5 kΩ, and an LDR divider can be higher still. The discarded first reading moves that capacitor to the new channel's voltage and the second reading gives the correct value. The speed maths is simple too: on the Uno one analogRead takes about 112 µs; with two readings and four digitalWrite calls per channel, all 16 channels are read in about 4 ms, or 250 full scans per second. The ATmega328P's ADC is designed for source resistances below 10 kΩ; for higher-impedance sensors, wait longer or put a 100 nF capacitor between SIG and GND.

If you pick select pins on the same port, you can change channels with one command instead of four digitalWrite calls: on the Uno, D4–D7 are bits 4–7 of PORTD, and PORTD = (PORTD & 0x0F) | (ch << 4); selects the channel in under a microsecond. The details of this technique are in the Arduino port manipulation article.

MIDI controller example: 16 potentiometers

The CD74HC4067's favourite job is a knob-based MIDI controller for music software. The ATmega32U4 in the Arduino Leonardo and Pro Micro can appear to the computer directly as a USB MIDI device, so no extra driver is needed. The code reads 16 potentiometers, converts the values to the 0–127 range and sends each one as a CC (Control Change) message between 20 and 35. So that the computer isn't flooded with messages when a knob's value jitters by one step, the code applies simple smoothing and 2 steps of hysteresis; when a knob is turned all the way, 0 and 127 are always sent. The wiring is the same as for the Uno. All you need is to install the MIDIUSB library from the Library Manager. With your DAW's MIDI learn feature you can assign each knob to any parameter; details on buttons, notes and DAW settings are in the Arduino MIDI controller article.

C++ (Arduino IDE)
1// CD74HC4067 + Arduino Leonardo / Pro Micro: 16 potansiyometreli USB MIDI kontrolcü (CC 20-35)
2// CD74HC4067 + Arduino Leonardo / Pro Micro: 16-knob USB MIDI controller (CC 20-35)
3#include <MIDIUSB.h>
4
5const int PIN_SIG = A0;
6const int SELECT_PINS[4] = {4, 5, 6, 7};    // S0..S3
7const byte MIDI_CHANNEL = 0;                // 0 = MIDI kanal 1 / MIDI channel 1
8const byte FIRST_CC = 20;                   // CC 20..35 tanımsız, serbest kullanılır / undefined CCs, free to use
9
10float smooth[16];
11int lastSent[16];
12
13void selectChannel(byte ch) {
14  for (byte bit = 0; bit < 4; bit++) digitalWrite(SELECT_PINS[bit], (ch >> bit) & 1);
15}
16
17void sendCC(byte control, byte value) {
18  midiEventPacket_t event = {0x0B, (uint8_t)(0xB0 | MIDI_CHANNEL), control, value};
19  MidiUSB.sendMIDI(event);
20}
21
22void setup() {
23  for (byte i = 0; i < 4; i++) pinMode(SELECT_PINS[i], OUTPUT);
24  for (byte ch = 0; ch < 16; ch++) { smooth[ch] = 0; lastSent[ch] = -1; }
25}
26
27void loop() {
28  bool sent = false;
29  for (byte ch = 0; ch < 16; ch++) {
30    selectChannel(ch);
31    delayMicroseconds(5);
32    analogRead(PIN_SIG);                              // ilk okumayı at / discard first reading
33    smooth[ch] += (analogRead(PIN_SIG) - smooth[ch]) * 0.3;   // basit yumuşatma / simple smoothing
34
35    int value = (int)(smooth[ch] / 8);               // 0-1023 -> 0-127
36    // 1 adımlık titremeyi gönderme (histerezis) / ignore 1-step jitter (hysteresis)
37    if (lastSent[ch] < 0 || abs(value - lastSent[ch]) >= 2 || (value != lastSent[ch] && (value == 0 || value == 127))) {
38      sendCC(FIRST_CC + ch, value);
39      lastSent[ch] = value;
40      sent = true;
41    }
42  }
43  if (sent) MidiUSB.flush();
44  delay(2);
45}
46

Multi-sensor project with an ESP32

The ESP32 has many analog pins, but the ADC2 pins can't be used while Wi-Fi is on, which leaves only 6 useful pins on ADC1. A multiplexer removes that limit. In the example, 8 capacitive soil moisture sensors, 4 LDR dividers and 4 potentiometers are read from a single ADC1 pin (GPIO 34). The code keeps each channel's name and type in a table; it converts the soil sensors to moisture percent using dry and wet calibration values, maps the LDRs and potentiometers to 0–100, and prints the result as JSON. That makes it easy to send the same line to a web server or MQTT later. analogReadMilliVolts() uses the ESP32 ADC's factory calibration and is more accurate than the raw analogRead value. The capacitive soil sensors don't affect each other across channels, because each drives its own output and the multiplexer connects only the one being read. Measure the calibration values with your own sensors in air and in water and change them; the method is described in the capacitive soil moisture sensor article.

C++ (Arduino IDE)
1// ESP32 + CD74HC4067: 8 toprak nem sensörü, 4 LDR ve 4 potansiyometre tek ADC pininden
2// ESP32 + CD74HC4067: 8 soil moisture sensors, 4 LDRs and 4 potentiometers on one ADC pin
3const int PIN_SIG = 34;                        // ADC1: Wi-Fi açıkken de çalışır / ADC1 works with Wi-Fi on
4const int SELECT_PINS[4] = {25, 26, 27, 14};   // S0, S1, S2, S3
5// Modülün VCC'si 3,3 V: sinyaller 3,3 V'u geçmez / module VCC is 3.3 V so signals stay below 3.3 V
6
7enum Kind { SOIL, LIGHT, KNOB };
8struct Channel { const char* name; Kind kind; };
9const Channel CHANNELS[16] = {
10  {"saksi1", SOIL}, {"saksi2", SOIL}, {"saksi3", SOIL}, {"saksi4", SOIL},
11  {"saksi5", SOIL}, {"saksi6", SOIL}, {"saksi7", SOIL}, {"saksi8", SOIL},
12  {"isik1", LIGHT}, {"isik2", LIGHT}, {"isik3", LIGHT}, {"isik4", LIGHT},
13  {"pot1", KNOB}, {"pot2", KNOB}, {"pot3", KNOB}, {"pot4", KNOB},
14};
15
16const int SOIL_DRY_MV = 2500;   // kapasitif sensör havada / capacitive sensor in air
17const int SOIL_WET_MV = 1100;   // kapasitif sensör suda / capacitive sensor in water
18
19void selectChannel(int ch) {
20  for (int bit = 0; bit < 4; bit++) digitalWrite(SELECT_PINS[bit], (ch >> bit) & 1);
21}
22
23int readMilliVolts(int ch) {
24  selectChannel(ch);
25  delayMicroseconds(10);
26  analogReadMilliVolts(PIN_SIG);               // ilk okumayı at / discard first reading
27  long sum = 0;
28  for (int i = 0; i < 8; i++) sum += analogReadMilliVolts(PIN_SIG);   // 8 örnek ortalaması / average of 8
29  return sum / 8;
30}
31
32int toPercent(const Channel& c, int mv) {
33  if (c.kind == SOIL) return constrain(map(mv, SOIL_DRY_MV, SOIL_WET_MV, 0, 100), 0, 100);
34  return constrain(map(mv, 0, 3300, 0, 100), 0, 100);   // LDR ve pot / LDR and pot
35}
36
37void setup() {
38  Serial.begin(115200);
39  for (int i = 0; i < 4; i++) pinMode(SELECT_PINS[i], OUTPUT);
40  analogSetPinAttenuation(PIN_SIG, ADC_11db);  // yaklaşık 0,15-3,1 V; 2,5 V üstü daha az doğrusal / about 0.15-3.1 V, less linear above 2.5 V
41}
42
43void loop() {
44  Serial.print('{');
45  for (int ch = 0; ch < 16; ch++) {
46    int mv = readMilliVolts(ch);
47    Serial.printf("\"%s\":%d%s", CHANNELS[ch].name, toPercent(CHANNELS[ch], mv), ch < 15 ? "," : "");
48  }
49  Serial.println('}');
50  delay(1000);
51}
52

Raspberry Pi Pico and MicroPython

The Pico has only three usable ADC inputs (GP26, GP27, GP28), so a multiplexer is even more useful here. Power the module from the Pico's 3V3 pin; the select pins go to GP2–GP5 and SIG to GP26. In MicroPython, read_u16() returns a value from 0 to 65535; the code turns it into a percentage and prints all 16 values as one list. You can watch the output in Thonny or send the same list to a web page with a Pico W. If you're new to MicroPython, the MicroPython basics article is a good place to start.

MicroPython
1# CD74HC4067 + Raspberry Pi Pico (MicroPython): 16 kanalı yüzde olarak oku
2# CD74HC4067 + Raspberry Pi Pico (MicroPython): read 16 channels as percent
3from machine import Pin, ADC
4import time
5
6select = [Pin(p, Pin.OUT) for p in (2, 3, 4, 5)]   # S0..S3 = GP2..GP5
7sig = ADC(26)                                        # SIG = GP26 (ADC0)
8
9
10def read_channel(ch):
11    for bit, pin in enumerate(select):
12        pin.value((ch >> bit) & 1)                   # kanal bitleri / channel bits
13    time.sleep_us(10)                                # oturma süresi / settling time
14    sig.read_u16()                                   # ilk okumayı at / discard first reading
15    return sig.read_u16()                            # 0-65535
16
17
18while True:
19    values = [read_channel(ch) * 100 // 65535 for ch in range(16)]
20    print(values)
21    time.sleep_ms(200)
22

CD74HC4067 vs 74HC4051

The 74HC4051 is the 8-channel sibling from the same family and uses 3 select pins. Its most important difference is a separate VEE pin that lets it switch negative-voltage signals too: as long as VCC − VEE stays at 10 V or less, it can pass a ±5 V audio signal, for example. The CD74HC4067 has no VEE, so the signal must always stay between 0 and VCC. If you need fewer than 16 channels or want a 16-pin chip that plugs straight into a breadboard, the 74HC4051 is more practical. If you need more channels, use two CD74HC4067s, share the select pins and give the SIG pins two separate analog inputs; that's 32 channels from 6 pins. For measurements where resolution isn't enough and you need 16-bit precision, an external ADC such as the ADS1115 is the better choice.

FeatureCD74HC406774HC4051
Channels16 (C0–C15)8 (Y0–Y7)
Select pins4 (S0–S3)3 (S0–S2, or A, B, C)
Arduino pins needed5 (1 analog + 4 digital)4 (1 analog + 3 digital)
Supply2–6 V2–6 V, VCC − VEE up to 10 V
Negative signalsNo, signal 0–VCCPossible with the VEE pin
Package24 pins, usually on a breakout board16 pins, DIP fits a breadboard
Typical on-resistanceAbout 70 Ω (4.5 V)About 70 Ω (4.5 V)

Common problems and fixes

SymptomLikely causeFix
Every channel reads the same valueSelect pins not connected, or EN is HIGHCheck the S0–S3 wires, tie EN to GND
Values look shifted by one channelReading right after switching channelsAdd a short wait and discard the first reading
Channel numbers are scrambledS0 and S3 swappedS0 must be the lowest bit; fix the wires or the array order in the code
Unused channels show random valuesAn unconnected channel is floatingThat's normal; don't read unused channels or tie them to GND
On the ESP32 readings saturate around 3.1 VADC attenuation setting or 5 V supplyPower the module from 3.3 V, use ADC_11db, treat about 3.1 V as the top
Potentiometers affect each otherHigh source resistance, ADC capacitor doesn't chargeWait longer, add 100 nF between SIG and GND, or use 10 kΩ pots

Project ideas

  • Idea: Add a second CD74HC4067 to the 16-knob MIDI controller and connect 16 more buttons; send the buttons as notes and the potentiometers as CCs.
  • Idea: Measure the moisture of 8 balcony pots with a single ESP32 and show the driest one on an OLED display.
  • Idea: Build a pressure-sensitive dance pad or electronic drum kit with 16 force sensors (FSRs).
  • Idea: Read LDRs at different points in a greenhouse and adjust the shade cloth according to the darkest area.
  • Idea: Monitor the temperature at different points of a battery pack or 3D printer with 16 NTC thermistors.

The CD74HC4067 is an essential helper for multi-channel projects, since a cheap module takes you to 16 analog pins; with the right supply voltage, a short wait and a discarded first reading, it gives stable results. If you want to see the basics of reading a single potentiometer and LDR step by step, you can look at the circuit diagram and code of the "Reading Light Intensity with LDR", "Servo Motor Control with a Potentiometer" and "ESP32 Color Mixer Lamp (3 Pots + RGB LED + OLED)" projects in the BlueGrays app.

Frequently asked questions

What is the CD74HC4067 used for?

The CD74HC4067 is a 16-channel analog multiplexer. Based on the binary number on its four select pins, it connects one of 16 channels to the common SIG pin. That lets you read 16 sensors or potentiometers one after another from a single analog pin.

How many sensors can a CD74HC4067 read?

A single CD74HC4067 reads 16 analog sensors and needs 1 analog and 4 digital pins. If you share the select pins of two modules and give their SIG pins separate analog inputs, you get 32 channels from 6 pins. For more, you can cascade multiplexers.

Does the CD74HC4067 work with an ESP32?

Yes, it works without problems when you power the module from the ESP32's 3.3 V. Connect SIG to an ADC1 pin that still works with Wi-Fi on, such as GPIO 34. If you power the module from 5 V, signals can exceed 3.3 V and damage the ESP32 pin.

Why are my multiplexer readings mixed up?

If you read immediately after changing channels, the sampling capacitor inside the ADC still holds the previous channel's voltage. Waiting a few microseconds and discarding the first reading fixes it. For sensors with high source resistance, a 100 nF capacitor between SIG and GND also helps.

What is the difference between the CD74HC4067 and the 74HC4051?

The CD74HC4067 has 16 channels and uses 4 select pins; the 74HC4051 has 8 channels and uses 3. Thanks to its VEE pin, the 74HC4051 can also pass negative-voltage signals, which the CD74HC4067 can't. Both have an on-resistance of about 70 Ω at a 5 V supply.

Can the CD74HC4067 be used as an output?

Yes, because the switches are bidirectional, a signal on SIG passes to the selected channel and can drive a single LED or input. But only one channel is connected at a time, and the previous output floats when the channel changes. To keep several outputs on at once, use a 74HC595 or PCF8574.

See all projects
Measuring Light Intensity with an LDR
AR-11Beginner

Measuring Light Intensity with an LDR

Want to see how bright your room is as a number? The LDR, a small part that reacts to light, measures the light around it, and the Arduino writes the value to your computer screen every half second.

4.5(86)
154
Reading Light Intensity with the ESP32 LDR Module
ES-11Beginner

Reading Light Intensity with the ESP32 LDR Module

Real-time monitoring of the LDR module's raw ADC value and relative light percentage calculated from dark and light reference values in the Serial Monitor. This percentage is not a lux measurement. Teaches the module’s calibration logic. It is ideal to complete this before Project 10, as it is used to determine the threshold value.

4.6(36)
56
Servo Motor Operation with Potentiometer
AR-36Beginner
Premium

Servo Motor Operation with Potentiometer

As you turn the potentiometer knob, the servo motor's arm turns right along with it: one end of the knob means zero degrees, the other end means half a turn.

4.6(37)
54
ESP32 LED Brightness Control with a Potentiometer (Analog → PWM)
ES-13Intermediate
Premium

ESP32 LED Brightness Control with a Potentiometer (Analog → PWM)

In this project, we control the brightness of an LED analogically using a potentiometer. The ESP32's ADC pin reads the 0-3.3V voltage from the potentiometer, and this value is then converted into a PWM (Pulse Width Modulation) signal and sent to the LED. As a result, as you turn the potentiometer, the LED gradually brightens and dims. With Arduino Core 3.0+, analogWrite() can be used directly; on the ESP32-S2/S3, the ADC resolution is fixed at 12-bit.

4.4(20)
32
ESP32 Color Mixer Light (3 Potentiometers + RGB LED + OLED)
ES-36Advanced
Premium

ESP32 Color Mixer Light (3 Potentiometers + RGB LED + OLED)

A smart color-mixer lamp: turn 3 potentiometers on the ESP32 and mix any color you like! As you turn the red, green and blue potentiometers, the common-cathode RGB LED changes color instantly. The SSD1306 OLED display shows each channel's 0-255 value, fill bars and the HEX web color code (like #FF8040) live.

4.7(6)
10
Led Control with Joystick
AR-59Intermediate
Premium

Led Control with Joystick

Push the little stick on the joystick all the way in any direction and the LED for that direction lights up: there are four different colours for right, left, up and down.

4.8(51)
68
Simple Piano with Buzzer and Button
AR-26Advanced
Premium

Simple Piano with Buzzer and Button

Build your own little piano with eight buttons. Each button is one note, from low to high: do, re, mi, fa, sol, la, ti and high do.

4.9(68)
90