1-Digit 7-Segment Display on Arduino-Compatible Board (DIY Board)

Now, we will be studying how to display numbers (or even some letters) to the 7-segment display on your Arduino-compatible board (I wrote an article on how to create your own Arduino-compatible board which you might want to see first : My First DIY Arduino Board.


Below are the needed components for this exercise:

  1. One (1) 7-Segment Display
  2. Two (2) 220-ohm Resistors
  3. Eight (8) Male-to-Male Jumper Wires
  4. Arduino boar (or in our case, the DIY Arduino-compatible board I created)
  5. FTDI Serial to TTL Module with Male-to-female jumper wires attached to it
  6. USB Cable for communicating with the Arduino IDE

Items 1-3 are the main components for this exercise, and items 4-6 are actually explained in the above-mentioned article I wrote previously.

Before going to attach anything to the 7-segment display, we first study its pinouts (to the board). Take a look at the image image below:

The pin labels above need to be attached to the corresponding pins to our Atmega328 microcontroller. (Refer to the above-mentioned article I wrote for the Atmega328 pinout).

7-segment display pin 1 – Arduino Digital Pin 6 (Atmega328 Pin 12)
7-segment display pin 2 – Arduino Digital Pin 5 (Atmega328 Pin 11)
7-segment display pin 3 – GND via 220-ohm resistor
7-segment display pin 4 – Arduino Digital Pin 4 (Atmega328 Pin 6)
7-segment display pin 5 – may be assigned with a digital pin in Arduino if needed.
7-segment display pin 6 – Arduino Digital Pin 3 (Atmega328 Pin 5)
7-segment display pin 7 – Arduino Digital Pin 2 (Atmega328 Pin 4)
7-segment display pin 8 – Arduino GND via 220-ohm resistor
7-segment display pin 9 – Arduino Digital Pin 8 (Atmega328 Pin 14)
7-segment display pin 10 – Arduino Digital Pin 9 (Atmega328 Pin 15)

The segments are actually controlled by the following Arduino digital pins. Refer to the details below:

Segment “a” – Arduino Digital Pin 2
Segment “b” – Arduino Digital Pin 3
Segment “c” – Arduino Digital Pin 4
Segment “d” – Arduino Digital Pin 5
Segment “e” – Arduino Digital Pin 6
Segment “f” – Arduino Digital Pin 8
Segment “g” – Arduino Digital Pin 9

Now, attach the 7-segment display component to the breadboard as shown in the image below:

After attaching the 7-segment display, connect the corresponding pins of this component to the digital pins of the Atmega328 microcontroller. Please refer to the discussion above regarding pin assignments to the microcontroller (or Arduino-compatible board):

Attach the FTDI Seria to TTL module to the breadboard, connecting its pins to its respective Atmega328 pin counterpart (Details of the FTDI Serial to TTL module is discussed in my previous articles):

Now, the next thing to be done is to prepare your code, to light up the segments.Basically each segment is assigned to a digital pin as discussed above. If we set the digital pin to HIGH, then the corresponding segment for that digital pin lights up. Numbers or even some letters are created by lighting up several combinations of segments. Below is my sample code for the 7-segment display:

// My first 7-segment display experiment
int a = 2; //For displaying segment "a"
int b = 3; //For displaying segment "b"
int c = 4; //For displaying segment "c"
int d = 5; //For displaying segment "d"
int e = 6; //For displaying segment "e"
int f = 8; //For displaying segment "f"
int g = 9; //For displaying segment "g"

void setup() {
 // put your setup code here, to run once:
 pinMode(a, OUTPUT); // segment a
 pinMode(b, OUTPUT); // segment b
 pinMode(c, OUTPUT); // segment c
 pinMode(d, OUTPUT); // segment d
 pinMode(e, OUTPUT); // segment e
 pinMode(f, OUTPUT); // segment f
 pinMode(g, OUTPUT); // segment g

void loop() {
 // display the digit 5

Compile the code above (CTRL-R in the Arduino IDE), and upload this sketch to the microcontroller (CTRL-U in the Arduino IDE). Once successful, you should be seeing the 7-segment display component displaying the digit 5, as seen from the image below:

Thank you very much for reading this tutorial, guys! Hope this helps. You might want to do some experiments, like displaying the digits from 0 to 9 every second. Try it! Let me know how you go.

Component sources:
Sun Kist Enterprises (https://web.facebook.com/SunKistEnterprise/) thru
Mr. Mark Rudolph C. Domasin (https://www.facebook.com/Rudolphchase)


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s