A mux (multiplexer) is an electronic switch that selects one of several input signals and forwards it to a single output line based on digital control pins. In a real circuit or installation, a mux drastically reduces the number of microcontroller GPIO pins or ADC channels required to monitor multiple sensors or control multiple loads, effectively turning a pin-starved microcontroller into a multi-channel data acquisition system.

A single 16-channel analog mux like the 74HC4067 allows you to read 16 separate analog sensors using just 5 microcontroller pins (4 digital select pins + 1 analog read pin).

The Core Concept: How a Multiplexer Routes Signals

Think of a multiplexer like the multi-position rotary switch on a bench multimeter. You have multiple jacks (inputs) for measuring voltage, current, or resistance, but only one internal measurement circuit (the output). The rotary dial (the select pins) physically connects the chosen jack to the internal circuitry while disconnecting the rest.

In silicon, this rotary switch is replaced by MOSFET transmission gates. You control which gate opens using binary addressing on the select pins (usually labeled S0, S1, S2, etc.). For an 8-channel mux, you have three select pins (S0, S1, S2). If you set S0=HIGH, S1=LOW, and S2=LOW (binary 001, or decimal 1), the internal switch connects input pin 1 to the common output pin.

Bench Tip: Always tie unused select pins to a defined logic level (GND or VCC). Leaving select pins floating on a breadboard will cause the internal MOSFETs to rapidly toggle due to ambient EMI, resulting in ghost readings on your ADC.

Where You Meet This in Practice

You will reach for a mux in DIY electronics and prototyping whenever you run out of pins but need to expand your I/O without adding a secondary microcontroller. Common jobsite and workbench applications include:

  • Analog Sensor Arrays: Reading 16 soil moisture sensors, potentiometers, or thermistors on an ESP32 or Arduino Uno when you exhaust the built-in ADC channels.
  • Digital Signal Routing: Multiplexing multiple UART lines or I2C buses into a single serial port on a Raspberry Pi Pico.
  • Audio/Video Switching: Routing multiple line-level audio signals into a single amplifier input in DIY synthesizer builds, or switching between composite video sources.
  • Capacitance Touch Matrices: Scanning large grids of capacitive touch pads by rapidly switching the sense lines into a single capacitance-to-digital converter.

Worked Numeric Example: Sizing and Timing a 16-Channel Mux

Let us look at the Texas Instruments CD74HC4067, a standard 16-channel analog multiplexer that costs roughly $0.80 to $1.20 in single quantities. Because it routes analog voltages, the internal MOSFETs are not perfect conductors; they introduce an on-resistance ($R_{ON}$).

According to the datasheet, at a 5V supply, the typical $R_{ON}$ is 70Ω. Let us calculate the impact of this resistance when reading a standard 10kΩ NTC thermistor configured as a voltage divider.

  1. Baseline Circuit: 10kΩ thermistor to GND, 10kΩ pull-up to 5V. Nominal mid-scale resistance is 10,000Ω.
  2. With Mux: The 70Ω $R_{ON}$ adds in series with the thermistor. Total resistance becomes 10,070Ω.
  3. Error Calculation: 70Ω / 10,000Ω = 0.007, or a 0.7% resistance error.
  4. ADC Impact: On a 10-bit ADC (1024 steps), a 0.7% error shifts your reading by roughly 7 steps.

Outcome: For a basic temperature monitor, a 7-step shift is negligible. However, if you are measuring a 100Ω precision RTD sensor, that same 70Ω $R_{ON}$ introduces a massive 70% error. In precision low-resistance scenarios, you must either calibrate out the $R_{ON}$ in software or use a dedicated instrumentation amplifier before the mux.

Timing is also a factor. The CD74HC4067 has a typical propagation delay of 20ns and a break-before-make time of 10ns. When scanning 16 channels in a loop, you must insert a minimum 50µs software delay after toggling the select pins to allow the internal capacitance to settle and the ADC sample-and-hold circuit to acquire a stable voltage.

Real-World Scenario Walkthrough: The CD4051 Analog Sensor Fail

Theory is clean; the workbench is not. Here is a classic failure mode when mixing analog muxes with higher-voltage field sensors.

