• +965 51122049

ARDUINO LESSON 3: 74HC595 SHIFT REGISTER USAGE

ARDUINO LESSON 3: 74HC595 SHIFT REGISTER USAGE

Hello Engineers. 

In today's lesson we will learn to burn 8 LEDs with fewer pins by using Arduino and 74HC595 shift register integration. 

Our required materials: 

  1. Arduino UNO 
  2. Breadboard 
  3. 74HC595 shift register integration 
  4. 8 LEDs 
  5. 8 pieces 220 Ω 
  6. Two male jumper cables 

 

As we all know, there are 13 digital input / output pins on our Arduino UNO card. But we may not want to use all of these pins for LED driving. Other than the Yada LED, other pins can be connected to other inputs such as sensor, switch, button etc. The method we use here will allow us to control 8 LEDs using only 3 digital output pins in the Arduino. 

74HC595 Shift Register Integration 

The shift register circuit consists of memory element circuits called successive flip-flops.They may be functions that convert parallel input to serial output (PISO), or convert it to serial in parallel output (SIPO), such as 74HC595, which we use in our project. 

The integrated unit we use is equipped with three bass latches: Serial data input (DS, pin 14), latch (ST_CP, pin 12) and clock pin (SH_CP, pin 11).The shift register operates as follows: if data input is desired, the latch pin is pulled to logic 0 level, data is input (logic 1 or 0) and the clock pulse is applied to the clock pin.In this way, 8 bits of data are input from a single serial input pin, and the data input serially in the result is taken from the parallel outputs (pins Q0 to Q7). 

 

If the logic of the shift register is complicated to you, there is no need to worry.The shiftOut function found in the Arduino software assumes all of these operations and allows you to only define the pins you use in the connection. 

We integrate our LEDs and Arduino in the following way: 

 

Our code looks like this: 

  Int latchPin = 5;
	
	
 Int clockPin = 6;
	
	
 Int dataPin = 4;
	
	
 Byte leds = 0;
	
	
 
 Void setup ()
	
	 
 {
	
	
   PinMode (latchPin, OUTPUT);
	
	
   PinMode (dataPin, OUTPUT);
	
	  
   PinMode (clockPin, OUTPUT);
	
	
 }
	
	
 
 Void loop ()
	
	 
 {
	
	
   Leds = 0;
	
	
   RegisteraYaz ();
	
	
   Delay (500);
	
	
   For (int i = 0; i <8; i ++)
	
	
   {
	
	
     BitSet (leds, i);
	
	
     RegisteraYaz ();
	
	
     Delay (500);
	
	
   }
	
	
   For (int i = 8; i> = 0; i--)
	
	
 {
	
	
     BitClear (leds, i);
	
	
     RegisteraYaz ();
	
	
     Delay (500);
	
	
   }
	
	
 }
	
	
 Void registerAYaz ()
	
	
 {
	
	
    DigitalWrite (latchPin, LOW);
	
	
    ShiftOut (dataPin, clockPin, LSBFIRST, leds);
	
	
    DigitalWrite (latchPin, HIGH);
	
	
 }
	
	

	
	

In the first part of our code, we have defined output pins as we always do.We have defined an 8-bit variable named leds (the variables in the byte type are 8 bits in size).Each bit of this byte represents the LEDs connected to the output of our shift register.We are registeraYaz function, we are doing necessary operations for shift register.In our loop function we call this function to transfer the changes we made in the LEDs variable to our LEDs.In our loop function, we used two for loops.In the first for loop, the LEDs will make each of the 8 bits in our variable 1 in order to get a pattern of 00000001, 00000011, 00000111 ....After each bit is 1 (11111111), starting with the second for loop this time, it will generate bits 01111111, 00111111, 00011111 ... 

You can try not to use the for loop but to make dark flashes, for example, in the order of LEDs = B00000001, leds = B00000010, leds = B00000100.Remember to call the registerAyaz function after every command. 

 

EVA Electronics Co. Wish You All The Success



Related posts
ARDUINO LESSON 6: DC MOTOR SPEED ​​CONTROL

ARDUINO LESSON 6: DC MOTOR SPEED ​​CONTROL

  • Jan 12, 2023
  • 1,573 Views

In this application, we will check the DC motor speed using a BJT type transistor. Why do we need a transistor...

ARDUINO LESSON 5: TEMPERATURE MEASUREMENT

ARDUINO LESSON 5: TEMPERATURE MEASUREMENT

  • Jan 12, 2023
  • 1,281 Views

The LM35 temperature sensor is an analogue output temperature sensor that performs precise temperature measure...