Blogroll

Powered by Blogger.

Thursday 10 April 2014

Arduino - ShiftOut, Extend Output Pins on Arduino With Shift Register 74HC595

by realfinetime  |  in ATmega328 at  11:00

Sometimes we will need more output pins than the output pins provided on the arduino board. In such situations we will use shift register ICs such as 74595. Pin diagram of 74595 is as shown in following figure.

By properly connecting one shift register IC to arduino, we can create eight digital outputs from three digital output pins of arduino. Circuit Diagram to create eight digital outputs from three digital output pins is as shown in the following figure.


Complete the above circuit and upload the following program.


//Pin connected to ST_CP of 74HC595
int latchPin = 12;
//Pin connected to SH_CP of 74HC595
int clockPin = 13;
////Pin connected to DS of 74HC595
int dataPin = 11;

void setup() 
{
    //set pins to output so you can control the shift register
    pinMode(latchPin, OUTPUT);
    pinMode(clockPin, OUTPUT);
    pinMode(dataPin, OUTPUT);
}

void loop() 
{
    // count from 0 to 255 and display the number 
    // on the LEDs
    for (int display_number = 0; display_number < 256; display_number++) 
   {
       // take the latchPin low so 
       // the LEDs don't change while you're sending in bits:
       digitalWrite(latchPin, LOW);
       // shift out the bits:
       shiftOut(dataPin, clockPin, MSBFIRST, display_number);  
       //take the latch pin high so the LEDs will light up:
       digitalWrite(latchPin, HIGH);
       // pause before next value:
       delay(500);
   }
}


Output of the above program will be as shown in figure given below.

                                                Q7     Q6     Q5    Q4     Q3    Q2     Q1    Q0


Now upload the following program.

//Pin connected to ST_CP of 74HC595
int latchPin = 12;
//Pin connected to SH_CP of 74HC595
int clockPin = 13;
////Pin connected to DS of 74HC595
int dataPin = 11;

void setup() 
{
    //set pins to output so you can control the shift register
    pinMode(latchPin, OUTPUT);
    pinMode(clockPin, OUTPUT);
    pinMode(dataPin, OUTPUT);
}

void loop() 
{
    // count from 0 to 255 and display the number 
    // on the LEDs
    for (int display_number = 0; display_number < 256; display_number++) 
   {
       // take the latchPin low so 
       // the LEDs don't change while you're sending in bits:
       digitalWrite(latchPin, LOW);
       // shift out the bits:
       shiftOut(dataPin, clockPin, LSBFIRST, display_number);  
       //take the latch pin high so the LEDs will light up:
       digitalWrite(latchPin, HIGH);
       // pause before next value:
       delay(500);
   }
}

Output of the above program will be as shown in figure given below.

                                                Q7     Q6     Q5    Q4     Q3    Q2     Q1    Q0

0 comments:

IMPORTANT NOTICE

All the circuits, published in this blog is only after testing and getting proper results in my private lab. When you try these circuits, you should check the supply voltage, polarity of components, presence of childrens nearby and shorts in the circuits. This website will not be responsible for any harm happened to you or your components caused by your carelessness.

For More Electronic Tips



Proudly Powered by Blogger.