Multiplexer and shift register projects

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 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.

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)

CanaKit Raspberry Pi 5 Starter Kit PRO - Turbine Black (128GB Edition) (8GB RAM)

Post a Comment

0 Comments