Arduino with 74hc165 and 74hc595

Hello,

I'm trying to create a code to control 10 LEDs with 10 reed switches. I've found a sample code at https://dronebotworkshop.com/shift-registers/ where code is very close to what I'd like to accomplish. But I'd like to make some changes to fit my idea.

  1. Right now the LED only lights up when the button is pressed. I'd prefer if it stayed on until another button is pressed.
  2. When example calls for pull up resistors on buttons. Would it be possible to use Arduino Uno boards build in resistors to make the wiring simpler?

Any tips or directions would be appreciated as I'm having problems wrapping my mind around shift registers.

/*
  74HC595 & 74HC165 Shift Register Demonstration
  74hc595-to-74ch165.ino
  Input for 8 pushbuttons using 74HC165
  Output to 0 LEDs using 74HC595

  DroneBot Workshop 2020
  https://dronebotworkshop.com
*/

// Define Connections to 74HC165

// PL pin 1
int load = 7;
// CE pin 15
 int clockEnablePin = 4;
// Q7 pin 7
int dataIn = 5;
// CP pin 2
int clockIn = 6;

// Define Connections to 74HC595

// ST_CP pin 12
const int latchPin = 10;
// SH_CP pin 11
const int clockPin = 11;
// DS pin 14
const int dataPin = 12;

void setup () {

  // Setup Serial Monitor
  Serial.begin(9600);

  // 74HC165 pins
  pinMode(load, OUTPUT);
  pinMode(clockEnablePin, OUTPUT);
  pinMode(clockIn, OUTPUT);
  pinMode(dataIn, INPUT);

  // 74HC595 pins
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);

}


void loop() {

  // Read Switches

  // Write pulse to load pin
  digitalWrite(load, LOW);
  delayMicroseconds(5);
  digitalWrite(load, HIGH);
  delayMicroseconds(5);

  // Get data from 74HC165
  digitalWrite(clockIn, HIGH);
  digitalWrite(clockEnablePin, LOW);
  byte incoming = shiftIn(dataIn, clockIn, LSBFIRST);
  digitalWrite(clockEnablePin, HIGH);

  // Print to serial monitor
  Serial.print("Pin States:\r\n");
  Serial.println(incoming, BIN);


  // Write to LEDs

  // ST_CP LOW to keep LEDs from changing while reading serial data
  digitalWrite(latchPin, LOW);

  // Shift out the bits
  shiftOut(dataPin, clockPin, LSBFIRST, incoming);

  // ST_CP HIGH change LEDs
  digitalWrite(latchPin, HIGH);

  delay(500);

}
  • Welcome to the group.

  • With respect, you have existing code that needs to be modified to your needs.
    Are you looking for someone to take the code you found and modify that code ?

  • What exactly are you needing help with ?

  • Suggest you read the posting guide lines.
    At the top of the list is for you to show us your proposed schematic.
    A schematic is the universal language we use to exchange ideas on your project.

  • What is your background in hardware and software ?

  • What hardware and equipment do you have ?

1 Like

The explanation in the dronwbotworkshop link is very simple and detailed. I'm not sure I could explain it an bettor.

Thank you for responses. They have not addressed either of my questions while making me feeling more stupid and unwelcome here.

Yes.

Can you clarify what you don't understand? If you can ask a specific question I or someone will try to help.

Do you mean the example that starts with:

Arduino & 74HC165 Hookup

The inputs of the 74HC165 need to be pulled down LOW to prevent false readings, so in addition to our eight pushbutton switches we will also need eight pulldown resistors. I used 10k resistors, but any value from 4.7k to 27k will work fine.

If that's what you mean, the example with the buttons and the resistors connected to the 74HC165 then the answer is no, because the internal Arduino Uno resistors are inside the microcontroller, not connected to the shift register, not only that but the Uno internal resistors are 'pull up' (to 5V), whereas the buttons in the example are wired to need 'pull down' (to 0V) resistors.

I note that while I was typing @jim-p replied with 'yes', which makes me think he's thinking of something different to me. One of us is wrong, I don't know which of us. It would help us if you made clear exactly what you are asking about.

I am but let's see what @pokethrow77 has to say.

1 Like

Search, "finite state machine" for a lot of information, or if you understand "set a flag/clear a flag" to indicate when the light should be on or off.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.