Part

74HC4051 analog multiplexer

Eight channels to one pin through analog switches: three address lines pick which one.

See every part
  • 16 pins
  • 1 setting
  • In 1 project
Drawn live by the editor's own code, at the size you see it.
74HC4051 analog multiplexer as drawn in the Mokxi simulator
At a glance

The 74HC4051 analog multiplexer in brief

What it is, and every setting the properties panel gives it.

The 74HC4051 is an 8 channel analog multiplexer, eight analog switches with one common pin in a 16 pin DIP: three address lines pick which channel reaches Z. The pins are Y0 to Y7, the eight channels, Z, the common pin, S0, S1 and S2, the channel address with S0 the least significant bit, E, enable, active low, which opens every switch when high, VEE, the negative analog supply, tied to GND on an Arduino, and VCC and GND, 2 to 6 V. Each switch passes current in either direction, so one analog pin reads eight sensors, or one pin drives eight outputs in turn. The model property picks the 74HC4051 or the CD4051B, which runs from 3 V to 18 V with a much higher on-resistance: 470 ohms against 70.

Family
Logic
Pins
16
model
74HC4051 (or CD4051B)
Pins

16 pins

Named as the editor names them, so a wire lands where you expect it.

Pin
What it does
Y4
Y6
Z
The common pin, to an analog input (or a PWM output).
Y7
Y5
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.
GND
Ground.
S2
The channel address, S0 the least significant bit.
S1
The channel address, S0 the least significant bit.
S0
The channel address, S0 the least significant bit.
Y3
Y0
Y1
Y2
VCC
Supply, 2 to 6 V.
How to use it

How to read eight knobs on one analog pin with a 74HC4051

Z, the common pin, goes to A0. The three address pins S0, S1 and S2 go to Uno pins 2, 3 and 4. E, enable, VEE and GND all go to ground: E low turns the switches on, and VEE is tied to GND on an Arduino. VCC is on 5 V. The three knobs’ wipers go to Y0, Y1 and Y2.

The sketch writes the channel number onto the three address pins, bit 0 to S0, waits 50 microseconds for the switch to settle and reads A0. It reads channels 0, 1 and 2 and prints them every 300 ms. The same pins would read eight channels. The 74HC4051 is the smaller cousin of the CD74HC4067, which has sixteen.

Part pin
Board pin
Z
A0
S0, S1, S2
Pins 2, 3, 4
Y0, Y1, Y2
The three knobs’ wipers
E, VEE, GND
Ground
VCC
5 V
Mux eightlive0.000 s 0.00x
Click to open it in the editor
This is the simulator itself, running here. Click anything to open it in the editor.
Pick a channel, then read
const uint8_t ADDRESS[3] = {2, 3, 4};   // S0, S1, S2

int readChannel(uint8_t channel) {
  for (uint8_t bit = 0; bit < 3; bit++) {
    digitalWrite(ADDRESS[bit], (channel >> bit) & 1 ? HIGH : LOW);
  }
  delayMicroseconds(50);                 // let the switch settle
  return analogRead(A0);                 // Z is on A0
}

void setup() {
  Serial.begin(9600);
  for (uint8_t bit = 0; bit < 3; bit++) pinMode(ADDRESS[bit], OUTPUT);
}

void loop() {
  for (uint8_t ch = 0; ch < 3; ch++) {
    Serial.print("Y");
    Serial.print(ch);
    Serial.print(" ");
    Serial.print(readChannel(ch));
    Serial.print(ch < 2 ? "  " : "\n");
  }
  delay(300);
}
Common errors

Common 74HC4051 analog multiplexer errors and fixes

What goes wrong
The fix
Every channel reads nothing.
E is active low. High opens every switch, so tie it to GND if unused.
The channels read each other.
Wait a few tens of microseconds after changing the address before analogRead(), as the sketch does.
The analog values are clipped.
VEE is the negative analog supply. On an Arduino tie it to GND, and keep signals between GND and VCC.
Questions

Questions and answers

How many analog pins does a 74HC4051 save?

It reads eight sensors on one analog pin and three digital pins.

What is the difference between the 74HC4051 and the CD4051B?

Same pins. The CD4051B runs 3 V to 18 V and has a much higher on-resistance: 470 ohms typical at 5 V against 70 ohms.

Can the 74HC4051 output as well as input?

Yes. Each switch passes current in either direction, so one pin can drive eight outputs in turn.

How it is modeled

What is true about the 74HC4051 analog multiplexer, here

In its help article’s own words: what the simulation gets right, and where it stops.

Modeled

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.

Not modeled

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.

From 74HC4051 8-channel multiplexer, in full.

Projects

See the 74HC4051 analog multiplexer in a project

One built-in project uses it. It opens in the editor, already wired.

Boards

The boards it is shown on

This board has a built-in project with the 74HC4051 analog multiplexer in it.

Wire up the 74HC4051 analog multiplexer

Open the editor and push it into the breadboard. It is free, and it runs on your own machine.