Aim
To interface a seven-segment display with Arduino and display numbers from 0 to 9 with a 1-second
delay between each number.
Apparatus Required
Arduino Uno
Seven-segment display
7 × 220Ω resistors
Jumper wires
Circuit Diagram
Pin Connections
Note: Each Arduino pin connects to its respective seven-segment pin through a 220Ω current-limiting
resistor.
Arduino Pin Seven Segment Pin Function
Pin 2 A Segment A
Pin 3 B Segment B
Pin 4 C Segment C
Pin 5 D Segment D
Pin 6 E Segment E
Pin 7 F Segment F
Pin 8 G Segment G
GND COM Common Cathode
Procedure
Hardware Setup:
Connect the seven-segment display to Arduino pins 2-8 through 220Ω resistors
Connect the common cathode (COM) pin to Arduino GND
Ensure all connections are secure
Software Implementation:
Define pin mappings for segments A-G
Create digit patterns array for numbers 0-9
Initialize pins as outputs in setup()
Implement displayDigit() function to control segments
Create main loop to cycle through digits 0-9 with 1-second delays
Wokwi Simulation:
Write there Arduino code into Wokwi editor
Use the provided JSON configuration for circuit setup
Run the simulation to verify functionality
Circuit Working Principle
The seven-segment display consists of 7 LEDs arranged in a pattern. Each segment (A-G) is controlled
by a digital pin from the Arduino. For a common cathode display:
HIGH (5V) on a segment pin turns the segment ON
LOW (0V) on a segment pin turns the segment OFF
The common cathode is connected to ground
Each digit (0-9) requires a specific combination of segments to be turned on/off, which is stored in the
digitPatterns array.
Expected Result
When the program runs, the seven-segment display will:
Display digit "0" for 1 second
Display digit "1" for 1 second
Continue sequentially through digits 2-9
Repeat the cycle indefinitely
Serial monitor will show which digit is currently being displayed
The display will continuously cycle through all digits 0-9 with a clear 1-second pause between each
number, creating a counting effect.
To simulate this in Wokwi:
Go to wokwi.com
Create a new Arduino project
Connect the resistor and pins
Write the Arduino code
Add the circuit components JSON configuration
Run the simulation to see the seven-segment display counting from 0 to 9
Source Code For Arduino
int segmentPins[] = {2, 3, 4, 5, 6, 7, 8};
int commonPin = 9;
bool digitPatterns[10][7] = {
{1, 1, 1, 1, 1, 1, 0},
{0, 1, 1, 0, 0, 0, 0},
{1, 1, 0, 1, 1, 0, 1},
{1, 1, 1, 1, 0, 0, 1},
{0, 1, 1, 0, 0, 1, 1},
{1, 0, 1, 1, 0, 1, 1},
{1, 0, 1, 1, 1, 1, 1},
{1, 1, 1, 0, 0, 0, 0},
{1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 0, 1, 1}
};
void setup() {
for (int i = 0; i < 7; i++) {
pinMode(segmentPins[i], OUTPUT);
}
pinMode(commonPin, OUTPUT);
digitalWrite(commonPin, LOW);
Serial.begin(9600);
Serial.println("Seven Segment Display - Counting 0 to 9");
}
void loop() {
for (int number = 0; number <= 9; number++) {
displayNumber(number);
Serial.print("Displaying: ");
Serial.println(number);
delay(1000);
}
}
void displayNumber(int number) {
for (int i = 0; i < 7; i++) {
digitalWrite(segmentPins[i], LOW);
}
for (int i = 0; i < 7; i++) {
digitalWrite(segmentPins[i], digitPatterns[number][i]);
}
}
void displaySegments(bool a, bool b, bool c, bool d, bool e, bool f, bool g) {
digitalWrite(segmentPins[0], a);
digitalWrite(segmentPins[1], b);
digitalWrite(segmentPins[2], c);
digitalWrite(segmentPins[3], d);
digitalWrite(segmentPins[4], e);
digitalWrite(segmentPins[5], f);
digitalWrite(segmentPins[6], g);
}
Source Code For JSON File
{
"version": 1,
"author": "Arduino Seven Segment Display",
"editor": "wokwi",
"parts": [
{ "type": "wokwi-arduino-uno", "id": "uno", "top": -18.6, "left": 85.8, "attrs": {} },
{
"type": "wokwi-7segment",
"id": "sevseg1",
"top": -43.02,
"left": -33.32,
"attrs": { "common": "cathode" }
},
{
"type": "wokwi-resistor",
"id": "r1",
"top": 51.95,
"left": 153.6,
"attrs": { "value": "220" }
},
{ "type": "wokwi-resistor", "id": "r2", "top": 70, "left": 150, "attrs": { "value": "220" } },
{ "type": "wokwi-resistor", "id": "r3", "top": 90, "left": 150, "attrs": { "value": "220" } },
{ "type": "wokwi-resistor", "id": "r4", "top": 110, "left": 150, "attrs": { "value": "220" } },
{ "type": "wokwi-resistor", "id": "r5", "top": 130, "left": 150, "attrs": { "value": "220" } },
{ "type": "wokwi-resistor", "id": "r6", "top": 150, "left": 150, "attrs": { "value": "220" } },
{ "type": "wokwi-resistor", "id": "r7", "top": 170, "left": 150, "attrs": { "value": "220" } }
],
"connections": [
[ "uno:2", "r1:1", "green", [] ],
[ "uno:3", "r2:1", "blue", [] ],
[ "uno:4", "r3:1", "yellow", [] ],
[ "uno:5", "r4:1", "orange", [] ],
[ "uno:6", "r5:1", "red", [] ],
[ "uno:7", "r6:1", "purple", [] ],
[ "uno:8", "r7:1", "gray", [] ],
[ "r1:2", "sevseg1:A", "green", [] ],
[ "r2:2", "sevseg1:B", "blue", [] ],
[ "r3:2", "sevseg1:C", "yellow", [] ],
[ "r4:2", "sevseg1:D", "orange", [] ],
[ "r5:2", "sevseg1:E", "red", [] ],
[ "r6:2", "sevseg1:F", "purple", [] ],
[ "r7:2", "sevseg1:G", "gray", [] ],
[ "uno:9", "sevseg1:COM", "black", [] ],
[ "uno:GND", "sevseg1:COM", "black", [] ]
],
"dependencies": {}
}
Wokwi Setup
Video Link :https://drive.google.com/file/d/1tHzKj3L4aiuXwHMI6VvtHI-
Xgj_UcC5N/view?usp=sharing
Wokwi Link : https://wokwi.com/projects/436479064962862081