A multiplexer (MUX) logic gate is a combinational digital circuit that routes one of multiple input signals to a single output line based on the binary state of its select pins. In a real circuit or installation, a MUX fundamentally changes your design by drastically reducing microcontroller pin count and wiring harness complexity, allowing a single ADC, GPIO, or communication bus to service dozens of distinct sensors or signals. Think of it like a railroad switch yard: multiple tracks (inputs) converge, and the switch operator (select pins) dictates which single track connects to the main line (output).
Core Truth Tables and IC Specifications
Selecting the right multiplexer depends entirely on whether you are switching discrete digital logic levels, continuous analog voltages, or serial communication buses. Below is a spec-sheet comparison of the most common MUX ICs you will encounter in modern prototyping and production.
| IC Part Number | Architecture | Channels | VCC Range | Prop Delay / Bandwidth | Approx Unit Price (2026) |
|---|---|---|---|---|---|
| SN74HC151 | Digital (Standard) | 8-to-1 | 2V to 6V | ~20ns @ 5V | $0.45 |
| SN74HC157 | Digital (Quad) | Four 2-to-1 | 2V to 6V | ~22ns @ 5V | $0.38 |
| CD4051B | Analog (CMOS) | 8-to-1 | 3V to 20V | ~40MHz Bandwidth | $0.52 |
| TCA9548A | I2C Bus Switch | 8-channel | 1.65V to 5.5V | I2C Speed Dependent | $1.15 |
Reading the Table: The SN74HC151 is your go-to for routing standard 3.3V or 5V digital signals (like reading multiple pushbuttons into one GPIO). The CD4051B uses internal transmission gates, meaning it passes continuous analog voltages without clipping them to logic rails. The TCA9548A is a specialized protocol MUX that isolates I2C buses, complete with internal pull-up resistors and bus capacitance isolation.
Worked Numeric Example: Expanding ESP32 ADC Channels
A common pain point with the ESP32-WROOM-32 is its limited number of usable, low-noise ADC pins. Suppose you need to read 8 separate 10kΩ potentiometers for a MIDI controller build, but you only have one clean ADC pin (e.g., GPIO 34) available. We will use a CD4051B analog MUX to solve this.
The Wiring and Logic
- Inputs (X0-X7): Wiper pins of the 8 potentiometers.
- Output (X): Routed to ESP32 GPIO 34.
- Select Pins (S0, S1, S2): Connected to ESP32 digital outputs (e.g., GPIO 25, 26, 27).
- Enable (E): Tied to GND.
To read the potentiometer on channel X5, we must set the select pins to the binary equivalent of 5, which is 101. Therefore, S2 = HIGH, S1 = LOW, S0 = HIGH.
The Impedance Calculation (Where Designs Fail)
Beginners often wonder if the MUX will distort the analog reading. We must calculate the voltage drop across the MUX's internal On-Resistance ($R_{ON}$). According to the CD4051B datasheet, at $V_{CC} = 5V$, typical $R_{ON}$ is 120Ω.
The ESP32's ADC input impedance is not infinite; during the sample-and-hold phase, it drops to roughly 100kΩ (depending on attenuation settings). This creates a voltage divider:
Result: On a 3.3V scale, your maximum error is roughly 3.9mV. Since the ESP32's 12-bit ADC has a resolution of ~0.8mV per step, this 120Ω resistance introduces less than 5 LSBs of error. It is perfectly acceptable for manual control surfaces, though you would need a low-impedance op-amp buffer for precision thermocouple readings.
Where You Meet MUX Logic Gates In Practice
Beyond basic ADC expansion, multiplexers are foundational to several advanced embedded systems and power electronics topologies.
- I2C Address Collisions: If you are building an environmental monitor with four BME280 sensors, they all share the same hardcoded I2C address (0x76 or 0x77). A TCA9548A I2C MUX allows the microcontroller to route the SDA/SCL lines to only one sensor at a time, bypassing the address conflict entirely.
- LED Matrix Scanning: Driving an 8x8 LED matrix directly requires 64 GPIO pins. By using MUX logic (or shift registers acting as multiplexed sinks/sources), you can drive the matrix using persistence of vision (POV) with just a handful of pins, rapidly switching the active row and column.
- Battery Management Systems (BMS): In 16-cell LiFePO4 BMS architectures, the AFE (Analog Front End) IC uses high-voltage analog multiplexers to sequentially route individual cell voltages to a single internal ADC for Coulomb counting and cell balancing verification.
Common Confusions and Bench Troubleshooting
When a circuit behaves erratically, the root cause is often a fundamental misunderstanding of MUX architecture. Here is what people commonly confuse, and how to fix it.
Digital vs. Analog MUX Architecture
The Mistake: Passing a 1kHz analog audio sine wave through a standard digital MUX like the 74HC151.
The Result: The 74HC151 contains standard CMOS logic gates. It will interpret the sine wave as a digital signal, clipping the peaks and outputting a harsh square wave.
The Fix: Always use an analog MUX (like the CD4051 or 74HC4067) for continuous voltage signals. Analog MUXes use parallel NMOS/PMOS transmission gates that pass voltage bidirectionally without referencing it to a logic threshold.
Multiplexer (MUX) vs. Demultiplexer (DEMUX)
A MUX takes many inputs to one output (data selector). A DEMUX takes one input to many outputs (data distributor). Confusing the two in a schematic will result in a completely non-functional bus. If you need to route a single PWM signal to one of eight different motor drivers, you need a DEMUX (like the 74HC138), not a MUX.
Floating Select Pins and Ghosting
If your MUX output is jumping between channels randomly, check your select pins. Microcontroller GPIOs often default to Hi-Z (high impedance) during boot or reset. If the MUX select pins are not pulled down via 10kΩ resistors, ambient EMI will toggle the select lines, causing the MUX to rapidly cycle through inputs. This 'ghosting' can cause short circuits if multiple high-current outputs are briefly bridged.
Frequently Asked Questions
Can I cascade multiple MUX ICs to get 32 channels?
Yes. You can wire the outputs of four 8-channel MUXes into a fifth 4-channel MUX. However, be aware that each stage adds propagation delay (for digital) or on-resistance (for analog). In analog chains, the cumulative $R_{ON}$ will increase your voltage drop error.
Do I need decoupling capacitors on a MUX IC?
Absolutely. A 100nF ceramic capacitor placed as close to the VCC and GND pins as possible is mandatory. When a MUX switches channels, the internal gate capacitance draws a momentary spike of current. Without local decoupling, this spike will cause a brownout on your microcontroller's 3.3V rail.






