list of products from Amazon (Not mine, i just link them!) Scroll Down For Article! Note: Elegoo boards are not Arduino, but they are compatible with Arduino IDE and are mutch more affordable!
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.
list of products from Amazon (Not mine, i just link them!)
Please NOTE that ELEGOO is not Arduino but it is compatible with Arduino IDE, and mutch cheaper!
CanaKit Raspberry Pi 5 Starter Kit PRO - Turbine Black (128GB Edition) (8GB RAM)
0 Comments