0% found this document useful (0 votes)
67 views12 pages

Martin Experiment#8

The document describes an experiment using shift registers to display data on LEDs. It involves connecting an Arduino board and 74HC595 shift register to 8 LEDs. The shiftOut() function is used to sequentially display the bits from most to least significant on the LEDs. Subsequent parts of the experiment explore displaying in reverse order, controlling with the serial monitor, and using an array to determine the output pattern. The final part connects two shift registers to 16 LEDs to implement dual binary counters.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views12 pages

Martin Experiment#8

The document describes an experiment using shift registers to display data on LEDs. It involves connecting an Arduino board and 74HC595 shift register to 8 LEDs. The shiftOut() function is used to sequentially display the bits from most to least significant on the LEDs. Subsequent parts of the experiment explore displaying in reverse order, controlling with the serial monitor, and using an array to determine the output pattern. The final part connects two shift registers to 16 LEDs to implement dual binary counters.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

NCP 516 – EMBEDDED SYSTEMS LABORATORY

EXPERIMENT #8 – USING THE SHIFT REGISTER

LEARNING OUTCOMES:
After completing this experiment the students will be able to:
1. Demonstrate the use of the shift register in displaying series of data.
2. Implement the shiftOut() function in your codes.
3. Construct circuits that will be interfaced with the shift registers.

EXPERIMENT 8.A. “HELLO WORLD”


COMPONENTS:
1. 1 x Arduino Board
2. 1 x 74HC595 Shift Register
3. 1 x 1µF Capacitor
4. 8 x LED’s
5. 8 x 220Ω Resistors
6. 1 x breadboard

CIRCUIT & SCHEMATIC DIAGRAM:

Figure 1. Circuit diagram of Experiment 8.A. Figure 2: Schematic diagram of Experiment 8.A.

PROCEDURE
1. Connect your circuit as shown in the circuit and schematic diagram.
2. Plug your Arduino board to your computer and start the Arduino program.
3. Choose the Arduino board that you are you using in the Tools > Boards menu, then choose
the COM port you are using in the Tools > Serial Port menu.
4. Encode and verify the program below, if no errors occurred download the program into
your Arduino board.

*Image and other sources are taken from arduino.cc

1|Page
NCP 516 – EMBEDDED SYSTEMS LABORATORY

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

void setup() {
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}

void loop() {
for (int numberToDisplay = 0; numberToDisplay < 256; numberToDisplay++) {
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay);
digitalWrite(latchPin, HIGH);
delay(100);
}
}

Result:

Observation:
The following experiment demonstrates how a shift register is incorporated in an Arduino project
as well as how to use shift registers. A shift register is a synchronous device that relies on the clock
signal to output desired values. It is mainly controlled by the shiftOut() function wherein its
parameters are defined by the user, as it includes the data pin, clock pin, bit order, and the value to
shift out or to display. In this experiment, we shiftOut() values from the MSB or most significant
bit first in a for loop. It outputs a sequential display of LED showing the MSB first to the LSB.

*Image and other sources are taken from arduino.cc

2|Page
NCP 516 – EMBEDDED SYSTEMS LABORATORY

EXPERIMENT 8.B. “HELLO WORLD AGAIN”


COMPONENTS:
1. 1 x Arduino Board
2. 1 x 74HC595 Shift Register
3. 1 x 1µF Capacitor
4. 8 x LED’s
5. 8 x 220Ω Resistors
6. 1 x breadboard

CIRCUIT & SCHEMATIC DIAGRAM:

Figure 3. Circuit diagram of Experiment 8.B. Figure 4: Schematic diagram of Experiment 8.B.

PROCEDURE
1. Connect your circuit as shown in the circuit and schematic diagram.
2. Plug your Arduino board to your computer and start the Arduino program.
3. Choose the Arduino board that you are you using in the Tools > Boards menu, then choose
the COM port you are using in the Tools > Serial Port menu.
4. Encode and verify the program below, if no errors occurred download the program into
your Arduino board.

CODE:
int latchPin = 8;
int clockPin = 12;
int dataPin = 11;

void setup() {
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}

void loop() {

*Image and other sources are taken from arduino.cc

3|Page
NCP 516 – EMBEDDED SYSTEMS LABORATORY

for (int j = 0; j < 256; j++) {


digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, j);
digitalWrite(latchPin, HIGH);
delay(1000);
}
}
Result:

