Arduino LED Projects with Multiplexer

Interface Arduino and Multiplexer


Schematic: Arduino, 3-to-8 multiplexer, PWM output and LED array wiring.

Product picks (affiliate links) — scroll down for the full article. Note: Elegoo and other compatible boards work with the Arduino IDE. They offer a low-cost alternative to official boards.

Disclosure: some links below are Amazon affiliate links. If you buy via these links, the site earns a small commission at no extra cost to you. Use the parts list to build and test the projects below.

CanaKit Raspberry Pi 5 Starter Kit PRO

ELEGOO Upgraded 37 in 1 Sensor Modules Kit

40 PCS 20 CM Breadboard Jumper Wires

HiLetgo 5pcs USB to Serial CH340 Module

This short collection shows three practical Arduino LED Multiplexer Projects. First, it explains how a 3-to-8 multiplexer and PWM let you control many LEDs with only a few pins. Next, it highlights real effects you can build fast. Finally, it points you to code, schematics, and parts so you can test on any compatible board.

What you'll learn:

  • How multiplexing cuts pin use: control 8 LEDs with 3 select pins + 1 PWM pin.
  • How to wire a 3-to-8 multiplexer to an Arduino board and LED array.
  • Simple code patterns for brightness, ping-pong, and random bursts.

Each example uses a small set of pins on any compatible arduino board. For instance, an arduino uno can drive eight leds with three select pins and one pwm pin. Accordingly, this method keeps wiring neat and parts count low.

Each project below focuses on one lighting effect. First, read the short description. Then, jump to the code and the schematic. Finally, test on your board and tweak delays or pwm values to match the led matrix or LED strip you use.

Quick navigation: Brightness Decrease · Ping Pong · Random Burst

Project 1: Brightness Decrease Effect Using Multiplexed LEDs

Description:

This compact project shows how to dim each LED smoothly while using a 3-to-8 multiplexer. You switch channels with three select pins. Then, you feed a single PWM pin to the multiplexer output. As a result, the sketch reduces the required pins on your arduino board and keeps the wiring tidy. Follow the steps below to build, test, and tweak the effect.

Parts and quick setup

  • Required parts: Arduino (Uno or compatible board), 3-to-8 multiplexer (e.g., 74HC4051), 8 LEDs, breadboard, jumper wires, current limiting resistors.
  • Pins (example): select pins A=2, B=3, C=4, INH (enable) = 5, PWM pin = 9. These pin choices work on an Arduino Uno.
  • Wiring note: connect each LED's resistor to the multiplexer outputs and then to ground or Vcc depending on your multiplexer configuration. Use jumper wires to keep the breadboard tidy.

Resistor calculation (simple)

Use Ohm's law to pick a resistor. For example, with 5V supply and a red LED (forward voltage ~2V) and target current 15mA: R = (5V - 2V) / 0.015A = 200Ω. Accordingly, use a 220Ω resistor to limit current safely.

How it works (short)

The select pins set the multiplexer channel. Then, the pwm signal drives the selected LED. By cycling channel selection fast and writing analog levels to the PWM pin, each LED shows gradual dimming without extra output pins. In practice, the arduino loops through the 8 channels and reduces PWM value stepwise to create the decrease effect.

Copy-ready code (core)

// Define select pins and PWM

const int A = 2;

const int B = 3;

const int C = 4;

const int INH = 5; // Inhibit / enable pin on multiplexer

const int PWM_PIN = 9; // PWM output pin

void setup() {

pinMode(A, OUTPUT);

pinMode(B, OUTPUT);

pinMode(C, OUTPUT);

pinMode(INH, OUTPUT);

digitalWrite(INH, LOW); // Enable multiplexer (check your datasheet)

pinMode(PWM_PIN, OUTPUT);

Serial.begin(9600);

}

void selectChannel(int channel) {

digitalWrite(A, channel & 0x01);

digitalWrite(B, (channel >> 1) & 0x01);

digitalWrite(C, (channel >> 2) & 0x01);

}

void loop() {

// Brightness decrease across all LEDs

for (int i = 0; i < 8; i++) {

selectChannel(i);

for (int brightness = 255; brightness >= 0; brightness -= 5) {

analogWrite(PWM_PIN, brightness);

delay(20);

}

}

}

Notes: change the pin numbers if your board uses different pins. Also, change the delay or brightness step to tune the speed and smoothness of the effect.

Tips and troubleshooting

  • If LEDs appear dim, raise the PWM duty cycle or reduce multiplexing dwell time per channel.
  • To avoid flicker, keep the per-channel refresh rate above ~60Hz; therefore, keep the loop fast and use short delays.
  • Check the multiplexer datasheet for INH (inhibit) logic. Some chips enable on LOW, others on HIGH.

