Use SN74HC595N Shift Register with arduino , project with code

arduino tutorial SN74HC595N Shift Register tutorial, project with code
SN74HC595N Shift Register

The SN74HC595N Shift Register, is an integrated circuit (IC), 8-bit. That allow to add an additional inputs or outputs, to a microcontroller by converting data between parallel and serial formats.
We give it 8-bit from the serial input and then outputs them to 8 pins. In this post we will learn: How To Use SN74HC595N Shift Register with arduino.

The SN74HC595N Shift Register pins

The SN74HC595N Shift Register
The SN74HC595N Shift Register

Electronic components needed :

  • SN74HC595N Shift Register
  • 8 LEDs
  • 8 Resistances ( 220 Ohm )
  • Electrical wires
  • Arduino UNO
  • Breadboard

Use SN74HC595N Shift Register with arduino , project with code

circuit diagram :

SN74HC595N Shift Register circuit diagram
SN74HC595N Shift Register circuit diagram

Arduino programming code :

int DataPin = 2;  // Data Pin is connected to Pin No. 2
int ClockPin = 3; // Data Pin is connected to Pin No. 3
int LatchPin = 4; // Data Pin is connected to Pin No. 4
byte Data = 0;  // 6 Bit Data to be sent through DataPin
// by www.andprof.com
void setup()
{
  pinMode(DataPin, OUTPUT);   // All 3 pins are output
  pinMode(ClockPin, OUTPUT);  
  pinMode(LatchPin, OUTPUT);
}


void loop()
{
  
  increment(); // LEDs increment start from 0 - 5   
  delay(100);  
  SOS();        // All LEDs ON and OFF 10 times
  OneByOne();   // LEDs Glow one by one from 0 to 5
  delay(100);
  

}

// Function defined below

void shiftWrite(int Pin, boolean State) // Function is similar to digitalWrite 
{                                       // State-0/1 | Pin - Pin No.
  bitWrite(Data,Pin,State);             // Making Pin(Bit) 0 or 1
  shiftOut(DataPin, ClockPin, MSBFIRST, Data); // Data out at DataPin
  digitalWrite(LatchPin, HIGH);                // Latching Data
  digitalWrite(LatchPin, LOW);
}

void increment()   //LEDs increment start from 0 - 5 
{
  int PinNo = 0;
  int Delay = 100; 
  
  for(PinNo = 0; PinNo < 8; PinNo++)
  {
    shiftWrite(PinNo, HIGH);
    delay(Delay);                
  }
  for(PinNo = 7; PinNo >= 0; PinNo--)
  {
    shiftWrite(PinNo, LOW);
    delay(Delay);                
  }
}

void OneByOne()  // LEDs Glow one by one from 0 to 5
{
  int PinNo = 0;
  int Delay = 100; 
  
  for(PinNo = 0; PinNo < 8; PinNo++)
  {
    shiftWrite(PinNo, HIGH);
    delay(Delay); 
    shiftWrite(PinNo, LOW);    
  }
  for(PinNo = 7; PinNo >=0 ; PinNo--)
  {
    shiftWrite(PinNo, HIGH);
    delay(Delay); 
    shiftWrite(PinNo, LOW);    
  }

}

void AllHigh()   // sets all High
{
  int PinNo = 0;
  for(PinNo = 0; PinNo < 8; PinNo++)
  {
   shiftWrite(PinNo, HIGH);  
  }
}

void AllLow()   // Sets all low
{
  int PinNo = 0;
  for(PinNo = 0; PinNo < 8; PinNo++)
  {
   shiftWrite(PinNo, LOW);  
  }
}

void SOS(){                  // All LEDs ON and OFF 10 times
  for (int x=0; x<10; x++){    
  AllHigh();
  delay(100);
  AllLow();
  delay(100);
  }
}

Explainer video :

Discover also :

Control Any Device by Remote Control

Clap Switch with Arduino and Sound Sensor

How to make fire detector using arduino