Shift Registers Arduino Tutorial

Using shift registers with your next Arduino project will allow you to drive multiple outputs with less pins. The 74HC595 IC is extremely versatile; it can be used to drive LEDs, motors and even Servos.

Bron : http://staticjolt.com/shift-registers-arduino-tutorial/
Bron : https://www.youtube.com/watch?v=bqfPZXEuyuc
Bron : http://www.nxp.com/documents/data_sheet/74HC_HCT595.pdf
Bron : http://bildr.org/2011/02/74HC595/

 

SHIFTING EIGHT OUTPUTS

You will need to make the connections described below. You may use different loads than the LEDs displayed and other outputs on the Arduino board. Make sure to change the configuration in the software if you decide to do so.

The code to start shifting!

The software is quite simple. You will need to create a register of 8 bits and shift it in when you want to update the actual register. The sample code blow illustrates a simple example which you can copy and paste into your project.

 

--CODE--

///////////////////////////////////
int DS_pin = 8;
int STCP_pin = 9;
int SHCP_pin = 10;

void setup()
{
pinMode(DS_pin,OUTPUT);
pinMode(STCP_pin,OUTPUT);
pinMode(SHCP_pin,OUTPUT);
writereg();
}

boolean registers[8];

void writereg()
{
digitalWrite(STCP_pin, LOW);
for (int i = 7; i>=0; i--)
{
digitalWrite(SHCP_pin, LOW);
digitalWrite(DS_pin, registers[i] );
digitalWrite(SHCP_pin, HIGH);
}
digitalWrite(STCP_pin, HIGH);
}

void loop()
{
for(int i = 0; i<8; i++) { registers[i] = HIGH; delay(100); writereg(); } for(int i = 7; i>0; i--)
{
registers[i] = LOW;
delay(100);
writereg();
}
}
///////////////////////////////////

--CODE--

Multiple Shift Registers from three pins

It is possible to chain shift registers in order to use any multiple of outputs with the same three pins. You simply need to connect the output of the first shift register to the input of the next one and make sure the clock signals are also sent along. Here is the schematic you can use as an example as well as the small code modifications you will need to run two shift registers at once.

The following code is used for two shift registers or a total of 16 outputs.

--CODE--

///////////////////////////////////
int DS_pin = 8;
int STCP_pin = 9;
int SHCP_pin = 10;

void setup()
{
pinMode(DS_pin,OUTPUT);
pinMode(STCP_pin,OUTPUT);
pinMode(SHCP_pin,OUTPUT);
writereg();
}

boolean registers[16];

void writereg()
{
digitalWrite(STCP_pin, LOW);
for (int i = 15; i>=0; i--)
{
digitalWrite(SHCP_pin, LOW);
digitalWrite(DS_pin, registers[i] );
digitalWrite(SHCP_pin, HIGH);
}
digitalWrite(STCP_pin, HIGH);
}

void loop()
{
for(int i = 0; i<16; i++) { registers[i] = HIGH; delay(100); writereg(); } for(int i = 15; i>0; i--)
{
registers[i] = LOW;
delay(100);
writereg();
}
}
///////////////////////////////////

--CODE--

 

Shifting Forward!

If you are able to use two shift registers, you will be able to chain 3, 4 or 10 of them. Make sure to always verify the maximum current you can supply; this may impact your circuits performance or even damage your Arduino board.