Observation:
The following experiment uses the same circuit diagram and setup that the last experiment used.
It contains a shift register that consists of 8 LEDs for the bit display of the shiftOut() function.
The difference in this experiment compared to the last is the manner of displaying the bits. In this
experiment, the bits are displayed in lowest significant bit first rather than most significant bit
first where we can observe that the display was reversed causing the last LED to light up first
rather than the first LED in MSB First.

EXPERIMENT 8.C. One by One


COMPONENTS:
1. 1 x Arduino Board
2. 1 x 74HC595 Shift Register
3. 1 x 1µF Capacitor
4. 8 x LED’s
5. 8 x 220Ω Resistors
6. 1 x breadboard

*Image and other sources are taken from arduino.cc

4|Page
NCP 516 – EMBEDDED SYSTEMS LABORATORY

CIRCUIT & SCHEMATIC DIAGRAM:

Figure 5. Circuit diagram of Experiment 8.C. Figure 6: Schematic diagram of Experiment 8.C.

PROCEDURE
1. Connect your circuit as shown in the circuit and schematic diagram.
2. Plug your Arduino board to your computer and start the Arduino program.
3. Choose the Arduino board that you are you using in the Tools > Boards menu, then choose
the COM port you are using in the Tools > Serial Port menu.
4. Encode and verify the program below, if no errors occurred download the program into
your Arduino board.

CODE:
const int latchPin = 8;
const int clockPin = 12;
const int dataPin = 11;

void setup() {
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
Serial.begin(9600);
Serial.println("reset");
}

void loop() {
if (Serial.available() > 0) {
int bitsToSend = Serial.read() - 48;
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend);
digitalWrite(latchPin, HIGH);
}
}

Result:

*Image and other sources are taken from arduino.cc

5|Page
NCP 516 – EMBEDDED SYSTEMS LABORATORY

Observation:
The following experiment also uses the same setup from the prior experiments wherein it is
composed of a shift register and 8 LEDs to display the bit order. The following experiment utilizes
the serial monitor of the Arduino board to control the output of the circuit. The prior circuits and
experiments used a looping technique to output every possible display from the most significant
bit or the least significant bit, however in this experiment the output is not controlled by a looping
statement, rather it is controlled by the serial monitor and thus, by the user. The user inputs an
integer to the serial monitor which will be read by the function Serial.read() function for the input.
The input is then passed to the shiftOut() function for the display of the bit input.

EXPERIMENT 8.D. Using an array


COMPONENTS:
1. 1 x Arduino Board
2. 1 x 74HC595 Shift Register
3. 1 x 1µF Capacitor
4. 8 x LED’s
5. 8 x 220Ω Resistors
6. 1 x breadboard

CIRCUIT & SCHEMATIC DIAGRAM:

*Image and other content are taken from arduino.cc

6|Page
NCP 516 – EMBEDDED SYSTEMS LABORATORY

Figure 7. Circuit diagram of Experiment 8.D. Figure 8: Schematic diagram of Experiment 8.D.

PROCEDURE
1. Connect your circuit as shown in the circuit and schematic diagram.
2. Plug your Arduino board to your computer and start the Arduino program.
3. Choose the Arduino board that you are you using in the Tools > Boards menu, then choose
the COM port you are using in the Tools > Serial Port menu.
4. Encode and verify the program below, if no errors occurred download the program into
your Arduino board.

CODE:
int latchPin = 8;
int clockPin = 12;
int dataPin = 11;
int dataArray[10] = {0xFF, 0xFE, 0xFC, 0xF8, 0xF0, 0xE0, 0xC0, 0x80, 0x00,
0xE0};

void setup() {
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}

void loop() {
for (int j = 0; j < 10; j++) {
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, dataArray[j]);
digitalWrite(latchPin, HIGH);
delay(300);
}
}

Result:

*Image and other content are taken from arduino.cc

7|Page
NCP 516 – EMBEDDED SYSTEMS LABORATORY

Observation:
The following experiment performs in the same manner as the prior experiments; however, it uses
a specific array to display each bit contained in the predefined array. The following experiment
uses a for loop condition together with an array to shiftOut() the bit or the data that is declared
within the array. This results in the display of each bit from the array starting with the most
significant bit.

