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.
0 comments: