74HC4051 8-channel multiplexer

Eight analog switches with one common pin, in a 16-pin DIP: three address lines pick which channel reaches Z.

Aliases: 74HC4051, CD74HC4051, CD4051, 8-channel analog mux. One analog pin reads eight knobs or sensors, or one pin drives eight outputs in turn, because each switch passes current in either direction. It is the smaller cousin of the CD74HC4067.

Pins

Pin What it does
Y0 to Y7 The eight channels.
Z The common pin, to an analog input (or a PWM output).
S0, S1, S2 The channel address, S0 the least significant bit.
E Enable, active low. High opens every switch. Tie it to GND if unused.
VEE The negative analog supply. On an Arduino, tie it to GND.
VCC, GND Supply, 2 to 6 V.

Reading eight knobs on an Arduino

const int S0 = 2, S1 = 3, S2 = 4;

int readChannel(int ch) {
  digitalWrite(S0, ch & 1);
  digitalWrite(S1, (ch >> 1) & 1);
  digitalWrite(S2, (ch >> 2) & 1);
  return analogRead(A0);   // Z is on A0
}

What the model gets right

From the Nexperia 74HC4051 and TI CD74HC4051 datasheets: E low joins the addressed channel to Z through the switch's on-resistance, both ways round, and leaves the others open; E high opens them all. The on-resistance is about 70 ohm at 4.5 V and more at lower supplies, so a load on Z divides against it. The address and enable are CMOS inputs read against half the supply; an address that is not a clean level opens every switch.

What it does not model

The switching time, break-before-make, charge injection, leakage, the on-resistance's change with the signal voltage, and signals below ground: VEE is not read, as if it were tied to GND.

Common mistakes

Leaving E or VEE unconnected. Reading Z straight after changing the address with a large source resistance: give the input a moment to settle.