Learn How to Use 7-Segment Displays with Arduino
Credit: CircuitDigest.com

Learn How to Use 7-Segment Displays with Arduino

Nowadays visual indication is a must feature for any electronic device, which will make user interaction much easier. There are multiple ways to implement the visual indication, from simple light indications to LCDs or even holograms. Today we will be talking about such a device, which has been used in the industry for decades – the Seven-Segment Display.

Source: Arduino Seven Segment Display - Tutorial from CircuitDigest


Seven Segment Display Pinout

As the name suggests, the seven-segment display consists of seven LEDs, which are arranged in a particular order to form the digit eight. And most common modules will come with an additional LED to indicate the decimal point. This will be useful when using multiple display modules to display a decimal number. Each one of these LEDs are arranged in a specific order as a segment and one of its pins is being brought out of the plastic package. The other LED pins are connected together and wired to form a common pin.

7-Segment Display Pinout
Common Cathode 7-Segment Display working
Common Anode Seven Segment Display Working

Connecting Seven Segment Display with?Arduino

Now let’s see how we can drive a seven-segment display with an?Arduino. For that let’s start by placing the display module on a breadboard with the decimal point facing downwards. Then wire up each pin as per the connection diagram below. In this tutorial, we will be using a Common Cathode display.


Connect either of the common pins (seven-segment pin 3 or 8) to the ground. And connect the rest of the pins to D2 to D9 of the?Arduino?through a current limiting resistor, as per the connection diagram. Just like driving an LED, it is preferable to use these current limiting resistors to increase the display life. Choose these values depending on the display?colour?and size. Here we will be using a 330 ohms resistor which will provide around 10mA current for the?LEDs.

Image showing how 7segment display is connected with Arduino

Arduino Code for 7-Segment Display

#include "SevSeg.h"

SevSeg sevseg;

void setup() {
  // Set to 1 for single-digit display
  byte numDigits = 1;

  // Defines common pins while using multi-digit display. Left for single digit display
  byte digitPins[] = {};

  // Defines Arduino pin connections in order: A, B, C, D, E, F, G, DP
  byte segmentPins[] = {9, 8, 7, 6, 5, 4, 3, 2};

  byte displayType = COMMON_CATHODE; // Use COMMON_ANODE for Common Anode display
  bool resistorsOnSegments = true;   // ‘false’ if resistors are connected to the common pin

  // Initialize sevseg object. Use COMMON_ANODE instead of COMMON_CATHODE for CA display
  sevseg.begin(displayType, numDigits, digitPins, segmentPins, resistorsOnSegments);

  sevseg.setBrightness(90);
}

void loop() {
  // Display numbers 0-9 with 1 second delay
  for (int i = 0; i <= 10; i++) {
    if (i == 10) {
      i = 0;
    }
    sevseg.setNumber(i);
    sevseg.refreshDisplay();
    delay(1000);
  }
}        

GitHub Link: https://github.com/Circuit-Digest/Basic-Arduino-Tutorials-for-Beginners-/tree/main/Interfacing%20Seven%20Segment%20Display%20with%20Arduino

Projects Using Seven-Segment Displays

  1. 7-Segment Display Clock
  2. 7-Segment Counter using 555 Timer
  3. Object/Product Counter

Shri Dhanush AM

Robotics - Automation - Controls

1 年

Nice one. I have worked on LPC for 7 segment analysis. I wish it would be an easy process to work with Arduino.

要查看或添加评论,请登录

Aswinth Raj的更多文章

社区洞察

其他会员也浏览了