The Arduino Uno has just 6 analog input pins (A0–A5). For many sensor-heavy projects — reading 8 potentiometers, monitoring 16 temperature sensors, or scanning a capacitive touch array — those 6 pins disappear fast. The solution is an analog multiplexer, and the CD4051 is one of the simplest and most widely available options. With only 3 control pins from your Arduino, the CD4051 gives you 8 analog channels that funnel into a single Arduino analog input. Chain two together and you have 16 channels — still using just one ADC pin.
This guide explains how the CD4051 works, how to wire it to an Arduino, how to write the selection code, and how to scale up for larger projects. It also covers the important gotchas — switching speed, input voltage limits, and signal leakage — that you need to know for reliable operation.
What Is the CD4051 Multiplexer?
The CD4051 is an 8-channel analog multiplexer/demultiplexer from the CMOS 4000 series logic family. It contains eight independent bilateral analog switches — each switch can pass an analog signal in either direction (input to output, or output to input). Three binary select pins (A, B, C) and an active-LOW inhibit pin choose which of the eight channels (Y0–Y7) is connected to the common pin (Z).
Unlike digital multiplexers that only handle logic HIGH/LOW, the CD4051 passes genuine analog voltages. Connected to an Arduino’s ADC, it lets you read analog voltage from any of 8 sensors using a single analogRead() call. Key specifications:
- Supply voltage (VDD–VSS): 3V to 15V
- Analog signal range: between VSS and VDD
- On-resistance: ~125Ω at 5V supply (contributes a small error in readings)
- Switching time: ~15 ns (extremely fast)
- Leakage current: ~1 nA (negligible for most sensors)
- Package: DIP-16 (breadboard friendly)
The CD4051 is not a perfect conductor — the ~125Ω on-resistance creates a small voltage divider error with high-impedance sources. For most sensors (potentiometers, thermistors, photoresistors), this error is negligible. For very high-impedance sources like microphones or pH electrodes, add a buffer amplifier (op-amp voltage follower) between the sensor and the CD4051 input.
CD4051 Pinout and Pin Functions
The CD4051 comes in a 16-pin DIP package. Here is a complete pin reference:
| Pin | Name | Function |
|---|---|---|
| 1 | Y4 | Channel 4 I/O |
| 2 | Y6 | Channel 6 I/O |
| 3 | Y2 | Channel 2 I/O |
| 4 | Y7 | Channel 7 I/O |
| 5 | Y5 | Channel 5 I/O |
| 6 | Y3 | Channel 3 I/O |
| 7 | Y1 | Channel 1 I/O |
| 8 | Y0 | Channel 0 I/O |
| 9 | Z | Common I/O → connects to Arduino analog pin |
| 10 | E (INH) | Inhibit (active HIGH disables all channels) |
| 11 | VEE (VSS) | Negative supply (GND for unipolar operation) |
| 12 | GND | Digital ground |
| 13 | A | Select bit 0 (LSB) |
| 14 | B | Select bit 1 |
| 15 | C | Select bit 2 (MSB) |
| 16 | VDD | Positive supply (5V) |
The channel selection truth table (C, B, A → channel selected): 000→Y0, 001→Y1, 010→Y2, 011→Y3, 100→Y4, 101→Y5, 110→Y6, 111→Y7. This binary address directly maps to the channel number.
Wiring the CD4051 to Arduino
Here is the wiring for a standard 5V Arduino setup reading 8 analog sensors through one CD4051:
| CD4051 Pin | Connect To | Notes |
|---|---|---|
| VDD (16) | 5V | Power supply |
| GND (12) | GND | Digital ground |
| VEE (11) | GND | Tie to GND for unipolar (0–5V) signals |
| INH/E (10) | GND | Tie LOW to keep channels active |
| Z (9) | Arduino A0 | Common analog output → ADC input |
| A (13) | Arduino D2 | Select bit 0 |
| B (14) | Arduino D3 | Select bit 1 |
| C (15) | Arduino D4 | Select bit 2 |
| Y0–Y7 | Sensor outputs | Connect sensor signal (0–5V) to each channel |
Add a 100nF decoupling capacitor between VDD (pin 16) and GND (pin 12). For each analog sensor, connect its output voltage directly to the corresponding Y pin of the CD4051. Sensors must output a voltage between 0V and 5V (or 0V to VDD). Never apply a voltage outside the VDD–VSS range to any Y pin — this will damage the chip.
Arduino Code for CD4051
Here is a complete Arduino sketch that reads all 8 channels of a CD4051 and prints the values to the Serial Monitor:
// CD4051 Multiplexer - Read 8 Analog Channels
const int pinA = 2; // Select bit 0
const int pinB = 3; // Select bit 1
const int pinC = 4; // Select bit 2
const int analogZ = A0; // Common output from CD4051
void setup() {
Serial.begin(9600);
pinMode(pinA, OUTPUT);
pinMode(pinB, OUTPUT);
pinMode(pinC, OUTPUT);
}
void selectChannel(int ch) {
// ch: 0–7
digitalWrite(pinA, (ch & 0x01) ? HIGH : LOW); // bit 0
digitalWrite(pinB, (ch & 0x02) ? HIGH : LOW); // bit 1
digitalWrite(pinC, (ch & 0x04) ? HIGH : LOW); // bit 2
}
void loop() {
for (int ch = 0; ch < 8; ch++) {
selectChannel(ch);
delay(1); // short settling time
int value = analogRead(analogZ);
Serial.print("CH");
Serial.print(ch);
Serial.print(": ");
Serial.print(value);
Serial.print(" ");
}
Serial.println();
delay(500);
}
The selectChannel() function uses bitwise operations to set the three select pins efficiently. Note the delay(1) after channel selection — this is the settling time. After switching channels, the CD4051 output voltage needs a moment to stabilise before the Arduino’s ADC samples it. The required settling time depends on source impedance: for potentiometers (low impedance), 1ms is more than enough; for high-impedance sources, you may need 5–10ms.
You can also use direct port manipulation for faster channel switching:
void selectChannelFast(int ch) {
// Using Arduino Uno PORTD (pins 2,3,4 = bits 2,3,4)
PORTD = (PORTD & 0b11100011) | ((ch & 0x07) << 2);
}
Expanding to 16 Channels
Using two CD4051 chips and a fourth Arduino digital pin, you can read 16 analog channels through two Arduino analog inputs. However, there is a smarter approach: use the INHIBIT pin to effectively create a 16-channel mux with a single Arduino analog input.
Connect both CD4051 chips with shared A, B, C select lines. Connect Chip 1’s INH to Arduino D5, and Chip 2’s INH to an inverted version of D5 (use a transistor or 74HC04 inverter). When D5 is LOW, Chip 1 is active and Chip 2 is disabled. When D5 is HIGH, Chip 2 is active. This gives you 16 channels from 4 digital pins and 1 analog pin.
// 16-channel expansion using 2x CD4051
// Chip1 INH on D5, Chip2 INH on D6 (hardware inverted)
const int chip1Enable = 5;
const int chip2Enable = 6;
void selectChannel16(int ch) {
// ch: 0–15
// 0–7: Chip1, 8–15: Chip2
if (ch < 8) {
digitalWrite(chip1Enable, LOW); // enable chip 1
digitalWrite(chip2Enable, HIGH); // disable chip 2
selectChannel(ch);
} else {
digitalWrite(chip1Enable, HIGH); // disable chip 1
digitalWrite(chip2Enable, LOW); // enable chip 2
selectChannel(ch - 8);
}
}
Practical Applications
The CD4051 unlocks a huge range of sensor-heavy Arduino projects. Here are some common use cases:
Multi-Zone Temperature Monitoring
Connect 8 LM35 or NTC thermistors to one CD4051. Read all 8 temperature zones from a single Arduino analog pin and build a multi-zone HVAC controller or server room monitor.
Resistive Sensor Arrays
Soil moisture sensors, force-sensitive resistors (FSR), flex sensors, and photoresistors are all resistive sensors with analog voltage outputs. Scan 8 of them with one CD4051 for robotics, smart agriculture, or interactive art installations.
Audio Signal Selection
The CD4051 handles audio frequencies without distortion, making it useful as an audio mixer or signal selector. Switch between 8 microphone inputs or audio sources under Arduino control.
Potentiometer Bank
Rotary encoders and potentiometers are essential for synthesiser or controller builds. Read 8 pots with a single analog input and just 3 digital pins, leaving the rest of your Arduino free for audio output and display control.
Capacitive Touch Sensing
Combined with the CapacitiveSensor library, the CD4051 enables 8-zone capacitive touch panels. Perfect for touchless control panels or interactive exhibits.
Limitations and Best Practices
On-Resistance and Reading Accuracy
The CD4051’s ~125Ω on-resistance is only an issue with very high impedance sources. The Arduino’s internal ADC input impedance is around 100 MΩ at DC, so the voltage divider effect with 125Ω is less than 0.01%. You only need to worry if your sensor’s output impedance exceeds a few kilohms.
Input Voltage Range
Analog inputs (Y0–Y7) must stay within the range defined by VDD and VSS. With a 5V supply and VSS = GND, inputs must be between 0V and 5V. Exceeding these limits damages the chip and can cause latch-up — a destructive condition where the chip draws excessive current.
Crosstalk Between Channels
When one channel is open (not selected), its switch is OFF but not perfectly isolated. There is a small capacitive coupling between channels. For audio or precision applications, keep input cables short and use shielded wiring for channels carrying sensitive signals.
Settling Time After Switching
Always add a delay between setting the select pins and calling analogRead(). The default Arduino ADC takes about 100 µs to complete a conversion. For fast scanning, a 1ms software delay is conservative but reliable. For high-speed applications, reduce to 100–200 µs and verify accuracy.
3.3V Arduino Compatibility
The CD4051 works at 3.3V (with VDD = 3.3V, VSS = GND). The input range becomes 0–3.3V. Ensure all sensors output in this range. Select lines from a 3.3V Arduino (Nano 33 IoT, etc.) will correctly drive the CD4051 at 3.3V supply.
Frequently Asked Questions
Can the CD4051 work bidirectionally as a demultiplexer?
Yes. The CD4051’s bilateral switches work in both directions. You can use it to steer one signal to 8 different outputs (demultiplexer) or read one of 8 inputs (multiplexer). This makes it useful for audio routing, signal distribution, and matrix scanning applications.
What is the difference between CD4051, CD4052, and CD4053?
All three are CMOS analog multiplexers. The CD4051 is an 8:1 single-channel mux. The CD4052 is a dual 4:1 mux (two independent 4-channel muxes in one package). The CD4053 is a triple 2:1 mux (three independent SPDT switches). Choose based on how many channels you need and your pin budget.
Can I read digital signals through the CD4051?
Yes. The CD4051 passes any signal within its voltage range — analog or digital. You can use it to multiplex digital sensor signals too, as long as you accept that you can only read one channel at a time. For digital signals, you may not even need a settling delay.
My CD4051 readings are noisy. What should I do?
Add a 100nF decoupling capacitor between VDD and GND close to the chip. Check that VEE/VSS is firmly connected to GND. Increase the settling delay after channel switching. Add a small capacitor (10–47 nF) between the Z (common output) pin and GND to filter high-frequency noise.
How do I use the CD4051 with a 3.3V Arduino Nano 33 IoT?
Supply the CD4051 with 3.3V on VDD (pin 16) and GND on VSS/GND (pins 11, 12). All sensor inputs must be in the 0–3.3V range. Connect Z to one of the Nano 33 IoT’s analog pins. The 3.3V digital select signals from the Nano will correctly drive the 3.3V-supplied CD4051.
Conclusion
The CD4051 analog multiplexer is a powerful and inexpensive solution for overcoming the Arduino’s limited number of analog input pins. With just 3 digital pins and 1 analog pin, you unlock 8 independent analog channels. Chain two chips for 16 channels with 4 digital pins and 1 analog pin. The concept scales cleanly, and the code remains simple.
Whether you are building a 8-zone temperature monitor, a multi-sensor robot, or a 16-potentiometer MIDI controller, the CD4051 belongs in your component drawer. Browse the full range of Arduino boards, sensors, and electronics at Zbotic — quality components delivered across India.
Add comment