← How-Tos
electronics 8 days ago ◯ 5 min read

Analog Multiplexer ICs for Makers: 74HC4051/4052/4053 Wiring and Expanding ESP32/Arduino ADC Channels

esp32arduino74hc4051analog multiplexeradcsensorselectronicswiring

Every ESP32 project eventually runs into the same wall: you need to read more analog sensors than you have usable ADC pins. The ESP32 has two ADC peripherals, but ADC2 shares internal circuitry with the WiFi radio and becomes unreliable or unavailable the moment WiFi is active โ€” a detail that quietly ruins a lot of "just use more GPIOs" plans. Before reaching for a second microcontroller or an I2C ADC expander chip, it's worth knowing that a two-dollar analog multiplexer IC can turn one good ADC pin into eight or sixteen, with a handful of digital GPIOs doing the channel selection.

How an Analog Multiplexer Differs From a Digital One

A 74HC4051-family chip looks similar to the logic multiplexers makers already use for buttons or shift registers, but it's built differently inside: instead of switching a digital high/low signal, it uses analog CMOS switches that pass through a continuous voltage with minimal distortion, within the chip's supply rails. That's the critical distinction โ€” you can route an analog sensor's actual voltage output through one of these, and the far side still reads the same voltage (minus a small, generally negligible, on-resistance drop), which a digital multiplexer or a plain logic gate cannot do.

The Common Chips

ChipConfigurationSelect Lines NeededNotes 74HC4051Single 8:1 multiplexer3 (A, B, C) + 1 enableSimplest, most common starting point 74HC4052Dual 4:1 multiplexer2 + 1 enableUseful when you need two independent analog channel groups from one chip 74HC4053Triple 2:1 multiplexer3 individual selectsGood for simple A/B signal routing rather than large sensor fan-in CD74HC4067Single 16:1 multiplexer4 + 1 enableDoubles the channel count per chip when you need to scale further

All four run comfortably at 3.3V, matching the ESP32's logic levels directly โ€” no level shifting needed, which is one reason they're a more frictionless choice than reusing a 5V-oriented part from an older Arduino project.

Wiring and Reading Channels

Each sensor's analog output connects to one of the chip's channel pins (Y0 through Y7 on the 4051). The chip's common I/O pin connects to your ESP32 ADC input pin. The select pins (A, B, C) are driven from three ESP32 GPIOs, and their binary combination picks which channel is connected through to the common pin at any instant โ€” set the select lines, wait briefly for the analog switch and any downstream filtering capacitor to settle, then take your ADC reading, then move to the next channel.

  1. Wire all eight sensor outputs to Y0-Y7.
  2. Wire the common output (Z on most datasheets) to a single ESP32 ADC1 pin.
  3. Wire the three select pins to three ESP32 GPIOs, and the enable/inhibit pin either tied active or to a fourth GPIO if you want the ability to disconnect all channels.
  4. In firmware, set the select GPIOs to the binary pattern for the desired channel, insert a short settling delay (a few microseconds is usually enough for low-impedance sensor outputs; add more if your sensors have high output impedance or there's any filtering capacitance on the shared line), then call your ADC read function.
  5. Cycle through all eight channels in sequence, storing each reading before moving to the next.

What You Give Up: Sampling Rate and Crosstalk

Multiplexing is not free. You're now sharing one ADC and one physical trace across multiple sensors, sequentially, which means your effective sampling rate per sensor drops by roughly the channel count (eight sensors through one 4051 each get read about 1/8th as often as a dedicated ADC pin would allow). For slow-changing signals โ€” soil moisture, potentiometer positions, temperature โ€” this is a non-issue. For anything that changes meaningfully within milliseconds, it will alias or blur readings, and a true multi-channel ADC or a per-channel sample-and-hold approach is the better fit.

There is also a small amount of crosstalk and charge injection between channels, especially at higher switching speeds or with long wire runs to each sensor โ€” keep settling delays generous if you see odd correlated noise between channels that shouldn't be related.

Multiplexer vs I2C ADC Expander

An ADS1115-style I2C ADC module is the other common answer to "I need more analog inputs," and it genuinely gives better resolution (16-bit vs the ESP32's noisy 12-bit) and doesn't share a single physical ADC's nonlinearity across channels. But it costs more per channel, uses an I2C bus (fine unless that bus is already busy), and still tops out at 4 channels per chip in the common ADS1115. For simple fan-in of many similar low-speed analog sensors on a tight budget, a 74HC4051-family multiplexer feeding the ESP32's existing ADC1 pin is usually the cheaper and simpler path, and the two approaches combine fine if you need both more channels and better resolution โ€” multiplex into an external precision ADC instead of the ESP32's own.

Safety

Keep every signal routed through the multiplexer within the chip's supply rail voltage โ€” these parts are not protected against overvoltage on their analog channel pins the way some sensor-specific ICs are, and a sensor output that exceeds the supply rail (even briefly, from a wiring fault or a different-voltage sensor module sharing the same multiplexer) can damage the chip or let that overvoltage leak through to your ESP32's ADC pin on an adjacent channel. If you're mixing sensors that run on different supply voltages, power the multiplexer itself from the higher of the two and confirm against the datasheet that the lower-voltage sensor's signal still reads correctly, or add a voltage divider on that channel before it reaches the mux.

A single $0.50-$2 multiplexer chip and three spare GPIOs turn a project that's run out of analog inputs back into one with headroom, and for anything other than fast-changing signals, the sampling rate trade-off is one most maker projects never notice.