Analog multiplexer data selector
Build it step by step
0 of 7 donePower the chip
Wire 5 V, ground, VEE and the inhibit pin.
Wire the eight inputs
Four pots, two LDR dividers, a half-supply and a ground.
Set the address by hand
Use the DIP switches and read the meter.
Step through the eight channels
Note the changes on each.
Move to the Uno
Connect A, B, C and COM to the Uno and upload.
Watch eight values
Turn the pots and cover the LDRs.
Check the references
Channel 6 should read about 512 and channel 7 near 0.
How do you build an analog multiplexer data selector?
A CD4051 selects one of eight sensors to send to a single meter, picked by three address lines. You need CD4051 analog multiplexer, DIP switch 8-position, Potentiometer 10 kΩ × 4, LDR Photoresistor × 2, Resistor 10 kΩ × 5, Digital multimeter, Arduino Uno R3, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 7 steps and about 60 minutes.
- Level
- Intermediate
- Time
- About 60 min
- Parts
- 9
Wiring
| From | To | Why |
|---|---|---|
| CD4051 pin 16 (VDD) | 5V | Power |
| CD4051 pin 8 (VSS) and pin 7 (VEE) | GND | Ground and negative supply |
| CD4051 pin 6 (INH) | GND | Chip enabled |
| CD4051 pin 11 (A) | DIP switch 1, with 10 kΩ to GND, or Uno D2 | Address bit 0 |
| CD4051 pin 10 (B) | DIP switch 2, with 10 kΩ to GND, or Uno D3 | Address bit 1 |
| CD4051 pin 9 (C) | DIP switch 3, with 10 kΩ to GND, or Uno D4 | Address bit 2 |
| DIP switch other sides | 5V | A closed switch reads high |
| Potentiometer wipers (four) | CD4051 pins 13, 14, 15, 12 (channels 0 to 3) | Four input signals, pot ends on 5V and GND |
| LDR with 10 kΩ | 5V through the LDR, 10 kΩ to GND, midpoint to pin 1 (channel 4) | Light sensor |
| Second LDR with 10 kΩ | Same, midpoint to pin 5 (channel 5) | Light sensor |
| Pin 2 (channel 6) | 5V through 10 kΩ and GND through 10 kΩ | Half supply reference |
| Pin 4 (channel 7) | GND | Zero reference |
| CD4051 pin 3 (COM) | Multimeter + or Uno A0 | Selected signal out |
Code
The CD4051 connects one of eight inputs to a single common pin according to the three-bit address on A, B and C (channel number = A + 2B + 4C). With the supply at 5 V and VEE at ground, signals must stay between 0 and 5 V. The switch has some on-resistance, so read into a high-impedance input such as a multimeter or an Arduino analogue pin. With the DIP switches, set the address by hand and read the meter; with the Uno, disconnect the switches and drive the address lines from D2 to D4. The pin numbers on the table follow the standard CD4051 pinout: 13, 14, 15, 12, 1, 5, 2, 4 are channels 0 to 7. Arduino IDE, board "Arduino Uno" (or "Arduino Nano" with processor ATmega328P).
Runs on a virtual Arduino Uno in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
// Reads all eight channels through the CD4051 with address lines on D2, D3 and D4.
const byte ADDR[3] = {2, 3, 4}; // A, B, C
const byte COM = A0;
int readChannel(byte ch) {
for (byte i = 0; i < 3; i++) digitalWrite(ADDR[i], (ch >> i) & 1);
delayMicroseconds(100); // let the switch and the input settle
analogRead(COM); // throw away the first reading after switching
return analogRead(COM);
}
void setup() {
for (byte i = 0; i < 3; i++) pinMode(ADDR[i], OUTPUT);
Serial.begin(9600);
}
void loop() {
for (byte ch = 0; ch < 8; ch++) {
Serial.print(readChannel(ch));
Serial.print(ch < 7 ? "\t" : "\n");
}
delay(500);
}What the serial monitor should show
Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Uno with its sensors at their default values. Your numbers will follow your real readings, but the format should match.
513 512 512 512 512 511 511 511 512 511 512 513 512 513 512 512 511 512 512 512 512 512 512 511 513 512 513 513 511 512 512 512 512 511 512 511 512 513 513 512 511 512 512 512 512 511 513 512
Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Address 000 | Channel 0, pot 1 |
| Address 111 | Channel 7, near zero |
| Covering an LDR | Its channel changes |
| Channel 6 | About half scale |
If it does not work
All channels read the same
Check the address lines and the inhibit pin.
Readings are noisy
Add a 100 nF capacitor on COM to ground.
Channel numbers wrong
Check the pin order against the datasheet.
Signal clipped
Keep inputs between 0 and 5 V.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the analog multiplexer data selector?
CD4051 analog multiplexer, DIP switch 8-position, Potentiometer 10 kΩ × 4, LDR Photoresistor × 2, Resistor 10 kΩ × 5, Digital multimeter, Arduino Uno R3, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).
How long does the analog multiplexer data selector take to build?
About 60 minutes for a intermediate maker, in 7 steps.
How do I know the analog multiplexer data selector works?
Address 000: Channel 0, pot 1. Address 111: Channel 7, near zero. Covering an LDR: Its channel changes.
All channels read the same: what should I check?
Check the address lines and the inhibit pin.
Readings are noisy: what should I check?
Add a 100 nF capacitor on COM to ground.
Channel numbers wrong: what should I check?
Check the pin order against the datasheet.
Signal clipped: what should I check?
Keep inputs between 0 and 5 V.
