Fiverr gig
$15 β€” I will help you with your project and simulate it for you
Hire me
πŸ€– Arduino Projects

How to extend the inputs and outputs of any microcontroller.

EmbedLab TeamFebruary 12, 20253 min read
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:

Proteus screenshot of the shifter, the multiplexer and the arduino uno

Pin connection table:

For the 74HC165
pin connections to the 74HC165

For the 74HC4051

Pin connections to the 74HC4051

Working Principle

  1. 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.
  2. 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).
  3. 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.

ET

EmbedLab Team

Embedded systems engineer and educator. Writes weekly tutorials at EmbedLab to help beginners ship real hardware.

Related projects

Browse all 50+ projects