Lois
Published © CERN-OHL2

Arduino-Controlled Dual 7-Segment LED Counters

Use Arduino and 8-bit shift registers to control dual 7-segment displays, cycling digits 0-9.

BeginnerProtip134

Things used in this project

Hardware components

Shift Register- Parallel to Serial
Texas Instruments Shift Register- Parallel to Serial
×1
Arduino UNO
Arduino UNO
×1
LED (generic)
LED (generic)
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
Resistor 10k ohm
Resistor 10k ohm
×1
7 Segment LED Display, InfoVue
7 Segment LED Display, InfoVue
×1

Software apps and online services

Online Simulation
PCBX Online Simulation

Hand tools and fabrication machines

Materia 101
Arduino Materia 101

Story

Read more

Schematics

Arduino-Controlled Dual 7-Segment LED Counters

A simple example of how to use Arduino and two 8-bit shift registers to control two 7-segment LED displays to show numbers. By cycling through the numbers 0 to 9, you can observe the digits changing on the displays.

Code

Arduino-Controlled Dual 7-Segment LED Counters

Arduino
A simple example of how to use Arduino and two 8-bit shift registers to control two 7-segment LED displays to show numbers. By cycling through the numbers 0 to 9, you can observe the digits changing on the displays.
// 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);
    }
}

Credits

Lois
13 projects • 2 followers
Contact

Comments

Please log in or sign up to comment.