Amazon List





List of Products from Amazon

These are affiliate links to products that may help you in your Arduino and Raspberry Pi projects.
Note: ELEGOO boards are not official Arduino boards, but they are compatible with the Arduino IDE and are more affordable!

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.

Code:

#include <Arduino.h>

// Define pins
const int buttonPin = 2;
const int ledPin = 9;

void setup() {
    pinMode(buttonPin, INPUT);
    pinMode(ledPin, OUTPUT);
}

void loop() {
    if (digitalRead(buttonPin) == HIGH) {
        digitalWrite(ledPin, HIGH);
    } else {
        digitalWrite(ledPin, LOW);
    }
}
  

Working Principle

  1. Button State Reading (74HC165):
    • The Arduino loads parallel data from the 8-button inputs into the 74HC165 shift register.
    • It then shifts out the data serially, reading each button state one by one.
  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.

This design is ideal for applications requiring efficient input reading and output control while minimizing pin usage on an Arduino or microcontroller.

Post a Comment

0 Comments