Using Shift Register with Arduino

Hello today we will examine driving LED using Bit-Shifting, shift register method, contrary to what is custom in this project, instead of the 74HC595 integration, hef4094 integrated, but you can also use the 74HC595 integration with the same code and diagram, paying attention to the output and input pins. Even though I saw that the LEDs and 7-Segment LEDs in my workshop were finished, I tried to do it with the diodes I had left, besides, we made examples with a gas sensor and a 7-segment 4 digit display in our previous articles, you can find it here. I'm going to write before we go any further.

What is Shift Register?

It is a form of circuit design that is often used in the field of logic circuits. The aim of the design, which benefits from flip-flops as an infrastructure, is to slide the bits on the diary base one-on-one with each hour pulse. It is also used as recorders because they temporarily save data. The purpose of use in LED circuits is to save on the I/O pins of the microprocessor, for example; In a circuit of 8 LEDs, without the Shift Register circuit, the number of I/O pins used is 10, including GND and VCC, but with the Shift Register circuit 3 + GND and VCC are used, we can say that it makes quite sense to use Shift Register based on this result.

HEF4094 Integration

HEF4094 is a serial shift register with 3 pin input and 8-bit pin output, it can trade in the range of 3V and 15V in voltage.

Shift

Shift Register Operating Logic

Although not much different from the 74HC595, as mentioned earlier, the HEF4094 integration is a shift register integration with 8-bit serial output controlled by 3 inputs. The 3 entries mentioned here are:

  • Serial Data Entry
  • Clock Input
  • Latch Input

The working logic is quite simple. First of all, we make the latch entry "0". This makes the system ready to read data. We give the data pin the value we want to be stored. When we send a clock pulse to the Clock pin, this data is written to the smallest bit. Next to the typing process, the remaining bits are deleted while the larger pine is scrolled. When 8 clock pulses are performed, the old 8-bit values are left, while the newly issued 8-bit data is stored. Then, when we make the latch pin "1", this 8-bit value is given to the output. With this animation, the basics of the shift-register method will be established.

Shift

Using Shift Register with Arduino

Arduino's own library contains the code "shiftOut" for Shift-Register integrations. But to understand the operating logic, let's first look at how to check without using this code. I used a regular LED but you can also use it with 1 digit 7 segment.

Shift

Arduino Code

int latchPin = 8;
int clockPin = 12;
int dataPin = 11;
byte led = 0;
void setup() {
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
}
void loop()
{
  led = 0;
  register_et();
  delay(200);
  for (int i = 0; i < 8; i++)
  {
    bitSet(led, i);
    register_et();
    delay(200);
  }
  for (int i = 8; i > = 0; i--)
  {
    bitClear(led, i);
    register_et();
    delay(200);
  }
}
void register_et()
{
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, LSBFIRST, led);
  digitalWrite(latchPin, HIGH);
}

Code Description

In the first part of our code, we defined our output pins, as we always do. We defined an 8-bit variable with leds name (variables of type byte are 8 bits in size). Each bit of this byte represents leDs that depend on the output of our shift register. Our register_eT function performs the necessary operations for shift register to work. by calling this function in our loop function, we call this function to transfer the changes we have made to the LED variable to our LEDs. In our loop function, we used two for loops. The first for cycle 00000001, 00000011, 00000111 each of the 8 bits in our LEDS variable by making it 1 in turn… it will allow us to obtain a pattern in the form of. After each bit is 1 (11111111), starting the second for cycle, this time by 0 to 01111111 the bits, 001111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 pattern.

Diagram for 7-Segment 1 Digit

Shift Shift