A multiplexer (often shortened to MUX) is an electronic switch that selects one of several input signals and forwards the selected input to a single output line based on digital control pins. If you are building an ESP32 or Arduino project and run out of GPIO pins or analog-to-digital converter (ADC) channels, a MUX is the component that changes your circuit by letting you read 8 or 16 sensors through a single microcontroller pin, trading parallel wiring for sequential digital addressing.

The Core Multiplexer Definition and How It Works

To understand the component at a bench level, think of a railway junction where a switch operator dictates which of several incoming tracks connects to the single main line. In a MUX, your input pins are the incoming tracks, the output pin is the main line, and the digital "select" pins act as the operator. By applying a specific binary combination to the select pins, you physically connect one input channel to the output.

Pin Savings Math: A standard 8-channel MUX requires 3 select pins (23 = 8) to route 8 inputs to 1 output. Reading 8 sensors directly requires 8 microcontroller pins; using a MUX requires 4 pins (3 select + 1 data), saving 4 pins. A 16-channel MUX (like the 74HC4067) uses 4 select pins to read 16 inputs, saving 11 pins.

What people commonly confuse a multiplexer with is a demultiplexer (DEMUX), which does the exact opposite: it takes a single input signal and routes it to one of many output lines based on select pins. Makers also frequently confuse MUXes with shift registers (like the 74HC595). While both save microcontroller pins, a shift register stores and shifts digital bits sequentially over time, whereas a multiplexer physically routes real-time analog or digital signals in parallel-to-serial fashion without storing state.

According to foundational digital logic principles outlined by All About Circuits, multiplexers are essentially data selectors. They do not process or alter the signal; they merely provide a low-resistance physical path from the chosen input to the output.

Worked Numeric Example: Reading 8 Analog Sensors with a CD4051B

Let’s look at a real-world scenario. You are building an ambient light tracker using an Arduino Nano and eight Light Dependent Resistors (LDRs). The Nano only has 8 analog pins (A0-A7), and you need A4/A5 for I2C, leaving you short on channels. You decide to use a Texas Instruments CD4051B 8-channel analog multiplexer, which costs roughly $0.50 in single quantities.

Wiring and Pin Mapping

The CD4051B has 8 input channels (X0 through X7), one common output (X), and three binary select pins (A, B, and C). You wire the output (X) to Arduino pin A0. The select pins A, B, and C go to digital pins D2, D3, and D4.

Channel to ReadBinary (C-B-A)Pin C (D4)Pin B (D3)Pin A (D2)
X0000LOWLOWLOW
X1001LOWLOWHIGH
X2010LOWHIGHLOW
X3011LOWHIGHHIGH
X4100HIGHLOWLOW
X5101HIGHLOWHIGH
X6110HIGHHIGHLOW
X7111HIGHHIGHHIGH

The Numeric Calculation and Edge Cases

Suppose you want to read the LDR on channel X5. You set C=HIGH, B=LOW, A=HIGH (binary 101). The internal CMOS switch closes, connecting X5 to X. The LDR and a 10kΩ pulldown resistor form a voltage divider. If the LDR's resistance drops to 10kΩ under bright light, the voltage at X5 is exactly 2.5V (half of the 5V VCC).

Bench Warning: On-Resistance ($R_{ON}$)
The CD4051B is not a perfect wire; it has an internal on-resistance ($R_{ON}$) of typically 120Ω at 5V. When the 2.5V signal passes through the MUX to the Arduino's A0 pin, that 120Ω forms a secondary voltage divider with the Arduino's ADC input impedance (roughly 100MΩ). The voltage drop is negligible here ($120 / 100,000,120 \approx 0.0001\%$). However, if you are feeding a high-impedance source (like a 1MΩ piezo sensor) through a MUX into a 16-bit ADC, that 120Ω will introduce measurable non-linearity and settling time delays. Always buffer high-impedance signals with an op-amp before the MUX.

Where You Meet This in Practice

