How to use shift register in 8 LEDs in Arduino

in #utopian-io8 years ago (edited)

Today i will going share how to use shift register on 8 leds in arduino, as you see it on the picture below.
20180106_201942.jpg

In this post focuses on the 74HC595N shift register which is the little microchip shown below. so what is shift register? Let us suppose we are doing a project that needs to update three, 7-segment LEDs. Each 7-segment LED requires 7 pins from your Arduino. That means you’ll need 21 pins from your Arduino to drive all 3 LEDs, the problem is arduino don’t have 21 output pins to support the project, so how can we do this lets try a 8 LEDs using a shift register and lets find out.. to find more info about about shift register click this link


20180106_205007.jpg

In this tutorial we need these couple of components:

20180106_200307.jpg

  • Arduino Board
  • Lots of jumper wires
  • 8 Leds
  • 8 resistors
  • Breadboard
  • 74HC595N shift register
  • HARDWARE

    First i placed the shift register on the breadboard and the 8 LEDs the postive leg of the leds to the vertical rail and the negative to the horizontal rail of the board.
    20180106_200557.jpg

    Place the resistors on the positive leg of the LEDs.
    20180106_200811.jpg

    SHIFT REGISTER SCHEMATIC

    A shift register has two 8-bit registers. The first register is called the “stage” register and is where the last byte is sitting that you wrote to it. The second 8-bit register is for storage and you tell the shift register microchip to transfer the “stage” shift register to the “storage” shift register. The “storage” register is mapped to the output PINs Q0 through Q7.

    Lets start wiring with the left outputs first.

    20180106_201257.jpg

  • Q1 – (+) side of LED 2
  • Q2 – (+) side of LED 3
  • Q3 – (+) side of LED 4
  • Q4 – (+) side of LED 5
  • Q5 – (+) side of LED 6
  • Q6 – (+) side of LED 7
  • Q7 – (+) side of LED 8
  • GND – to ground
  • Vcc – to power (+)
  • Q0 – (+) side of LED 1
  • DS – to Arduino PIN 4
  • OE – to ground
  • STCP – to Arduino PIN 5 – this is the latch pin.  You start by writing a LOW value to this pin, then write the byte to DS then raise the STCP to HIGH
  • SHCP – to Arduino PIN 6 –  this is the clock pin and is how the Arduino and the Shift register agree on a clock
  • MR – to power (+)
  • Q7S – NOT USED YET – this is the piggy back PIN.  If you connect this pin to another shift register DS pin then the bits will go to the next shift shift instead of going into the bit bucket.
  • SOFTWARE

    Before we work on our sketch, make sure to download the Arduino IDE for your specific operating system. I’ll leave a link to where you can download this software: https://www.arduino.cc/en/Main/Software


    seq1.png

    Arduino Sketch Using One Shift Register and 8 LEDs
    serrrrrr.png

    copy the code here:

    const int DATAPIN1 = 4;   // DS
    const int LATCHPIN1 = 5;  // STCP
    const int CLOCKPIN1 = 6;  // SHCP
    int ledValue = 1;
    void setup() {  
      pinMode(DATAPIN1, OUTPUT);
      pinMode(LATCHPIN1, OUTPUT);
      pinMode(CLOCKPIN1, OUTPUT);  
    }
    void loop() {
     
      digitalWrite(LATCHPIN1, LOW);

      shiftOut(DATAPIN1, CLOCKPIN1, MSBFIRST, ledValue);    
      digitalWrite(LATCHPIN1, HIGH);

      ledValue = ledValue * 2;
      if (ledValue > 128) {
        ledValue = 1;
      }
      delay(500);
    Click verify/compile then upload it to the arduino board, the LEDs should start the sequential control.

    20180106_195701.jpg

    the Shift registers provide a way to save output pins. They are pretty simple to use and cheap, the source of the code is came from GITHUB and here is the result of my work.
    20180106_195824.gif

    thank you for stopping by, if you like it please upvote and follow me @pakganern
    20180105_182452[1].jpg



    Posted on Utopian.io - Rewarding Open Source Contributors

    Sort:  

    Thank you for the contribution. It has been approved.

    You can contact us on Discord.
    [utopian-moderator]

    what a nice flashback of my university days. there's so much we can do with arduino indeed. our project back then was a mobot to follow a path. well it's really nice to have read this. cheers!

    Hey @pakganern I am @utopian-io. I have just upvoted you!

    Achievements

    • This is your first accepted contribution here in Utopian. Welcome!

    Suggestions

    • Contribute more often to get higher and higher rewards. I wish to see you often!
    • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

    Get Noticed!

    • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

    Community-Driven Witness!

    I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

    mooncryption-utopian-witness-gif

    Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

    Coin Marketplace

    STEEM 0.13
    TRX 0.34
    JST 0.036
    BTC 109587.97
    ETH 4474.98
    USDT 1.00
    SBD 0.84