Search

Arduino and shift registers without shiftOut function

Please let us in the comment zone any suggestions that you think will improve the article!

If you like the article click the follow button  to stay in touch with us!

 

 

1.Introduction

Recently i’ve worked with a shift register and some leds. So, i’ve made a post with what i’ve learned.

The shift register is SN74HC595N, a device which has 8 outputs and a serial input (one wire). On the serial input the data are received in a “row”, bit after bit and in this way with this device we can control those 8 output independetly. With this shift register we can control big number of other electronic components or other devices with a smal number of pins from arduino (for example we have most of arduino pins ocuppied and we want to control 10 relays or the most common schematic for this device is in led array).

Before to work with this device you must know the difference between LSB(less significant bit) and MSB(most significant bit):

-the LSB is the right most bit, the one in position of the value 20   

  • 00000001-the LSB in this case is 1

-the MSB is the left most bit, the one in position of the value 27

  • 10000000- the MSB in this case is 1

We must know those things because the shift registers has eight output pins with some correlation(schematic below):

2.Schematic

shift register schematic

Let’s talk a little about those pins

  • VCC-power between 2 and 6 volts
  • GND-ground
  • QA-QH-outputs
  • QH’-a special output not used for LEDs(later in the post)
  • SER-serial input (on this pin come from arduino the states of outputs- in other datasheets you may found “DS”)
  • RCLK-storage register clock
  • SRCLK-shift register clock
  • OE-output enable with bar above (i don’t know how to put it there :))
  • SRCLR-direct overriding clear (same with the bar)

3.Functioning

As you guessed VCC from 5 volts to arduino and GND also to GND. The outputs for the first example i’ve mounted 8 led in series with 560 ohm resistor (see next schematic).

SER come to digital pin 8 on arduino (on this pin cames states of outputs), RCLK to digital pin 9, SRCLK to digital pin 10, OE to GND (if OE is connected to 5V all outputs are disabled) and SRCLR on 5V (if this pin is connected to GND the shift register is cleared).

shift register connections on arduino

OK, so, for functioning

-OE-to GND;

-SRCLR-to 5 volts;

The other three pins we must control in this way:

-When RCLK go from LOW to HIGH all outputs are enabled

-When SRCLK go from LOW to HIGH the state from SER pin is memorized

-On the SER pin came information

4. Examples

The best way to understand this is with an example:

Do you remeber MSB and LSB???

For shift register QA is MSB and QH is LSB.

When we wrote the information in device the information is from QH to QA, first state of SER correspond to QH and the seventh to QA.

The program below power on the led mounted on output QH:

const int SER=8;
const int RCLK=9;
const int SRCLK=10;

void setup() {
pinMode(SER, OUTPUT);
pinMode(RCLK, OUTPUT);
pinMode(SRCLK, OUTPUT);
}

void loop() {
digitalWrite(RCLK, LOW); //put the shift register in register mode

digitalWrite(SRCLK, LOW);//make the overriding clear low preparing to memorize the state
digitalWrite(SER, HIGH); //the state of the “H” output(high-LED is on)
digitalWrite(SRCLK, HIGH);// finish to memorize
digitalWrite(SRCLK, LOW);//repeat
digitalWrite(SER, LOW);//state low-LED off
digitalWrite(SRCLK, HIGH);
digitalWrite(SRCLK, LOW);
digitalWrite(SER, LOW);
digitalWrite(SRCLK, HIGH);
digitalWrite(SRCLK, LOW);
digitalWrite(SER, LOW);
digitalWrite(SRCLK, HIGH);
digitalWrite(SRCLK, LOW);
digitalWrite(SER, LOW);
digitalWrite(SRCLK, HIGH);
digitalWrite(SRCLK, LOW);
digitalWrite(SER, LOW);
digitalWrite(SRCLK, HIGH);
digitalWrite(SRCLK, LOW);
digitalWrite(SER, LOW);
digitalWrite(SRCLK, HIGH);
digitalWrite(SRCLK, LOW);
digitalWrite(SER, LOW);
digitalWrite(SRCLK, HIGH);

digitalWrite(RCLK, HIGH);//enable outputs
}

A picture of the result is:

shift register with h output active

As you guessed the left LED is from QH output and the right one is from QA output.

If we make the last SER high the QA output will be on :

const int SER=8;
const int RCLK=9;
const int SRCLK=10;

void setup() {
pinMode(SER, OUTPUT);
pinMode(RCLK, OUTPUT);
pinMode(SRCLK, OUTPUT);
}

void loop() {
digitalWrite(RCLK, LOW); //put the shift register in register mode

digitalWrite(SRCLK, LOW);//make the overriding clear low preparing to memorize the state
digitalWrite(SER, HIGH); //the state of the “H” output(high-LED is on)
digitalWrite(SRCLK, HIGH);// finish to memorize
digitalWrite(SRCLK, LOW);//repeat
digitalWrite(SER, LOW);//state low-LED off
digitalWrite(SRCLK, HIGH);
digitalWrite(SRCLK, LOW);
digitalWrite(SER, LOW);
digitalWrite(SRCLK, HIGH);
digitalWrite(SRCLK, LOW);
digitalWrite(SER, LOW);
digitalWrite(SRCLK, HIGH);
digitalWrite(SRCLK, LOW);
digitalWrite(SER, LOW);
digitalWrite(SRCLK, HIGH);
digitalWrite(SRCLK, LOW);
digitalWrite(SER, LOW);
digitalWrite(SRCLK, HIGH);
digitalWrite(SRCLK, LOW);
digitalWrite(SER, LOW);
digitalWrite(SRCLK, HIGH);
digitalWrite(SRCLK, LOW);
digitalWrite(SER, HIGH);
digitalWrite(SRCLK, HIGH);

digitalWrite(RCLK, HIGH);//enable outputs

}

shift register with a and h outputs active

 

Facebooktwitterpinterest

Related posts

Leave a Comment

Show Buttons
Hide Buttons