Menu Close

Arduino – Shift Register (Serial In Parallel Out)

This tutorial of Robo India explains how to extend output pins of Arduino Board. It is major constrain of Arduion. But with the help of this tutorial you can increase output pins of Arduino Board.

1. Introduction:

A step by step illustrated tutorial to extend output pins of Arduino. This tutorial uses 74HC595N shift Register for Serial in and Parallel out.

This register IC takes 3 pin input and gives output at 8 Pins. Thus this extends 3 pins to 8 pins.

1.1 SN74HC595N Shift Register.

This is a popular shift register we are using in this tutorial. It requires a three pin interface from Arduino

  1. Data pin: Data is sent in serial mode.
  2. Clock Pin: A clock runs on this pin
  3. Latch Pin: This pin is used to toggle so that shift register shows 8 bit data on output.

Data sheet of SNHC595N can be downloaded from here:

Following is the pinout diagram of SN74HC595N shift Register:

2. Required Hardware

Following Hardware will be required to perform this sketch of shift register.

S.No.ItemQuantity
1.R-Board with FTDI or Arduino Board1
2.Bread Board1
3.Male to male Jumpers 24
4.Indicator LED8
5.100 OHM Resistance 
6.SN74HC595N Shift Register1

3. Building Circuit

Make following circuit with the help of above mentioned components.

3.1 You may go with Robo India’s R-Board(UNO Compatible)-

Here is the schematic of this circuit-

or

3.2 You may go with original Arduino UNO Board-

Here is the schematic of this circuit-

4. Programming:

Once we are done with circuit part, here is our programme to this circuit. Every command of the following programme is explained in the comment section. A few function to consider for this sketch.

4.1 shiftWrite(Pin, State): This function is same as digitalWrite function. It makes Pin HIGH/LOW. Usage is as same as the digitalWrite function.

4.2increament() : This function is designed for LED array on  shift register, LED starts glowing from LED 0 to LED 7 and as all gets ON these starts getting OFF from LED 7 to LED 0.

4.2 OneByOne(): This function is similar to above mention increment() function but the difference is that in this function only one LED glows at a time. So in this function LED starts glowing from LED 0 to LED 7 and in the reverse order too.

4.3. AllHigh(): This function makes all output pins HIGH.

4.4 AllLow(): This function makes all output pins LOW.

4.5 SOS(): This function repeats AllHigh() and AllLow() function 10 times with an interval of 100ms between two steps.

The output Video demonstrate all of the above mentioned function.

You may download this code (Arduino Sketch) from here.

// Robo India Tutorial on Shift Register SN74HC595N
//http://roboindia.com/


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;  // 8 Bit Data to be sent through DataPin

void setup()
{
  pinMode(DataPin, OUTPUT);   // All 3 pins are output
  pinMode(ClockPin, OUTPUT);  
  pinMode(LatchPin, OUTPUT);
}


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

}

// 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 increament()   //LEDs increment start from 0 - 7 
{
  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 7
{
  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);
  }
}


5. output:

Here is the output of this tutorial-

6. Following Product of Robo India can be useful for this circuit:

If you use this LED array it will save jumpers and circuit will be hassle free.

If you have any query please write us at info@roboindia.com

Thanks and Regards
Content Development Team 
Robo India
http://roboindia.com

Leave a Reply