Interface Arduino with 7-segment display | 4-Digit counter example

Interface Arduino with 7-segment display | 4-Digit counter example

This post shows how to interface Arduino UNO board with 7-segment display in order to build a simple 4-digit counter which counts from 0 to 9999. A push button connected to Arduino is used to increment the displayed number.

There are two types of the seven-segment displays: common anode and common cathode.
In the common anode type all the 7 LED anode terminals are connected together whereas in the common cathode all cathode terminals are connected together.

The common terminal is connected to +VCC (+5V, +3.3V …) or GND (0V) depending on the type of the 7-segment display (common anode or common cathode respectively).

Basically for each 7-segment digit there are 8 pins: one for the common terminal (anode or cathode) and 7 pins for the 7 segments (A, B, C, D, E, F and G). Another pin may be used for the decimal point (DP).

one-digit seven-segment display

In multi-digit 7-segment display (for example 4-digit) all pins of the same segment are connected together (segment A of digit 1 with segment A of digit 2 …), and each digit has its common pin alone. This is called multiplexing technique. This technique minimizes number of pins used.

So for a 4-digit display we’ll have 7 pins of the 7 segments, 4 pins of the 4 digits (common terminals) and 1 pin for the decimal point (DP) which means a total of 12 pins.

Hardware Required:

  • Arduino UNO board
  • 4-Digit common anode 7-segment display
  • 4 x PNP transistor (2SA10152S90152N3906 …)
  • 7 x 100 ohm resistor
  • 4 x 4.7k ohm resistor
  • Push button
  • Breadboard
  • Jumper wires

Interfacing Arduino with 7-segment display circuit:
Example circuit schematic diagram is shown below.

Arduino with common anode 7-segment display | Arduino 7 segment

The push button which is connected to Arduino A0 pin is used to increment the displayed number.
A common anode 7-segment display is used in this example.

In the circuit there are 4 transistors of the type PNP, the collector of each transistor is connected to common anode pin of 1 digit. That means each transistor supplies one digit segments.
The 4 transistors are used to supply the display LEDs with sufficient current because Arduino microcontroller (ATmega328P) may not be able to do that (maximum output current is 40mA).
Each transistor emitter pin is connected to +5V that comes from the Arduino board and each transistor base is connected to the Arduino through 4.7k resistor.

Each 100 ohm resistor is used for limiting the current that passes through the segment LED.

Interfacing Arduino with 7-segment display code:
Example Arduino code is below.

Since the 4 digits are multiplexed we need to refresh the display very quickly (display one digit at a time, others are off). For that I used Timer1 module interrupt with the following configuration:

 

 

With the above configuration Timer1 module overflows every 4096 microseconds (4096 = 65536/16) which is a good refresh period.

Note that Timer1 module is 16-bit timer, prescaler = 1 (TCCR1B = 1) and Arduino UNO clock = 16MHz.

 

 

The following video shows a simple protoboard circuit of the example:

and the video below shows Proteus simulation (simulation circuit is not the same as real hardware circuit, example circuit diagram is shown above):

Proteus simulation file download:
Arduino 7-segment display counter

Other Arduino projects where 7-segment display was used:
Print Arduino ADC values on 7-segment display
Arduino with rotary encoder and 7 segment display
Arduino with LM335 temperature sensor and seven-segment display
Interfacing Arduino with LM35 sensor and 7-segment display
7-Segment display with 74HC595 shift register | Arduino Projects


Discover more from Simple Circuit