Shift The Graph

February 19th, 2012

I have started working with an Arduino. For someone getting started in electronics, this device, and the community around it make it so much easier to learn. Within two minutes of plugging it in and starting the software, I was able to do something.

Fast forward a bit, this project is the first big project I have taken on. It is a 10 segment bar graph that I wired up, but now, I am moving it’s control from the 10 analog pins to some shift registers. This frees up most of the pins that I needed initially, and doesn’t make control more difficult.

A shift register is like a bucket brigade. Each bucket is one bit on the register, and as you pass it bits, the rest of them get passed one down the line. So, to control which legs of the shift register are powered and which not, I just have to pulse 1’s and 0’s into the register until I get it set the way I want. Since the LED segments are controlled by the shift register legs, they’re set by what is pulsed to the register.

If I want to have an alternating pattern, the registers contain these values
[code] [10101010] -> [10101010]
// Register 1 -> Register 2[/code]

If I were to push one more bit down the line, they would all move one step along.
[code] [01010101] -> [01010101]
// Register 1 -> Register 2[/code]

If I wanted to push the segments to all lit, the register just has to be fed 1’s.
[code] [11111111] -> [11010101]
// Register 1 -> Register 2[/code]

Part List

  • Arduino
  • 10 x 330Ω Resistors
  • 10 Segment LED bar graph or 10 x LED’s
  • 2 x 74LS164N Shift Registers (or any non-164 shift register, your wiring may be different)
  • Wires and Breadboards


  • For this project, I’m not using the reset ability of the 164, so that pin has been tied to V+.
  • There is an Arduino function called shiftOut() that would make this a little easier. I have not used it because I wanted to shift the bits myself to get a better feel for what it was doing.
  • To wire the shift registers to the Arduino, it’s pin 2 on the Arduino to the clock pin (pin 8) on the first or second shift register (since they’re both wired together), and pin 3 Arduino to data pin (pin 1) on the first shift register.

#define DATA 3
#define CLOCK 2

void setup() {
pinMode(DATA, OUTPUT);

for(int i = 0; i < 10; ++i){
digitalWrite(DATA, LOW);
digitalWrite(CLOCK, HIGH);
digitalWrite(CLOCK, LOW);

void loop() {
for(int i = 0; i < 10; ++i){
int hilo = random(0, 2);

case 0: digitalWrite(DATA, LOW); break;
case 1: digitalWrite(DATA, HIGH); break;

digitalWrite(CLOCK, HIGH);
digitalWrite(CLOCK, LOW);

WordPress - Entries (RSS) and Comments (RSS) - © 2011 Ben Dauphinee