The Setup

A DIY automated greenhouse used a CD4051B (an 8-channel analog mux, ~$0.50) to read eight resistive soil moisture sensors. The Arduino Uno was powered by a 5V USB buck converter, while the soil sensors were excited by a separate 12V solar battery bus to prevent electrolysis in the soil. The sensor outputs were wired directly to the CD4051 input pins.

The Numbers

  • CD4051B VDD (Logic High) = 5V
  • CD4051B VSS / VEE (Logic Low / Analog Low) = 0V
  • Sensor Output Voltage Range = 0V to 10V (depending on soil moisture)

The Outcome

Upon powering the system, the Arduino serial monitor spit out erratic, maxed-out 1023 ADC values. Within three minutes, the CD4051B IC was hot to the touch, and the Arduino began randomly resetting.

What Went Wrong

The CD4051B is an analog mux, meaning it passes continuous voltage levels, but its input pins are protected by internal ESD clamping diodes tied to VDD and VSS. These diodes prevent the input voltage from exceeding VDD by more than a standard diode drop (~0.5V).

Critical Safety & Design Rule: Never feed an analog mux an input voltage higher than its VDD + 0.5V. Doing so forward-biases the internal protection diodes, injecting current directly into your logic power rail.

When the dry soil sensor output hit 10V, it exceeded the 5.5V clamp limit. The excess 4.5V pushed current through the diode into the 5V rail. Because the cheap USB buck converter could not sink current, the 5V rail spiked to 7V+, causing the Arduino to brownout and reset, while the CD4051B dissipated the excess energy as heat, eventually degrading the silicon.

The Fix: We added a simple voltage divider (a 10kΩ series resistor and an 8.2kΩ pull-down resistor) on each of the eight sensor lines. This scaled the 0-10V sensor output down to a safe 0-4.5V range before it reached the mux pins. The system has run flawlessly for over two years since.

What People Commonly Confuse a Mux With

When ordering parts or designing schematics, it is easy to grab the wrong IC if you conflate these components:

Component Function Can it pass Analog Voltages? Best Use Case
Multiplexer (Mux) Many inputs to 1 output Yes (if analog mux like CD4051) Reading multiple sensors with one ADC pin
Demultiplexer (Demux) 1 input to many outputs Usually No (digital logic only) Routing a single data stream to multiple destinations
Shift Register (e.g., 74HC595) Serial-in, Parallel-out No (digital HIGH/LOW only) Expanding digital outputs for LEDs or relays
I2C GPIO Expander (e.g., PCF8574) I2C bus to parallel digital I/O No (digital HIGH/LOW only) Adding digital buttons/switches without using many pins

If you try to use a digital shift register to read the varying voltage of a potentiometer, you will fail; shift registers only recognize discrete logic thresholds (e.g., anything above 2.5V is a '1', below is a '0'). You must use an analog multiplexer for continuous voltage routing.

Frequently Asked Questions

Can I use a digital mux (like the 74HC151) for analog signals?

No. Digital multiplexers are built with standard logic gates (AND/OR/NOT) designed to output clean digital rails (0V or VCC). They will clip, distort, or completely block continuous analog waveforms. Always choose a CMOS transmission-gate mux (like the 4000-series CD4051/CD4067 or the 74HC4051/74HC4067) for analog signals.

Do I need pull-down resistors on the unconnected input pins of a mux?

Yes. If an input pin on an analog mux is left floating, it acts as an antenna, picking up ambient RF and mains hum. This noise can couple through the internal parasitic capacitance into the active channel, introducing jitter into your ADC readings. Tie unused analog inputs to GND via a 10kΩ resistor.

How do I handle the 'break-before-make' glitch when switching channels?

When the mux switches from Channel A to Channel B, it briefly disconnects A before connecting B to prevent the two inputs from shorting together. This creates a momentary open circuit, which can cause a voltage spike or glitch on the output line. If you are driving a sensitive analog load, place a small capacitor (e.g., 10nF to 100nF) on the common output pin to GND to smooth out the transition glitch, but be aware this will increase your RC settling time.