Arduino SevSeg 7-Segment Library: Wiring, Code and Simulator
To build this Arduino SevSeg 7-Segment Library project you need an Arduino Uno and a 7-segment display. The SevSeg library shows a number on a common-cathode 7-segment display. Make the 9 connections in the wiring table, upload the Arduino C++ code, and change setNumber(7) to another digit.
Open this circuit in the free Arduino Uno simulator
Parts list
| Qty | Part | What it does |
|---|---|---|
| 1 | Arduino Uno | the microcontroller board |
| 1 | 7-segment display | One digit. Segments A–G and DP share COM (common cathode by default). |
Wiring
| # | From | To |
|---|---|---|
| 1 | Arduino Uno pin 2 | 7-segment display A |
| 2 | Arduino Uno pin 3 | 7-segment display B |
| 3 | Arduino Uno pin 4 | 7-segment display C |
| 4 | Arduino Uno pin 5 | 7-segment display D |
| 5 | Arduino Uno pin 6 | 7-segment display E |
| 6 | Arduino Uno pin 7 | 7-segment display F |
| 7 | Arduino Uno pin 8 | 7-segment display G |
| 8 | Arduino Uno pin 10 | 7-segment display DP |
| 9 | Arduino Uno pin 9 | 7-segment display COM |
Step by step
- Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Arduino Uno. No install or account is needed.
- Add the parts. Add a 7-segment display from the parts palette.
- Wire 1. Connect Arduino Uno pin 2 to 7-segment display A.
- Wire 2. Connect Arduino Uno pin 3 to 7-segment display B.
- Wire 3. Connect Arduino Uno pin 4 to 7-segment display C.
- Wire 4. Connect Arduino Uno pin 5 to 7-segment display D.
- Wire 5. Connect Arduino Uno pin 6 to 7-segment display E.
- Wire 6. Connect Arduino Uno pin 7 to 7-segment display F.
- Wire 7. Connect Arduino Uno pin 8 to 7-segment display G.
- Wire 8. Connect Arduino Uno pin 10 to 7-segment display DP.
- Wire 9. Connect Arduino Uno pin 9 to 7-segment display COM.
- Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
- Run it. Press Run. Change setNumber(7) to another digit.
Arduino C++ code
// SevSeg: show a digit on a common-cathode 7-segment display (segments on 2-8).
#include <SevSeg.h>
SevSeg seg;
void setup() {
byte digitPins[] = {9};
byte segmentPins[] = {2, 3, 4, 5, 6, 7, 8, 10};
seg.begin(COMMON_CATHODE, 1, digitPins, segmentPins, true);
seg.setNumber(7);
}
void loop() {
seg.refreshDisplay();
}
What to try
Change setNumber(7) to another digit.
Frequently asked questions
How do I wire the SevSeg 7-Segment Library project on an Arduino Uno?
Make 9 connections: Arduino Uno pin 2 to 7-segment display A; Arduino Uno pin 3 to 7-segment display B; Arduino Uno pin 4 to 7-segment display C; Arduino Uno pin 5 to 7-segment display D; Arduino Uno pin 6 to 7-segment display E; Arduino Uno pin 7 to 7-segment display F; Arduino Uno pin 8 to 7-segment display G; Arduino Uno pin 10 to 7-segment display DP; Arduino Uno pin 9 to 7-segment display COM.
What parts do I need for this Arduino project?
An Arduino Uno and a 7-segment display.
Can I simulate this Arduino project online for free?
Yes. The BitForBytes Embedded Lab runs this exact circuit and Arduino C++ code in your browser for free, with no install and no hardware. The sketch is compiled with the real Arduino toolchain and runs on an emulated ATmega328P.
What does the code do?
The SevSeg library shows a number on a common-cathode 7-segment display.
More Arduino Uno projects
- Arduino LED Blink: Wiring, Code and Simulator
- Arduino LDR Light Sensor: Wiring, Code and Simulator
- Arduino NTC Thermistor Thermometer: Wiring, Code and Simulator
- Arduino PWM to Analog RC Filter: Wiring, Code and Simulator
- Arduino Capacitance Meter: Wiring, Code and Simulator
- Arduino DC Motor PWM Speed Control with MOSFET: Wiring, Code and Simulator