A multiplexer (often abbreviated as MUX) is a combinational logic circuit that selects one of several analog or digital input signals and forwards it to a single output line based on the state of its control pins. In a real circuit, a MUX changes your physical wiring constraints by allowing a microcontroller with limited GPIO or ADC pins to interface with dozens of sensors or data lines without needing a larger, more expensive processor. Beginners frequently confuse a multiplexer with a demultiplexer (DEMUX) or a decoder; while a MUX takes many inputs to one output, a DEMUX takes one input to many outputs, and a decoder translates binary inputs into distinct active output lines without necessarily routing a continuous data signal.
The Core Concept and Signal Routing
At its core, a multiplexer acts as an electronically controlled multi-position switch. Think of the rotary dial on a bench multimeter: you physically turn the dial to connect one specific probe tip to the internal measurement circuitry. A MUX does exactly this, but it uses digital logic pins to move the 'dial' in nanoseconds.
The routing is governed by select lines (often labeled S0, S1, S2, etc.). The number of input channels a MUX can handle is dictated by the formula 2^n, where n is the number of select pins. For example, a MUX with 3 select pins can route 2^3 = 8 distinct input channels to a single common output. When you pull S0 HIGH, S1 LOW, and S2 LOW (binary 001), the internal MOSFET switches connect input pin Y1 to the output pin Z, while all other inputs remain electrically disconnected (high impedance).
This architecture is foundational in digital logic and data acquisition. According to Analog Devices' MT-088 Tutorial on Multiplexers, the critical performance metrics for these ICs are transition time (how fast the switch flips), on-resistance (the internal resistance of the closed switch), and charge injection (the tiny voltage spike introduced when the switch toggles).
Worked Numeric Example: Expanding ESP32 ADC Channels
Let’s look at a common bench scenario: you are building a thermal monitoring node using an ESP32 DevKit v1, and you need to read 8 separate NTC thermistors. The ESP32 has 12 usable ADC channels, but ADC2 conflicts with the WiFi radio, leaving you short on pins if you also need digital I/O for a display and relays.
Instead of using 8 dedicated ADC pins, we insert a CD74HC4051 8-channel analog multiplexer between the thermistors and the microcontroller.
- Inputs: 8 thermistors wired to Y0 through Y7.
- Output: Common pin Z wired to ESP32 GPIO 34 (ADC1_CH6).
- Control: Select pins S0, S1, and S2 wired to ESP32 digital GPIOs 25, 26, and 27.
The Math and Timing:
We traded 8 analog pins for 1 analog pin + 3 digital pins, yielding a net savings of 4 microcontroller pins. More importantly, we freed up ADC2 for other tasks. Timing-wise, the ESP32 ADC takes roughly 100µs per sample. Reading all 8 channels sequentially takes 800µs. Adding 5µs of GPIO switching overhead per channel gives us a total loop time of 840µs. This is well under 1 millisecond, meaning we can sample the entire thermal array 1,000 times per second—far faster than the thermal mass of the NTC beads can physically change.
Where You Meet Multiplexers in Practice
You will encounter multiplexing logic across almost every sub-discipline of electronics, from hobbyist breadboards to industrial PLC racks.
- LED Matrices and Charlieplexing: Driving a 16x16 LED matrix directly would require 256 GPIO pins. By using multiplexing (scanning rows and columns sequentially at >60Hz), you can drive the entire grid with just 32 pins, relying on human persistence of vision to perceive a steady image.
- I2C Bus Routing: The I2C protocol is limited by hardcoded device addresses. If you want to connect five BME280 environmental sensors (all hardcoded to address 0x76) to a single I2C bus, you will hit an address collision. An I2C multiplexer like the TCA9548A creates up to 8 isolated downstream I2C buses, allowing identical sensors to coexist.
- Data Acquisition (DAQ) Systems: High-end bench multimeters and oscilloscopes use reed-relay multiplexers to switch high-voltage probes into a single, ultra-high-resolution ADC. These mechanical MUXes offer near-zero on-resistance and zero charge injection compared to solid-state CMOS switches.
- Audio/Video Matrices: Routing multiple HDMI sources to a single display, or multiple line-level audio inputs to a single amplifier channel, relies on high-bandwidth analog multiplexers capable of passing MHz or GHz signals without degrading the waveform.
Decision Tree: Choosing the Right MUX for Your Build
Selecting the wrong multiplexer can result in logic level mismatches, signal attenuation, or bricked microcontrollers. Use this decision matrix to lock in the correct part number for your specific architecture.
| Signal Type | System Voltage | Channel Count | Recommended Part Number | Key Datasheet Spec to Watch |
|---|---|---|---|---|
| Analog (Sensors/Audio) | 5V Logic | 8 Channels | CD74HC4051 | On-Resistance (~80Ω at 5V) |
| Analog (Sensors/Audio) | 3.3V Logic | 16 Channels | CD74HC4067 | On-Resistance increases to ~120Ω at 3.3V |
| Digital (I2C Routing) | 3.3V or 5V | 8 Buses | TCA9548A | Passes I2C clock/data; check pull-up resistor limits |
| High-Speed Digital (SPI/USB) | 3.3V Logic | 4 Channels | SN74CB3T3257 | Bandwidth (>400MHz) and low capacitance (~5pF) |
Debugging and Common Pitfalls
Why are my analog readings drifting or fluctuating when switching MUX channels?
This is caused by charge injection and parasitic capacitance. When the internal MOSFET switch toggles, it dumps a tiny amount of charge into the output line. Furthermore, the ADC sample-and-hold capacitor needs time to charge through the MUX's internal resistance.
The Fix: Add a 100nF ceramic capacitor from the MUX output pin (Z) to ground to act as a charge reservoir. In your firmware, add a 1ms to 5ms delay() immediately after writing the new select pin states and before calling analogRead(). This gives the signal time to settle.
Can I use a 5V 74HC4051 with a 3.3V ESP32?
Technically yes, but it requires careful power routing. If you power the 74HC4051 VCC pin with 5V, the 3.3V logic from the ESP32 GPIOs might not reliably cross the MUX's V_IH (Logic HIGH threshold), which is typically 3.15V on a 5V supply. Worse, if your analog input signals are 5V, the MUX will pass 5V directly into the ESP32's 3.3V-tolerant ADC pin, potentially destroying the silicon.
The Fix: Power the 74HC4051 VCC at 3.3V. According to the Texas Instruments SN74HC4051 Datasheet, the IC operates perfectly fine down to 2V. This ensures the 3.3V GPIO select pins trigger reliably, and the analog signals passed to the ESP32 never exceed 3.3V.
What is 'On-Resistance' and why does it ruin my voltage divider circuits?
The internal switch of a MUX is not a perfect short circuit; it has an internal resistance (R_ON), typically 80Ω to 120Ω depending on the supply voltage. If you are reading a high-impedance source (like a 1MΩ voltage divider for battery monitoring), that 120Ω creates a secondary voltage divider with the ADC's internal sampling impedance, causing massive reading errors.
The Fix: Keep your source impedance below 10kΩ. If you must measure high-impedance circuits, buffer the MUX output with a rail-to-rail unity-gain op-amp (like the MCP6001) before feeding it to the microcontroller's ADC.






