How to Display Up Counting on a 7-Segment Display Using Arduino with Reduced Inputs

In this project, we’ll explore how to display up counting on a 7-segment display using an Arduino and a BCD to seven-segment decoder. By reducing the number of inputs, this guide simplifies the process while maintaining functionality.

This project is perfect for beginners looking to enhance their understanding of Arduino programming and digital electronics.

Components Required

To get started, you’ll need the following components:

  • Arduino UNO Board
  • Seven-Segment Display
  • BCD to Seven-Segment Decoder
  • Push Button
  • Resistors
  • LEDs

Step-by-Step Guide

  1. Connect the Components:
    • Use the BCD to seven-segment decoder to connect the seven-segment display to your Arduino.
    • Attach the push button to pin 13 on the Arduino for manual counting.
    • Ensure proper wiring with resistors to prevent damage to the components.
  2. Source Code: Here is the optimized code to count up on the seven-segment display while reducing the number of inputs used.
const byte UP = 13, LED = 12, CLOCK = 11, DATA = 10, LATCH = 9; 
byte check, count = 0, convert = 0;

void setup() {
  pinMode(UP, INPUT); 
  pinMode(LED, OUTPUT); 
  pinMode(CLOCK, OUTPUT);
  pinMode(DATA, OUTPUT); 
  pinMode(LATCH, OUTPUT); 
  displayvalue(convert);
}

void loop() {
  while (1) {
    check = digitalRead(UP); 
    if (check == 1) {
      delay(250); 
      count++; 
      if (count == 99) {
        count = 0; 
        convert = 0; 
        displayvalue(convert); 
        break; 
      }
      convert = bintobcd(count); 
      displayvalue(convert);
    }
  }
  digitalWrite(LED, 1); 
  delay(1000); 
  digitalWrite(LED, 0);
}

byte bintobcd(byte recv) {
  byte q, r;
  q = recv / 10; 
  r = recv % 10; 
  q = q << 4; 
  q = q | r; 
  return q;
}

void displayvalue(byte recv) {
  digitalWrite(LATCH, 0); 
  shiftOut(DATA, CLOCK, MSBFIRST, recv); 
  digitalWrite(LATCH, 1);
}

Code Explanation

  • BCD to seven-segment decoder: The binary-coded decimal (BCD) helps convert the binary numbers into decimal form for the seven-segment display.
  • Counting: The push button (connected to pin 13) increments the counter, which is then displayed on the seven-segment display.
  • bintobcd Function: Converts the binary counter value into BCD format for display.
  • The LED connected to pin 12 blinks every second as an indicator.

    Results

    With everything wired correctly and the code uploaded, pressing the button will increment the number on the 7-segment display. Once the count reaches 99, it resets to zero and continues counting from there.


    Comments

    Leave a Reply

    Your email address will not be published. Required fields are marked *