Arduino UNO 7 Segment Display using a register shifter

Description of the Arduino 7-Segment Display Code with Shift Register

This Arduino code is designed to control two 7-segment displays using a shift register. The code defines three pins for communication with the shift register: dataPin (A5), clockPin (A4), and resetPin (A3). The numbers array contains the byte representations of the digits 0 through 9, which are used to display the corresponding numbers on the 7-segment displays.

In the setup() function, the data, clock, and reset pins are configured as outputs. The loop() function iterates through the numbers 0 to 9, displaying each number on the first 7-segment display while simultaneously showing the next number on the second display. The displayNumber() function handles the reset of the shift register and sends the appropriate data to each display. The shiftOut() function is responsible for shifting out the data bits to the shift register, controlling the segments that light up for each digit.

This project is a great introduction to shift registers and 7-segment display interfacing with Arduino, allowing beginners to learn about digital output control and data handling in electronics.



SCHEMATIC:

CODE:

// Define pins
const int dataPin = A5; // The D1 pin of the shift register is connected to pin A5 of the Arduino
const int clockPin = A4; // The clock input pin of the shift register is connected to pin A4 of the Arduino
const int resetPin = A3; // The reset pin of the shift register is connected to pin A3 of the Arduino

// Common cathode 7-segment display characters
byte numbers[] = {
0x3F, // 0
0x06, // 1
0x5B, // 2
0x4F, // 3
0x66, // 4
0x6D, // 5
0x7D, // 6
0x07, // 7
0x7F, // 8
0x6F // 9
};

void setup() {
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(resetPin, OUTPUT);
}

void loop() {
for (int i = 0; i < 10; i++) {
displayNumber(i, (i + 1) % 10);
delay(1000);
}
}

void displayNumber(int num1, int num2) {
digitalWrite(resetPin, LOW); // Reset shift register
digitalWrite(resetPin, HIGH);

//Send data to the first 7-segment display
shiftOut(dataPin, clockPin, MSBFIRST, numbers[num1]);

// Send data to the second 7-segment display
shiftOut(dataPin, clockPin, MSBFIRST, numbers[num2]);

}

void shiftOut(int value) {
for (int i = 0; i < 8; i++) {
digitalWrite(dataPin, (value & (1 << (7 - i))) ? HIGH : LOW);
digitalWrite(clockPin, HIGH);
digitalWrite(clockPin, LOW);
}
}

  • Arduino projects
  • 7-segment display tutorial
  • Shift register interfacing
  • Arduino programming for beginners
  • Electronics projects for beginners
  • Digital display projects
  • DIY electronics projects
  • Arduino shiftOut function
  • Controlling multiple displays with Arduino
  • 7-segment display with shift register

Post a Comment

0 Comments