Ardumotive Arduino Greek Playground
  • Home
    • About us
    • Contact
    • License
  • Arduino
    • Tutorials
    • Workshop
  • Raspberry Pi
  • DIY 3D Printer
  • News
    • Events >
      • Unboxing & Review
    • Blog
The 1st Arduino Playground in Greece - Open Source Hardware

Shift Register

Available Languages
Greek
English
*Σύντομα και στα Ελληνικά

Introduction 

Picture
In this tutorial you will learn how to use a shift register (or serial to paralled controller). The shift register will give to your Arduino an additional 8 digital outputs, by using only 3 pins on your board
In this tutorial you will practice by using the shift register with Arduino uno to control 8 LEDs.

What you will need - Hardware

For this tutorial you will need:
  • Arduino uno
  • Breadboard
  • Shift Register IC (74HC595)
  • 4x Red LEDs
  • 4x Green LEDs
  • 8x 330 Ohm (or 220) resistors
Picture

The Circuit

Picture
Picture
The connections are easy, see the image above with the breadboard circuit schematic.


You can find more info about IC here: datasheet

The code

Picture
We will use example sketch from ShiftRegister74HC595.h library.
How it works:
  • sr.setAllHight(); Turn all LEDs on
  • sr.setAllLow(); Turn all LEDs off
  • sr.set(i, HIGH); Turn LED i on ( 0 < i < 7)
  • uint8_t pinValues[] = { B10101010 }; 
  • sr.setAll(pinValues); Binary to turn on 2nd,4th,6th and 8th LED
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
  ShiftRegister74HC595.h - Library for easy control of the 74HC595 shift register.
  Created by Timo Denk (www.simsso.de), Nov 2014.
  Additional information are available on http://shiftregister.simsso.de/
  Released into the public domain.
*/

#include <ShiftRegister74HC595.h>
// create shift register object (number of shift registers, data pin, clock pin, latch pin)
ShiftRegister74HC595 sr (1, 2, 3, 4); 
void setup() { 
}

void loop() {
  sr.setAllHigh(); // set all pins HIGH
  delay(500);
  sr.setAllLow(); // set all pins LOW
  delay(500); 
  for (int i = 0; i < 8; i++) {
    sr.set(i, HIGH); // set single pin HIGH
    delay(2000); 
  }
  // set all pins at once
  uint8_t pinValues[] = { B10101010 }; 
  sr.setAll(pinValues); 
  delay(5000);
  // read pin (zero based)
  uint8_t stateOfPin5 = sr.get(5);
}
Download the code from here and open it with Arduino IDE. Inside you will also find additional libraries.
shiftregister595_tutorial.zip
File Size: 2 kb
File Type: zip
Download File

You can make your own modifications to the code, for example, try to change line: uint8_t pinValues[] = { B10101010 }; with uint8_t pinValues[] = { B11001100 };

Well done!

Picture
You have successfully completed one more "How to" tutorial and you learned how to use a shift register ic with Arduino. I hope you liked this, let me know in the comments. You can also post photos with your circuit!

Picture

Search Engine

Picture

Licence 

Picture

Help us to grow up!

Picture


Donate us
About us
License
Cookies policy

Visit the biggest Arduino Shop in Greece!

Picture
find us on dwrean.net
find us on Codebender
find us on Instructables
Developed and designed by Vasilakis Michalis Copyright © 2013 Ardumotive All Rights Reserved
All trademarks referenced herein are properties of their
Powered by Create your own unique website with customizable templates.
Design by DivTag Templates