Beyond basic analog sensor reading, multiplexers solve several specific hardware bottlenecks in embedded systems and audio electronics.

  • I2C Address Collisions: The BME280 environmental sensor has a hardcoded I2C address (0x76 or 0x77). If you need to log data from four different microclimates, you cannot wire four BME280s to the same I2C bus. An I2C multiplexer like the NXP TCA9548A acts as a digital traffic cop, creating up to 8 virtual I2C buses. You send a command to the TCA9548A to open "channel 2," talk to the sensor, then close it and open "channel 3."
  • Audio Signal Routing: In guitar pedalboards or DIY synthesizers, analog MUXes (like the 4051 or 4052) are used to switch audio paths without the "popping" sound associated with mechanical switches, provided the select pins are triggered at zero-crossing points.
  • Capacitive Touch Matrices: Reading a 16-pad capacitive touch interface requires 16 dedicated touch pins on a high-end microcontroller. Using a 16-channel MUX allows a cheap 20-pin ESP8266 to scan all 16 pads sequentially using a single touch-sense pin.

Comparison: Multiplexer vs. Demultiplexer vs. Shift Register

Choosing the right pin-saving IC depends entirely on signal direction and type. Here is how the three most common components compare on the workbench.

FeatureMultiplexer (MUX)Demultiplexer (DEMUX)Shift Register (e.g., 74HC595)
Signal DirectionMany Inputs → 1 Output1 Input → Many OutputsSerial In → Parallel Out (or vice versa)
Signal TypeAnalog or DigitalAnalog or DigitalDigital Only
Primary Use CaseReading multiple sensors via 1 ADC/GPIORouting 1 audio source to multiple ampsDriving multiple LEDs or relays
Common IC PartCD4051B, 74HC4051, TCA9548A74HC138, CD4051B (used in reverse)74HC595, CD4021
Real-time Routing?Yes, continuous physical connectionYes, continuous physical connectionNo, data is clocked and latched

Frequently Asked Questions

What is the standard multiplexer definition in digital logic?

In strict digital logic theory, a multiplexer is defined as a combinational logic circuit that selects one of $2^n$ digital input lines and routes it to a single output line, governed by $n$ select lines. While the textbook definition focuses purely on 1s and 0s, the physical silicon implementation (CMOS transmission gates) allows the exact same logic to route continuous analog voltages, which is why makers use digital MUX ICs for analog audio and sensor signals.

How does an I2C multiplexer solve sensor address conflicts?

An I2C multiplexer like the TCA9548A sits on the main I2C bus as a standard slave device. When you want to talk to a sensor on a sub-bus, the microcontroller sends an I2C command to the MUX to close the internal FET switches for that specific channel. This physically isolates the other channels, meaning identical sensors on different channels don't "see" each other or cause bus collisions. It changes a real circuit installation by allowing unlimited identical sensors on a single pair of SDA/SCL wires, limited only by the MUX channel count and bus capacitance.

What is the difference between a multiplexer and a demultiplexer?

The difference is strictly directional. A multiplexer (MUX) is a data selector: it takes many inputs and funnels them down to one output (many-to-one). A demultiplexer (DEMUX) is a data distributor: it takes one input and fans it out to one of many outputs (one-to-many). Interestingly, many analog CMOS ICs, like the CD4051, are bilateral. Because the internal switches are just MOSFETs, current can flow in either direction, meaning you can wire a CD4051 "backwards" to use it as a demultiplexer.

Does an analog multiplexer introduce voltage drop or signal delay?

Yes, both. As noted in the CD4051B example, the internal switches have an on-resistance ($R_{ON}$) typically between 60Ω and 120Ω. If your load draws significant current, this resistance will cause a measurable voltage drop (Ohm's Law: $V = I \times R_{ON}$). Furthermore, the internal MOSFETs introduce a small parasitic capacitance (usually around 5pF to 10pF per channel). When switching between channels, the microcontroller's ADC requires a few microseconds to charge its internal sample-and-hold capacitor through this $R_{ON}$ and parasitic capacitance. If you read the ADC immediately after toggling the MUX select pins, you will read the ghost voltage of the previous channel. Always add a 10µs to 50µs delay in your code after switching MUX channels before calling analogRead().