mdraber
Published © GPL3+

Shift Register Tutorial

A guide how to control 7 segment display with Shift register as well as daisy chain them to create multi digit displays

IntermediateFull instructions provided39
Shift Register Tutorial

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Shift Register- Parallel to Serial
Texas Instruments Shift Register- Parallel to Serial
×1
7 Segment LED Display, InfoVue
7 Segment LED Display, InfoVue
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

7 segment display connected to shift registor and arduino

Code

Conreol 7 segment display with Arduino and Shift Register to display digit sequence 0-9

Arduino
int DS1_pin = 4;
int STCP1_pin =3;
int SHCP1_pin = 2 ;

int digits [10][8]{
  {0,1,1,1,1,1,1,0}, // digit 0
  {0,0,1,1,0,0,0,0}, // digit 1
  {0,1,1,0,1,1,0,1}, // digit 2
  {0,1,1,1,1,0,0,1}, // digit 3
  {0,0,1,1,0,0,1,1}, // digit 4
  {0,1,0,1,1,0,1,1}, // digit 5
  {0,1,0,1,1,1,1,1}, // digit 6
  {0,1,1,1,0,0,0,0}, // digit 7
  {0,1,1,1,1,1,1,1}, // digit 8
  {0,1,1,1,1,0,1,1}  // digit 9
};


void display_digit(int d){
  if (digits[d][0]==1) digitalWrite(7, LOW); else digitalWrite(7, HIGH); //A
  if (digits[d][1]==1) digitalWrite(8, LOW); else digitalWrite(8, HIGH); //B
  if (digits[d][2]==1) digitalWrite(9, LOW); else digitalWrite(9, HIGH); //C
  if (digits[d][3]==1) digitalWrite(2, LOW); else digitalWrite(2, HIGH); //D
  if (digits[d][4]==1) digitalWrite(3, LOW); else digitalWrite(3, HIGH); //E
  if (digits[d][5]==1) digitalWrite(5, LOW); else digitalWrite(5, HIGH); //F
  if (digits[d][6]==1) digitalWrite(4, LOW); else digitalWrite(4, HIGH); //G
}

void DisplayDigit(int Digit)
{
    digitalWrite(STCP1_pin,LOW);
    for (int i = 7; i>=0; i--)
   {
    digitalWrite(SHCP1_pin,LOW);
    if (digits[Digit][i]==1) digitalWrite(DS1_pin, LOW); 
    if (digits[Digit][i]==0) digitalWrite(DS1_pin, HIGH);
    digitalWrite(SHCP1_pin,HIGH);
   }
   digitalWrite(STCP1_pin, HIGH); 
}


void setup() {  
  pinMode(DS1_pin, OUTPUT);
  pinMode(STCP1_pin, OUTPUT);
  pinMode(SHCP1_pin, OUTPUT);
}

void loop() {
for (int i=0;i<10;i++){  
  DisplayDigit(i);  
  delay(300);
}
} 

Control 7 display with Arduino and Shift Register-display digit sequence 0-9 using SHIFTOUT function

Arduino
int DS_pin = 4;
int STCP_pin =3;
int SHCP_pin = 2 ;

int dec_digits [10] {1,79,18,6,76,36,32,15,0,4};

void setup() {

  pinMode(DS_pin, OUTPUT);
  pinMode(STCP_pin, OUTPUT);
  pinMode(SHCP_pin, OUTPUT);
}


void loop() { 
 
for (int i=0;i<10;i++){
  digitalWrite(STCP_pin,LOW);
  shiftOut(DS_pin, SHCP_pin, LSBFIRST,dec_digits[i]);
  digitalWrite(STCP_pin, HIGH);
  delay(300);

}
} 

Connect two 7 segment displays to show count from 0 to 99

Arduino
Two shift registers are daisy chained . When one is overflown it pushes bits to teh other one
int DS_pin = 4;
int STCP_pin =3;
int SHCP_pin = 2 ;

int dec_digits [10] {1,79,18,6,76,36,32,15,0,4};


void setup() {

  pinMode(DS_pin, OUTPUT);
  pinMode(STCP_pin, OUTPUT);
  pinMode(SHCP_pin, OUTPUT);
}


void loop() { 

  
for (int j=0;j<10;j++){  
for (int i=0;i<10;i++){
  digitalWrite(STCP_pin,LOW);
  shiftOut(DS_pin, SHCP_pin, LSBFIRST,dec_digits[i]);
  shiftOut(DS_pin, SHCP_pin, LSBFIRST,dec_digits[j]);
  digitalWrite(STCP_pin, HIGH);
  delay(300);
}
}
} 

Credits

mdraber

mdraber

4 projects • 0 followers

Comments

Add projectSign up / Login