Spring Sale: 5% OFF Over $89, Code: Elephant5; 10% OFF Over $149, Code:Elephant10



Arduino Project 22: Counting Your Number

Posted by Fiona Su on

thumb

Introduction:
The shift register operates in a fairly simple way, but can be modified to become very complicated but very useful.
We can control the shift of the register with clock pulses. As we raise the signal going to the clock pin to high, the clock is moved forward one step, and when we pull it low and high again it shifts another. Each time we shift the clock we switch the input to a different one of the eight registers. We are essentially controlling the output of each of the eight pins one at a time, and as we move one clock signal forward, we switch to the next output pin to control.
The shift register can be a great tool when you are short on output pins, taking 8 outputs from only about 3 actual data inputs. It can be added to for some really complicated applications, and they can be daisy-chained together for even more output options.
In this project, we only use three I\O ports to control a, b, c, d, e, f, g and dp, therefor to control the segment display.

Below is the pin diagram for 1-digit 7-seg LED segment display:

thumb

Hardware Required:

  • Arduino Board *1
  • USB Cable *1
  • 74HC595 IC *1
  • 1-digit 7-seg LED *1
  • 220Ω Resistor *8
  • Breadboard*1
  • Breadboard Jumper Wires

Connection for REV4:

thumb 

Connection for Arduino Mega 2560 R3:

thumb

Sample Code:

int latchPin = 4;
int clockPin = 5;
int dataPin = 2; //define three pins
void setup ()
{
  pinMode(latchPin,OUTPUT);
  pinMode(clockPin,OUTPUT);
  pinMode(dataPin,OUTPUT); //three pins as output
}
void loop()
{

  int a[10]={
    252,96,218,242,102,182,190,224,254,246};   //define functional array
  for(int x=0; x<10 ;x++ )                        //calculate counting function
  {
    digitalWrite(latchPin,LOW);
    shiftOut(dataPin,clockPin,MSBFIRST,a[x]);     //display array a[x]
    digitalWrite(latchPin,HIGH);
    delay(1000);
  }
}

 

Result:
After connection and uploading codes, you can count the numbers on segment display from 0 to 9.

thumb

 

 

 

 

0 comments

Leave a comment

Please note, comments must be approved before they are published