logo-mobile

ROHM

ROHM
Menu
  • Arduino –
  • Raspberry Pi –
  • Trending –
  • Others –
  • About –
  • Contact –

Arduino

How to Add a Digital Numerical Display to Your Project

DevicePlus Editorial Team
Published by DevicePlus Editorial Team at February 14, 2021
Categories
  • Arduino
Tags

In the past, we’ve shown how to control an LED matrix with an Arduino. However, if your project only needs to show numbers, you might be better off with a seven-segment numerical display. These displays look like retro style digital alarm clocks and can display numbers using just seven LEDs. This guide will show you how.

 

How Seven-Segment LED Displays Work

Seven-segment displays feature an array of seven LEDs, in the shape of an 8, that can be individually lit up to display different numbers (or, in some cases, letters). Often there’s an eight LED that can function as a decimal place. Some modules come with multiple seven-segment arrangements. For example, a four-digit seven-segment display could be used as a clock.

To keep things simple, we’ll focus on just one digit for this guide. Seven-segment displays can take one of two forms: either a common anode or common cathode configuration. In a common anode configuration, all LEDs are connected to power, and each individual LED is controlled by selectively connecting them to ground. In the common cathode, this is reversed: each LED is connected to ground, and power is controlled on an individual basis.

The exact configuration of your display may vary, so look for markings on your module and find the specification sheet to confirm which configuration your display is wired for and which pins correspond to which LED. For this guide, we’ll be using a 5611AS, which uses a common cathode configuration.

To make the code work, you’ll also need the SevSeg library, found here on Github. Download the .zip file, then in your IDE, navigate to Sketch > Include library > Add .ZIP library… and select the SevSeg library. Now, you’ll be able to include it in your sketches.

What You’ll Need

Like the LED matrix, this project will require quite a bit of wiring and resistors. Since each LED needs its own resistor to avoid burning out the LEDs, make sure you have plenty of resistors handy. For the entire project, here’s what you’ll need:

Arduino Uno
Seven-segment LED display
Wires
8x 220 ohm resistor
Breadboard
USB cable
Arduino IDE

 

Since the cabling here can get a bit bulky, make sure you have enough space on your breadboard for all the wiring and resistors you’ll need. Once you have everything, move onto the next section.

The Code

Since we’re using the SevSeg library, the code for this project will be fairly simple. First, here’s the full code you can paste into your IDE and upload:

#include “SevSeg.h”
SevSeg digit;

void setup(){
byte numDigits = 1;
byte digitPins[] = {2, 3, 4, 5, 6, 7, 8, 9};
byte segmentPins[] = {6, 5, 2, 3, 4, 7, 8, 9};
bool resistorsOnSegments = true;

byte hardwareConfig = COMMON_CATHODE;
digit.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments);
digit.setBrightness(90);
}

void loop(){
for (int i = 0;i < 10;i++){
digit.setNumber(i);
digit.refreshDisplay();
delay(1000);
}
}

Next, let’s go through the parts of the code, starting with the top two lines.

#include “SevSeg.h”
SevSeg digit;

The first line here includes the SevSeg.h library, allowing you to use all the commands included in this library. The second creates an object of the SevSeg type, in this case, called “digit,” that will be used to control your display. For modules with more than one digit, you can add more for each digit and give them unique names.

void setup(){
byte numDigits = 1;
byte digitPins[] = {2, 3, 4, 5, 6, 7, 8, 9};
byte segmentPins[] = {6, 5, 2, 3, 4, 7, 8, 9};
bool resistorsOnSegments = true;

byte hardwareConfig = COMMON_CATHODE;
digit.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments);
digit.setBrightness(90);
}

In this section, we’ll set up the display. Most of the work here is being done by the digit.begin() function. Per the SevSeg library documentation, this command is used to tell the Arduino what traits your display has, like the number of digits (in this case, one), which Arduino pins you’re using to address the display (pins 2-9), and whether there are resistors on the circuits. The segmentPins array identifies which Arduino pins correspond to which segment, from A through G and ending with the decimal point. Refer to your display’s documentation to determine which segments correspond with which pins.

Each of these are assigned to a variable first—which makes it easier to expand the sketch later—before being passed to the digit.begin function. Finally, digit.setBrightness tells the sketch how bright to light the LED segments.

void loop(){
for (int i = 0;i < 10;i++){
digit.setNumber(i);
digit.refreshDisplay();
delay(1000);
}
}