Ready to try? Download the full code from the code block above and buy the parts from the product list above. Additionally, test the selectChannel function by printing the channel index to Serial for fast verification.

Project 2: Ping Pong LED Effect with Arduino and Multiplexer

Description:

Build a smooth ping-pong LED pattern with a 3-to-8 multiplexer and one PWM pin. The code lights LEDs in order from 0 to 7, then reverses the order. You use three select pins to pick the channel, and one pwm signal to set brightness. This design reduces pin count, so you can run an 8-LED sequence using only a few pins on your arduino board.

Wiring recap

  • Connect multiplexer select pins A, B, C to three digital pins on the Arduino (example: 2, 3, 4).
  • Connect the multiplexer output to the PWM pin (example: D9) through the LED and its current limiting resistor on the breadboard.
  • Use jumper wires to route each multiplexer channel to an LED+resistor pair. Confirm polarity before powering the board.

Tune the speed

Adjust the delay inside the loop to change the ping-pong time. For example, use delay(80) for a fast blink, or delay(200) for a slow sweep. Additionally, you can use millis() instead of delay() to keep the loop non-blocking and maintain precise timing for multiple effects.

Copy-ready code (ping-pong)

// Ping-pong LED effect with multiplexer

const int A = 2;

const int B = 3;

const int C = 4;

const int INH = 5; // Inhibit pin for multiplexer

const int PWM_PIN = 9; // PWM pin on Arduino Uno

void setup() {

pinMode(A, OUTPUT);

pinMode(B, OUTPUT);

pinMode(C, OUTPUT);

pinMode(INH, OUTPUT);

digitalWrite(INH, LOW); // Enable multiplexer (check your chip)

pinMode(PWM_PIN, OUTPUT);

}

void selectChannel(int channel) {

digitalWrite(A, channel & 0x01);

digitalWrite(B, (channel >> 1) & 0x01);

digitalWrite(C, (channel >> 2) & 0x01);

}

void loop() {

// forward

for (int i = 0; i < 8; i++) {

selectChannel(i);

analogWrite(PWM_PIN, 255); // full brightness

delay(100); // change this to tune time

analogWrite(PWM_PIN, 0);

}

// reverse

for (int i = 6; i >= 0; i--) {

selectChannel(i);

analogWrite(PWM_PIN, 255);

delay(100);

analogWrite(PWM_PIN, 0);

}

}

Change the delay(100) value to speed up or slow down the pattern. Also, you can lower brightness by writing a smaller PWM value to PWM_PIN.

Troubleshooting

  • If the LEDs show ghosting, shorten the dwell time or add a small blanking period when switching channels.
  • If order is wrong, verify the select pin wiring and the mapping in selectChannel; pin order difference on some boards can change the sequence.
  • If you see flicker, reduce delay per channel and ensure overall refresh is above 60Hz for each LED.

This ping-pong example keeps code short and clear for beginners. For advanced control, replace delay with millis() and implement a state machine so you can run multiple patterns at once.

Project 3: Random LED Burst Effect Using Arduino

Code:

// Random LED burst with multiplexer

const int A = 2; // select pin bit 0

const int B = 3; // select pin bit 1

const int C = 4; // select pin bit 2

const int INH = 5; // multiplexer enable/inhibit

const int PWM_PIN = 9; // PWM output (Arduino Uno)

void setup() {

pinMode(A, OUTPUT);

pinMode(B, OUTPUT);

pinMode(C, OUTPUT);

pinMode(INH, OUTPUT);

digitalWrite(INH, LOW); // Enable multiplexer (check datasheet)

pinMode(PWM_PIN, OUTPUT);

Serial.begin(9600);

}

void selectChannel(int channel) {

digitalWrite(A, channel & 0x01);

digitalWrite(B, (channel >> 1) & 0x01);

digitalWrite(C, (channel >> 2) & 0x01);

}

void loop() {

// burst 10 random LEDs

for (int i = 0; i < 10; i++) {

int randomLED = random(0, 8); // pick channel 0..7

selectChannel(randomLED);

analogWrite(PWM_PIN, 255); // turn LED on

delay(100); // visible burst time

analogWrite(PWM_PIN, 0); // turn LED off

delay(50); // short gap

}

delay(1000); // pause between bursts

}

This code runs on an Arduino Uno or a compatible board. It chooses a number from 0 to 7, then it sets the three select pins. Next, the PWM pin drives the selected LED. Finally, the loop repeats to create lively bursts. Use the gist raw link above to download the full multiplexer3codes.ino file.

