How to extend the inputs and outputs of any microcontroller.
This project uses two key ICs: the 74HC4051 analog multiplexer/demultiplexer and the 74HC165 shift register. It controls an 8-button input system and a PWM-controlled LED system. The 74HC165 shift register reads up to 8 buttonswith just a few GPIO pins. The 74HC4051 multiplexer controls 8 LEDs with one PWM pin. It scans buttons, updates LEDs, and sets their brightness. When a button is pressed, the LED toggles between ON (full brightness) and OFF using an XOR operation. The PWM pin (D9) controls LED brightness, saving microcontroller resources. The system runs in a loop, checking for button presses and updating LEDs. This method reduces pins needed while maintaining control over inputs and outputs.
CODE:
Schematic:
Pin connection table:
Working Principle
Button State Reading (74HC165):
- The Arduino loads parallel data from 8-button inputs into the 74HC165 shift register.
- It then shifts out the data serially, reading each button state one by one.
- If a button is pressed, its corresponding bit is set in the buttonStates variable.
LED Control (74HC4051):
- The system loops through all 8 LEDs, using the 74HC4051 multiplexer to select which LED to control.
- If the corresponding button is pressed, it toggles the LED ON/OFF using an XOR operation.
- The LED brightness is set using PWM on pin D9, meaning the LED is either fully ON (255) or OFF (0).
Efficient GPIO Usage:
- Instead of using 16 separate GPIO pins, the project uses just 6 digital pins for controlling 8 buttons and 8 LEDs.
- The 74HC165 shift register allows reading multiple inputs through a single data pin.
- The 74HC4051 multiplexer enables control of multiple LEDs using a single PWM pin.
This design is perfect for projects needing efficient input reading and output control with minimal pin usage.
You may also like
EmbedLab Team
Embedded systems engineer and educator. Writes weekly tutorials at EmbedLab to help beginners ship real hardware.
Related projects

Add inputs and outputs to microcontrollers
This project integrates two key ICs: the 74HC4051 analog multiplexer/demultiplexer and the 74HC165 shift register , to efficiently control an 8-button input system and a PWM-controlled LED system . Co

Water Level Sensor with Arduino
Step-by-step Arduino tutorial: wire the water level to an Arduino UNO, upload the example sketch, and read live values on the Serial Monitor.
 β Arduino UNO tutorial cover image](/uploads/arduino-covers/tcs3200-colour-sensor-with-arduino.webp)
Interfacing 16x2 LCD with Arduino
Step-by-step Arduino tutorial: wire the tcs3200 colour to an Arduino UNO, upload the example sketch, and read live values on the Serial Monitor.
 β Arduino UNO tutorial cover image](/uploads/arduino-covers/sound-sensor-with-arduino.webp)
Interfacing 16x2 LCD with Arduino
Step-by-step Arduino tutorial: wire the sound to an Arduino UNO, upload the example sketch, and read live values on the Serial Monitor.

Arduino Micro SD Card Module Project
Step-by-step Arduino tutorial: wire the sd card to an Arduino UNO, upload the example sketch, and read live values on the Serial Monitor. Use it for data loggers (temperature, humidity, gps).