In the loop() section, we’ll run the display through a loop that will count from 0 to 9 and then start over. For each iteration of the loop, the variable i will be used in the digit.setNumber command to tell the display which number to show. The SevSeg library automatically interprets this to send the correct signal to the correct LED segments (as long as you’ve assigned them correctly in the previous section). Then, digit.refreshDisplay is called to tell the display to update with the new number.

Finally, we add a delay(1000) command to keep each number shown for one second.

The Wiring

Connecting the display here involves a lot of wiring, but it’s not as complex as it looks. Again, we’ll use the 5611AS, but if you’re using a different model, check the specs for your display. Starting on the bottom of the display (the side with the decimal LED), from left to right, the pins are 1 through 5. On the top, the pins from left to right are 10 through 6. You can think of this as starting on the bottom left corner with pin 1 and counting to pin 10 by wrapping around the display counterclockwise.

For this display, you’ll need to run eight circuits from the Arduino to pins on the display, with a 220 ohm resistor in between. Each LED needs a resistor to stop it from burning out. While you could add a single, higher resistance resistor after the common ground pins, this would result in different numbers appearing at different levels of brightness, depending on how many segments are lit up.

For each of the following, use a breadboard to add a resistor in the circuit in between the Arduino and the display, connecting the following pins on the Arduino to their corresponding pins on the display:

● Connect Arduino pin 2 to display pin 4
● Connect Arduino pin 3 to display pin 2
● Connect Arduino pin 4 to display pin 1
● Connect Arduino pin 5 to display pin 6
● Connect Arduino pin 6 to display pin 7
● Connect Arduino pin 7 to display pin 9
● Connect Arduino pin 8 to display pin 10
● Connect Arduino pin 9 to display pin 5

Finally, the two middle pins on each side of the display—pins 3 and 8—should be connected to GND on the Arduino. Once the whole display is wired up, you can upload the code and turn it on. Try changing the code to show different numbers to see your display in action.

DevicePlus Editorial Team
DevicePlus Editorial Team

Check us out on Social Media

  • Facebook
  • Twitter

Recommended Posts

  • Enter the Matrix, LED Matrix that is! Create your very own light up LED display with ArduinoEnter the Matrix, LED Matrix that is! Create your very own light up LED display with Arduino
  • Controlling Robot Arm with DialsControlling Robot Arm with Dials
  • Display characters with LEDs! How to use a matrix LEDDisplay characters with LEDs! How to use a matrix LED
  • Arduino Sensors – ROHM Sensor Evaluation Kit OverviewArduino Sensors – ROHM Sensor Evaluation Kit Overview
  • How to Control a Light with a DimmerHow to Control a Light with a Dimmer
  • How to Add an LCD Display to Your ProjectHow to Add an LCD Display to Your Project
Receive update on new postsPrivacy Policy

Recommended Tutorials

  • How to integrate an RFID module with Raspberry Pi How to integrate an RFID module with Raspberry Pi
  • How to Use the NRF24l01+ Module with Arduino How to Use the NRF24l01+ Module with Arduino
  • How to Run Arduino Sketches on Raspberry Pi How to Run Arduino Sketches on Raspberry Pi
  • Setting Up Raspberry Pi as a Home Media Server Setting Up Raspberry Pi as a Home Media Server

Recommended Trends

  • SewBot Is Revolutionizing the Clothing Manufacturing Industry SewBot Is Revolutionizing the Clothing Manufacturing Industry
  • All About The Sumo Robot Competition And Technology All About The Sumo Robot Competition And Technology
  • 5 Interesting Tips to Calculating the Forward Kinematics of a Robot 5 Interesting Tips to Calculating the Forward Kinematics of a Robot
  • Go Inside the Drones That Are Changing Food Delivery Go Inside the Drones That Are Changing Food Delivery
Menu
  • Arduino –
    Arduino Beginner’s Guide
  • Raspberry Pi –
    Raspberry Pi Beginner's Guide
  • Trending –
    Updates on New Technologies
  • Others –
    Interviews / Events / Others

Check us out on Social Media

  • Facebook
  • Twitter
  • About
  • Company
  • Privacy Policy
  • Terms of Service
  • Contact
  • Japanese
  • 简体中文
  • 繁體中文
Don’t Forget to Follow Us!
© Copyright 2016-2023. Device Plus - Powered by ROHM
© 2023 Device Plus. All Rights Reserved. Muffin group

istanbul escort istanbul escort istanbul escort