A multiplexer (often shortened to 'mux') is an electronic switch that routes one of several input signals to a single output line based on the binary state of its select pins. In a real circuit or installation, a multiplexer changes a microcontroller's physical pin limitation into a logical routing problem, allowing you to read dozens of sensors or route multiple data buses using only a handful of GPIO pins. Think of it like a multi-position rotary switch on a vintage stereo receiver, where you physically turn a dial to route the CD player, turntable, or tape deck into the single amplifier input; in a mux, binary voltage levels on the select pins turn that dial electronically at microsecond speeds.
The Core Concept and What It Changes in a Circuit
At the silicon level, a multiplexer is built from an array of logic gates (for digital signals) or transmission gates (for analog signals). When you apply a binary address to the select pins, the internal gates close the path between the chosen input and the common output, while keeping all other paths high-impedance (disconnected).
What people commonly confuse a multiplexer with is a demultiplexer (which takes one input and routes it to one of many outputs), a decoder (which converts binary to a single active line, like a 74HC138), or an I2C GPIO expander (which adds actual independent pins rather than just routing existing ones). A mux does not create new pins; it time-shares a single pin across multiple sources.
Where You Meet Multiplexers in Practice
You will encounter multiplexers on the bench in three primary scenarios:
- Analog Sensor Arrays: Reading multiple thermistors, potentiometers, or LDRs when your microcontroller runs out of ADC pins.
- I2C Bus Expansion: Using an I2C mux like the TCA9548A to route multiple identical OLED displays or sensors that share the same hardcoded I2C address (e.g., four BME280 sensors all stuck at 0x76).
- Digital Logic and Clock Routing: Selecting between different clock sources or routing digital signals in FPGA development boards and vintage computer restorations.
Worked Numeric Example: Expanding ESP32 ADC Channels
Let's say you are building a multi-zone 3D printer enclosure heater and need to read 24 NTC thermistors. The ESP32 DevKit v1 has 15 usable ADC pins, which is not enough, and upgrading to a larger microcontroller adds cost and PCB complexity.
Instead, we use three CD4051B 8-channel analog multiplexers. Each CD4051B requires 3 select pins (S0, S1, S2) and 1 common I/O pin. If we wire the 3 select pins in parallel across all three muxes, we use exactly 3 ESP32 GPIOs to control the addressing for all 24 channels. We then use 3 separate ESP32 ADC pins for the common I/O of each mux.
Real-World Scenario Walkthrough: The 74HC4052 Sensor Array
Theory is clean; the breadboard is not. Here is a real-world scenario demonstrating how a multiplexer behaves when parasitic elements get involved.
- Setup: Wiring a 74HC4052 (dual 4-channel analog mux) to read 8 slide potentiometers on an Arduino Nano. VCC is tied to 5V, VEE and INH (Inhibit) are tied to GND. Select pins A and B are on D2 and D3. The two common pins are wired to A0 and A1.
- Numbers: The 74HC4052 has an on-resistance ($R_{ON}$) of about 120 ohms at 5V. The Arduino Nano's 10-bit ADC expects a source impedance of < 10k ohms to properly charge its internal 14pF sample-and-hold capacitor within the ADC clock cycles.
- Outcome: Faders 1-4 on A0 read perfectly smooth values from 0 to 1023. Faders 5-8 on A1 read erratic values, violently jumping from 0 to 1023 and settling around 400 regardless of the physical slider position.
- What Went Wrong: The issue was twofold. First, I left the unused inputs on the second half of the chip floating. In CMOS logic, floating inputs cause the internal transistors to oscillate, injecting massive substrate noise into the analog routing path. Second, the breadboard contact resistance combined with long, unshielded jumper wires introduced capacitive coupling from the digital select lines into the high-impedance analog traces. Tying all unused input pins directly to GND and adding a 100nF decoupling capacitor directly across the VCC and GND pins on the chip stabilized the readings immediately.
Multiplexer vs. Demultiplexer vs. Decoder vs. Expander
It is easy to grab the wrong chip from the parts bin. Here is how these four common routing and expansion ICs differ in function and application.
| Component Type | Signal Flow | Primary Use Case | Common Part Number |
|---|---|---|---|
| Multiplexer (Mux) | Many Inputs → 1 Output | Reading multiple sensors on one ADC pin | CD4051B, 74HC151 |
| Demultiplexer (Demux) | 1 Input → Many Outputs | Routing a single audio source to different zones | 74HC138 (often used as demux), CD4051B (bidirectional) |
| Decoder | Binary Address → 1-of-N Active Line | Driving 7-segment displays or enabling chip-select lines | 74HC138, CD4511 |
| I2C/GPIO Expander | Serial Bus ↔ Multiple Independent I/O | Adding actual new pins to a microcontroller via I2C/SPI | MCP23017, TCA9548A (I2C Mux) |
Bench Mistakes and Troubleshooting FAQ
Q: Why is my analog multiplexer outputting a voltage that is 0.5V lower than the actual sensor voltage?
A: You are experiencing voltage drop across the mux's internal on-resistance ($R_{ON}$). If your load draws current, $V = I \times R_{ON}$ will subtract from your signal. For high-impedance ADC inputs (which draw almost zero current), this drop is negligible. But if you are driving an LED or a low-impedance load through a CD4051B, the voltage will sag. Buffer the mux output with an op-amp configured as a voltage follower if you need to drive a load.
Q: Can I pass negative audio signals through a 74HC4051?
A: No. The 'HC' (High-speed CMOS) series cannot handle voltages below GND on its input pins; doing so will forward-bias the internal ESD protection diodes and potentially destroy the chip or cause severe signal clipping. If you need to route bipolar (negative) analog signals, you must use the unbuffered '4000' series CMOS (like the CD4051B) and tie the VEE pin to a negative voltage rail (e.g., -5V), while keeping VCC at +5V and VDD (logic control) at +5V.
Q: My digital mux output is flickering randomly when I switch channels. What gives?
A: You likely have floating select pins. CMOS inputs have incredibly high impedance and will act as antennas, picking up stray electromagnetic interference from your bench or nearby digital clocks. Always tie your select pins to defined logic levels, and if you are driving them from a microcontroller, ensure your code sets the pins as OUTPUT and doesn't accidentally leave them in a high-impedance INPUT state during boot.
For deeper reading on digital logic routing and transmission gate architectures, the All About Circuits digital textbook chapter on multiplexers provides excellent schematic breakdowns of the internal gate structures. Understanding the silicon underneath the plastic package is what separates a parts-swapper from a true circuit designer.