EXPERIMENT 8.E. Dual Binary Counters


COMPONENTS:
1. 1 x Arduino Board
2. 2 x 74HC595 Shift Register
3. 1 x 1µF Capacitor
4. 16 x LED’s
5. 16 x 220Ω Resistors
6. 1 x breadboard

CIRCUIT & SCHEMATIC DIAGRAM:

*Image and other content are taken from arduino.cc

8|Page
NCP 516 – EMBEDDED SYSTEMS LABORATORY

Figure 9. Circuit diagram of Experiment 8.E. Figure 10: Schematic diagram of Experiment 8.E.

PROCEDURE
1. Connect your circuit as shown in the circuit and schematic diagram.
2. Plug your Arduino board to your computer and start the Arduino program.
3. Choose the Arduino board that you are you using in the Tools > Boards menu, then choose
the COM port you are using in the Tools > Serial Port menu.
4. Encode and verify the program below, if no errors occurred download the program into
your Arduino board.

CODE:
int latchPin = 8;
int clockPin = 12;
int dataPin = 11;

void setup() {
Serial.begin(9600);
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}

void loop() {
for (int j = 0; j < 256; j++) {
digitalWrite(latchPin, 0);
shiftOut(dataPin, clockPin, MSBFIRST, j);
shiftOut(dataPin, clockPin, MSBFIRST, 255-j);
digitalWrite(latchPin, 1);
delay(1000);
}
}

*Image and other content are taken from arduino.cc

9|Page
NCP 516 – EMBEDDED SYSTEMS LABORATORY

Result:

Observation:
The following experiment is different from the prior experiments in terms of the circuit diagram
wherein it consists of two shift registers and 16 LEDs to display two instances of the binary
counter. The second circuit design of the shift register is connected to the prior shift register in
terms of the clock and the data pin. This resulted in two binary counters wherein it is executed in
a both MSB first, however the display of the LEDs HIGH and LOW state are reversed for each
instance. This is because of the wiring diagram which required that the data pin of the second shift
register is to be connected to the inverted output of the first shift register, which results in the
inversion the HIGH and LOW state of the first shift register onto the second shift register.

EXPERIMENT 8.F. Dual One by One


COMPONENTS:
1. 1 x Arduino Board
2. 2 x 74HC595 Shift Register
3. 1 x 1µF Capacitor
4. 16 x LED’s
5. 16 x 220Ω Resistors
6. 1 x breadboard

*Image and other content are taken from arduino.cc

10 | P a g e
NCP 516 – EMBEDDED SYSTEMS LABORATORY

CIRCUIT & SCHEMATIC DIAGRAM:

Figure 11. Circuit diagram of Experiment 8.F. Figure 12: Schematic diagram of Experiment 8.F.

PROCEDURE
1. Connect your circuit as shown in the circuit and schematic diagram.
2. Plug your Arduino board to your computer and start the Arduino program.
3. Choose the Arduino board that you are you using in the Tools > Boards menu, then choose
the COM port you are using in the Tools > Serial Port menu.
4. Encode and verify the program below, if no errors occurred download the program into
your Arduino board.

CODE:
int latchPin = 8;
int clockPin = 12;
int dataPin = 11;

void setup() {
Serial.begin(9600);
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}

void loop() {
for (int j = 0; j < 8; j++) {
digitalWrite(latchPin, 0);
shiftOut(dataPin, clockPin, MSBFIRST, j);
shiftOut(dataPin, clockPin, MSBFIRST, 7-j);
digitalWrite(latchPin, 1);
delay(1000);
}
}

*Image and other content are taken from arduino.cc

11 | P a g e
NCP 516 – EMBEDDED SYSTEMS LABORATORY

Result:

Observation:
The last experiment uses the same experimental setup that the dual binary counter used wherein
its code is modified to perform a one-by-one bit output. However, the following experiment did
not utilize the serial monitor of the Arduino board unlike the single one-by-one, but instead used
a for loop to display up to the desired bits. The following experiment showed that each bit can be
controlled for display using the following bit order and bit value once defined. The following shift
registers still vary in output since the following display are inverted for the latter. It can be observed
that there is limited display due to the small integer declaration from the for loop conditional
statement.

*Image and other content are taken from arduino.cc

12 | P a g e

You might also like