Project tutorial
Interfacing SN74HC165N with Arduino

Interfacing SN74HC165N with Arduino © CC BY-SA

Sample code on how to interface with the SN74HC165N IC so as to save data pins when dealing with a large amount of simple digital inputs.

  • 2 views
  • 0 comments
  • 0 respects

Components and supplies

About this project

When working on a project using shift registers I found plenty of tutorials on how to user SIPO but almost nothing on PISO so I wrote this tutorial. This could provide the basics for getting a PISO register working on your project!

Currently, the byte of information is simply printed to the serial monitor but the byte could be written bit by bit for input. My use of this register is monitoring the state of 5 arcade buttons.

Code

SN74HC165_V1.inoC/C++
/*
:Author: Matthew Moore
:Email: mattmooreux@gmail.com
:Date: 02/11/2020
:Revision: version 1
:License: Public Domain
 */

int latchPin = 4; //Connect to pin 1 on SN74HC165N
int clockPin = 2; //Connect to pin 2 on SN74HC165N
int dataPin = 3; //Connect to pin 9 on SN74HC165N

int buttonPin = A0; //Connect the NO side of a button to A0. This will act as a stepper in our code so that we can manually pulse the IC and read from it. 

byte butts = 0; //All our IC data will be compressed into this byte for simplicity

void setup() {
  Serial.begin(9600);  //start serial connection

  pinMode(buttonPin, INPUT_PULLUP); //The button connected to A0 will use a PullUp solution so make sure the COM lead of the button is connected to GND

  pinMode(latchPin, OUTPUT); //Set out IC and button pins
  pinMode(dataPin, INPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(buttonPin, INPUT_PULLUP);
}


void updatePullRegister(){
  digitalWrite(clockPin, HIGH); //First step here will be to pulse the latch/reset pin while sending a falling clock signal.
  digitalWrite(latchPin, LOW); //This will lock in the current state of the inputs to be sent to the arduino. 
  delayMicroseconds(5);
  digitalWrite(clockPin, LOW);
  digitalWrite(latchPin, HIGH); 

  for(int i = 0;i<8;i++){
    bitWrite(butts, i, digitalRead(dataPin)); //Grab our byte, select which bit, and write the current input as 1 or 0

    digitalWrite(clockPin, LOW); 
    delayMicroseconds(5);
    digitalWrite(clockPin, HIGH); //send a clock leading edge so to load the next bit
  }

}

void loop(){
  butts = 0; //Reset the butts byte to 0s across the board

  if (digitalRead(buttonPin) == LOW) {
    updatePullRegister(); //run the fuction to load all the serial info into the butts byte
    Serial.println("Input Pins: \r"); //print the whole byte bit by bit to the monior
    for (int i = 0; i < 8; i++) {
      Serial.print(i);
      Serial.print(": ");
      Serial.print(bitRead(butts, i));
      Serial.println();
    }
  }
}

Schematics

SN74HC165N Schematic
Schematic for connecting IC to Arduino Uno
Screen shot 2020 02 13 at 12 48 30 pm k4xeffeymi

Comments

Similar projects you might like

XBee Arduino Interfacing

Project tutorial by Fouad_Roboticist

  • 1,328 views
  • 4 comments
  • 5 respects

Interfacing Arduino With Node-RED

by Gokul Periyasamy

  • 25,636 views
  • 1 comment
  • 19 respects

Interfacing Arduino UNO with SURE Electronics LED Dot Matrix

Project tutorial by Arduino_Scuola

  • 5,129 views
  • 1 comment
  • 3 respects

Arduino TFT Interfacing

Project tutorial by the lonely programmer

  • 4,693 views
  • 0 comments
  • 20 respects

BMP180 Interfacing with Arduino in Depth

by WGLabz

  • 4,359 views
  • 1 comment
  • 6 respects

Interfacing Arduino with Raspberry Pi

by Sankar Cheppali

  • 94,052 views
  • 9 comments
  • 30 respects
Add projectSign up / Login