Code explained — short notes

  • setup() — sets pin modes for the select pins, the inhibit pin, and the PWM output. Then it enables the multiplexer and starts Serial for debugging.
  • selectChannel() — converts the channel number into three bits and writes them to the A, B, C pins. In effect, this picks which multiplexer output is active.
  • loop() — generates random numbers and lights the chosen LED for a short time. You can change the loop to alter the number, timing, and intensity of bursts.

How to test wiring and logic

  1. Power the board and open Serial Monitor. Then, run a quick test: in loop print the selected channel (Serial.println(randomLED)) to confirm the numbers look random.
  2. Test each channel manually: call selectChannel(0..7) and measure the multiplexer output voltage to verify correct mapping.
  3. Check LED wiring on the breadboard and confirm each LED has a current limiting resistor (recommended 220Ω or 330Ω for 5V systems).

Resistors and safe current (ohms / calculation)

Pick resistor value with Ohm's law. For a typical LED: supply = 5V, LED forward voltage ≈ 2V, target current = 15mA: R = (5V − 2V) / 0.015A ≈ 200Ω. Thus use 220Ω. If you run many leds at once, check total current limits for your board and power supply.

Notes on multiplexing and brightness

  • Multiplexing trades continuous output for fewer pins. Each LED receives power only a fraction of the time (time-division). Consequently, brightness drops; compensate by raising duty cycle or peak PWM value.
  • Keep the per-channel refresh rate high to avoid flicker. For example, iterate faster so each LED refreshes above ~60Hz.
  • Consult the multiplexer datasheet for INH (inhibit) behavior. Some chips enable on LOW, others on HIGH — adjust digitalWrite(INH, LOW/HIGH) accordingly.

Non-blocking alternative (millis)

// Simple non-blocking burst skeleton using millis()

unsigned long lastTime = 0;

const unsigned long burstInterval = 100; // ms per LED on-time

int burstCount = 0;

void loop() {

if (millis() - lastTime >= burstInterval) {

lastTime = millis();

int randomLED = random(0,8);

selectChannel(randomLED);

analogWrite(PWM_PIN, 255);

// schedule turning off later and continue other tasks

// (implement with a small state machine)

burstCount++;

if (burstCount >= 10) {

burstCount = 0;

// pause between bursts handled by additional timing logic

}

}

// other non-blocking tasks can run here

}

Use the millis() pattern when you need precise timing or when you run multiple effects at once. This pattern keeps the code responsive and avoids long delay() blocking the processor.

Practical limits and recommendations

  • You can multiplex many LEDs, but each additional LED reduces apparent brightness. For large arrays, consider using external drivers or LED matrix modules.
  • Use proper jumpers and a stable power supply. If you plan high current, use a separate 5V supply and common ground.
  • Follow the datasheet: check max voltage and current per channel for your multiplexer IC. Some parts tolerate only limited current without extra transistors or buffers.

Download the full code from the raw gist link above to run the exact examples shown here. Also, watch the short demo video (if available) to see timing and brightness settings in action.

Connections:

Wiring summary

  • Connect select pins A, B, C to Arduino digital pins (example: 2, 3, 4).
  • Connect INH (inhibit) pin to a digital pin (example: 5). Set LOW or HIGH per your multiplexer datasheet to enable output.
  • Route the multiplexer common output to the PWM pin (example: D9). Each channel connects to one LED + resistor on the breadboard using jumper wires.
  • Use current limiting resistors (220Ω–330Ω) for each LED. Check voltage and total amount of current if you drive many LEDs.

Breadboard connections and jumper wires — follow this wiring visual when you build.

Quick checklist before power-up:

  • Verify pin mapping in code matches your wiring (A=2, B=3, C=4, INH=5, PWM=9 by default).
  • Confirm each LED has a resistor and correct polarity.
  • Check the multiplexer datasheet for inhibit logic level and per-channel current limits.

Final notes & next steps

To summarize, this guide shows how to wire and code a multiplexer-driven LED array on an Arduino board. Next, try these experiments to extend the project:

  • Increase the amount of LEDs by chaining multiplexers or using an LED matrix driver.
  • Swap the Arduino Uno for an Arduino Mega if you need more pins for sensors or control lines.
  • Use transistors or driver ICs when you need higher current per LED.

Affiliate note: Some links in this post are affiliate links. If you buy parts via those links, the site earns a small commission without extra cost to you. See the product list above for recommended parts.

IOT proteus-simulation

Share this tutorial:

Post a Comment

0 Comments