How OnResistance (Ron) Can Ruin Your Analog Readings (And How to Fix It)
🤔 OnResistance troubleshooting analog readings is crucial for accurate measurements; high Ron can distort data. Learn practical fixes and improve your circuit…
Read article
Unlock the full potential of your microcontroller projects by mastering multiplexers and demultiplexers—the ultimate solution for expanding I/O ports without upgrading your MCU. Whether you’re a hobbyist or a pro, this guide dives into practical interfacing techniques, showing you how to control multiple sensors, LEDs, or displays using just a few pins. Learn to reduce wiring complexity, save board space, and boost efficiency with clear, step-by-step examples. From signal routing to data selection, we cover the essential logic, timing, and code snippets—perfect for Arduino, ESP32, STM32, and more. Get ready to maximize your MCU’s capabilities and simplify your DIY builds today!
🤔 OnResistance troubleshooting analog readings is crucial for accurate measurements; high Ron can distort data. Learn practical fixes and improve your circuit…
Read article🚀 Discover the software hardware multiplexing benefits and understand their key differences, pros, and cons. Perfect for DIY electronics enthusiasts, this guide…
Read article🔧 Discover how to leverage the versatile CD4000 series CMOS mux components in modern DIY projects. Explore detailed CMOS mux datasheet application…
Read article🚀 Discover how to build your first Raspberry Pi Pico Multiplexer with our easy-to-follow tutorial, transforming your DIY electronics skills from beginner…
Read articleWhen your microcontroller runs out of GPIO pins, you don’t need a bigger MCU—you need a multiplexer (MUX) or demultiplexer (DEMUX). These clever ICs let you expand inputs and outputs dramatically, reading many sensors or driving many LEDs with just a few pins. In this subcategory of our Interfacing Tutorials, you’ll learn how to wire, code, and troubleshoot 74HC4051, CD4067, and 74HC238 chips with Arduino, ESP32, and STM32. Expect practical breadboard diagrams, C++ sketches, and timing logic breakdowns, all geared for DIY electronics projects.
First, you need to match the chip to your task. For analog signals (like potentiometers or LDRs), use an analog multiplexer like the 74HC4051 (8-channel) or CD4067 (16-channel). For digital outputs, a demultiplexer like the 74HC238 (3-to-8 line) is ideal. Consider voltage levels—most 74HC series work at 3.3V–5V, perfect for ESP32 and Arduino. Also check bandwidth if you’re sampling fast analog signals.
In our tutorials, you’ll see comparison tables showing channel count, logic voltage, and switching speed. We also cover breakout boards vs. bare DIP chips. Remember: a 16-channel MUX can replace 16 digital inputs with just 4 control pins plus one data pin—saving precious GPIO for other uses. For beginners, we recommend starting with the 74HC4051 because it’s cheap, forgiving, and widely documented.
Let’s get physical. Connect the MUX’s address pins (A0, A1, A2) to three digital outputs on your Arduino, the common pin (COM) to an analog input, and each sensor’s signal to the MUX’s channel pins (Y0–Y7). Add a 10kΩ pull-down resistor on the COM line if your sensors are open-collector. Use a 5V supply for the MUX, but if using an ESP32, keep logic levels at 3.3V—check your chip’s datasheet.
We provide a step-by-step breadboard layout with clear color-coded wires. You’ll also learn to enable the chip using the active-low enable pin (E), which allows you to stack multiple MUXes for even more channels. After wiring, you’ll test each channel by sending a 3-bit binary value (000–111) to the address pins and reading the analog value. This setup is perfect for building weather stations with many temperature sensors or a touch-sensitive keyboard.
Programming a MUX is straightforward. In your Arduino sketch, define three pins for address control and one pin for the data input. Use a loop to iterate through 0–7, set the address pins, then read `analogRead()` or `digitalRead()`. For faster scanning, you can use bit manipulation to set the pins in one go—our code examples show both beginner-friendly and optimized versions.
For ESP32, we also cover how to use the I2C bus with a MUX like the TCA9548A to connect multiple I2C devices with the same address—a lifesaver for adding many OLED displays or accelerometers. We include full code with comments explaining each line. We also demonstrate how to debounce digital inputs that go through a demultiplexer, ensuring reliable button presses without extra hardware.
Demultiplexers work in reverse: one input, many outputs. Use a 74HC238 to drive 8 LEDs or relay modules from just 4 pins (3 address + 1 data). Our tutorial shows how to control each output individually or in sequence, perfect for creating a running light effect or a compact relay controller for home automation. We also explain how to extend PWM signals—though note that MUX/DEMUX can’t mix analog PWM directly; use it as a digital switch for on/off control.
For more advanced projects, we cover using a demultiplexer to select which 7-segment display to update in a multi-digit counter. This technique reduces pin usage from 12 to just 7. We provide timing diagrams showing when to change the address pins versus the data pin to avoid ghosting. You’ll also learn how to combine a MUX input and DEMUX output on the same MCU to create a full matrix scanning system for keypads.
No connection? First, verify you’ve set the enable pin low—many chips have an active-low enable that beginners forget. Next, check that the address pins are truly pulled to GND or VCC, not floating. Use a multimeter to confirm the common pin toggles between channels. If your analog readings are erratic, your power supply may be noisy—add a 100nF decoupling capacitor between VCC and GND on the MUX.
Another common issue is exceeding the chip’s voltage range—never feed a 5V sensor into a 3.3V MUX without level shifting. We also explain how to use a logic analyzer to visually confirm the address pins change correctly. If your outputs don’t light up, test each DEMUX channel with a simple LED and resistor directly, bypassing your MCU code. Our guides include a checklist at the end of each tutorial to isolate hardware vs. firmware problems.
A multiplexer (MUX) selects one of many input signals and routes it to a single output, controlled by address pins. A demultiplexer (DEMUX) does the reverse—takes one input signal and routes it to one of many outputs. For MCUs, a MUX expands inputs (e.g., reading many sensors), while a DEMUX expands outputs (e.g., driving many LEDs).
Yes, but only if the MUX is analog-compatible, like the 74HC4051. It acts as a switch for analog voltages without converting them. The MCU’s analog-to-digital converter (ADC) still needs to be on the common pin. Ensure the MUX’s voltage range matches your sensor’s output and your MCU’s ADC input limits.
Using an 8-channel MUX like the 74HC4051 requires 3 address pins plus 1 data pin—so you expand one MCU data pin into 8 inputs. With 4 address pins (CD4067), you get 16 channels. You can also cascade multiple MUXes by sharing address pins and using separate enable lines, gaining exponential expansion.
You need a small delay (1–10 microseconds) after changing address pins before reading the output, especially for capacitive loads. Add a `delayMicroseconds(10)` in your code after setting address pins. Also, place a 10nF capacitor on the common pin to smooth transients if your sensors have high output impedance.
No, not directly. The MUX’s supply voltage determines its signal range. If the MUX runs at 5V, its outputs can go to 5V, which may damage the ESP32’s GPIO. Use a level shifter between the MUX’s common pin and the ESP32, or choose a MUX rated for 3.3V operation and keep sensor voltages within 3.3V.