0% found this document useful (0 votes)
41 views1 page

Laboratory Manual 2016 Edition

This document provides instructions for interfacing a 7-segment display and a 4-digit 7-segment display to an Arduino board. It describes the pinouts of the displays and how to write code to display numbers on each. For the single 7-segment display, the code loops through the digits 0-9, activating the appropriate LED segments for each. For the 4-digit display, a multiplexing technique is used to rapidly switch between the digits to display a 4-digit number simultaneously using only 12 pins. A 74HC595 shift register IC is used to reduce the number of Arduino pins needed to control the 32 LED segments.

Uploaded by

ア ム
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views1 page

Laboratory Manual 2016 Edition

This document provides instructions for interfacing a 7-segment display and a 4-digit 7-segment display to an Arduino board. It describes the pinouts of the displays and how to write code to display numbers on each. For the single 7-segment display, the code loops through the digits 0-9, activating the appropriate LED segments for each. For the 4-digit display, a multiplexing technique is used to rapidly switch between the digits to display a 4-digit number simultaneously using only 12 pins. A 74HC595 shift register IC is used to reduce the number of Arduino pins needed to control the 32 LED segments.

Uploaded by

ア ム
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

DEPARTMENT

COLLEGE OF ENGINEERING
NOTRE DAME UNIVERSITY
COTABATO CITY, 9600
PHILIPPINES

Laboratory Exercise 6
7-Segment and Dot Matrix LED
Objectives:
At the end of the exercise, the students should be able to:
• interface 7 Segment display to Arduino board
• interface 8x8 Dot Matrix to Arduino board
• add library file to a sketch
• describe the functions of an 595 Shift Register
Materials:
1 – Arduino UNO R3 Starter Kit
1 – Personal Computer with installed Arduino IDE
Software
7-Segment Display
Seven segment displays are used in many embedded
system and industrial applications where the range of
outputs to be shown is known beforehand. Basic 1 digit
seven segment display can show numbers from 0-9 and a
few characters. 7 segment displays are of different types;
especially they differ in the number of digits/character it
can display. Basically a 7 segment display is a single unit,
which can display only 1 digit or 1 character. More digits
are displayed by multiplexing single unit 7 segment
displays together to form 2 digit display, 3 digit display or
4 digit 7 segment display. Its quiet easy to interface
Arduino and 7 Segment display together!
Single-Digit 7 Segment Display

3.8.com

E G DF

Com DP

Figure 6-1. 7 Segment Pin Out Diagram


As you can see there are 10 pins in total. You may notice
two pins named com, as shown in the circuit diagram all
the anodes (+ pins) of the LEDs are connected to these
two pins. We call these 2 pins as common anodes and
such displays are called Common Anode 7 segment
displays. There are some seven segment displays which
have common cathodes instead of common anodes. The
only difference for common cathode displays is all the
cathodes (- pins) are connected together and they are
known as Common Cathode 7 segment displays. Apart
from these 2 com pins, there are 8 other pins named
A,B,C,D,E,F,G and DP. As you can see in the figure,
these pins are cathodes (- pins) of the led segments of
common anode display (in the case of common cathode
display these pins will be anodes).
1. Construct the circuit diagram below.
R1
+7.5-12VDC 2200 Com

MCU1
ArduinoUno
10
PowerJack

DISP
Extemal

ArduinoUNO

Figure 6-2. 7 Segment Display to Arduino board


2. Verify your 7 segment types whether common anode
or cathode.
3. Write the program below to your sketch and upload
it. Observe the result.
int seg_a = 11; // declare the
variables
int seg_b = 10;
int seg_c = 9;
int seg_d = 8;
int seg_e = 7;
int seg_f = 6;
int seg_g = 5;
int seg_dp = 4;
int com = 12;

void setup() {
pinMode(seg_a,OUTPUT); //
configure all pins used to outputs
pinMode(seg_b,OUTPUT);
pinMode(seg_c,OUTPUT);
pinMode(seg_d,OUTPUT);
pinMode(seg_e,OUTPUT);
pinMode(seg_f,OUTPUT);
pinMode(seg_g,OUTPUT);
pinMode(seg_dp,OUTPUT);
pinMode(com,OUTPUT);

void loop() {
digitalWrite(com,HIGH); // set
common anode HIGH (5V)
for (int i = 0; i < 10; i++) { //
count 0 - 9
switch(i){ // switch statemet to
select the number

case 0: // set relevent segments


HIGH and others LOW
digitalWrite(seg_a,LOW);
digitalWrite(seg_b,LOW);
digitalWrite(seg_c,LOW);
digitalWrite(seg_d,LOW);
digitalWrite(seg_e,LOW);
digitalWrite(seg_f,LOW);
digitalWrite(seg_g,HIGH);
digitalWrite(seg_dp,HIGH);
break;

case 1:
digitalWrite(seg_a,HIGH);
digitalWrite(seg_b,LOW);
digitalWrite(seg_c,LOW);
digitalWrite(seg_d,HIGH);
digitalWrite(seg_e,HIGH);
digitalWrite(seg_f,HIGH);
digitalWrite(seg_g,HIGH);
digitalWrite(seg_dp,HIGH);
break;

case 2:
digitalWrite(seg_a,LOW);
digitalWrite(seg_b,LOW);
digitalWrite(seg_c,HIGH);
digitalWrite(seg_d,LOW);
digitalWrite(seg_e,LOW);
digitalWrite(seg_f,HIGH);
digitalWrite(seg_g,LOW);
digitalWrite(seg_dp,HIGH);
break;

case 3:
digitalWrite(seg_a,LOW);
digitalWrite(seg_b,LOW);
digitalWrite(seg_c,LOW);
digitalWrite(seg_d,LOW);
digitalWrite(seg_e,HIGH);
digitalWrite(seg_f,HIGH);
digitalWrite(seg_g,LOW);
digitalWrite(seg_dp,HIGH);
break;

case 4:
digitalWrite(seg_a,HIGH);
digitalWrite(seg_b,LOW);
digitalWrite(seg_c,LOW);
digitalWrite(seg_d,HIGH);
digitalWrite(seg_e,HIGH);
digitalWrite(seg_f,LOW);
digitalWrite(seg_g,LOW);
digitalWrite(seg_dp,HIGH);
break;

case 5:
digitalWrite(seg_a,LOW);
digitalWrite(seg_b,HIGH);
digitalWrite(seg_c,LOW);
digitalWrite(seg_d,LOW);
digitalWrite(seg_e,HIGH);
digitalWrite(seg_f,LOW);
digitalWrite(seg_g,LOW);
digitalWrite(seg_dp,HIGH);
break;

case 6:
digitalWrite(seg_a,LOW);
digitalWrite(seg_b,HIGH);
digitalWrite(seg_c,LOW);
digitalWrite(seg_d,LOW);
digitalWrite(seg_e,LOW);
digitalWrite(seg_f,LOW);
digitalWrite(seg_g,LOW);
digitalWrite(seg_dp,HIGH);
break;

case 7:
digitalWrite(seg_a,LOW);
digitalWrite(seg_b,LOW);
digitalWrite(seg_c,LOW);
digitalWrite(seg_d,HIGH);
digitalWrite(seg_e,HIGH);
digitalWrite(seg_f,HIGH);
digitalWrite(seg_g,HIGH);
digitalWrite(seg_dp,HIGH);
break;

case 8:
digitalWrite(seg_a,LOW);
digitalWrite(seg_b,LOW);
digitalWrite(seg_c,LOW);
digitalWrite(seg_d,LOW);
digitalWrite(seg_e,LOW);
digitalWrite(seg_f,LOW);
digitalWrite(seg_g,LOW);
digitalWrite(seg_dp,HIGH);
break;

case 9:
digitalWrite(seg_a,LOW);
digitalWrite(seg_b,LOW);
digitalWrite(seg_c,LOW);
digitalWrite(seg_d,LOW);
digitalWrite(seg_e,HIGH);
digitalWrite(seg_f,LOW);
digitalWrite(seg_g,LOW);
digitalWrite(seg_dp,HIGH);
break;

}
delay(1000); // Show each number
for 1 second
}

}
4-Digit 7-Segment Display
Now we are going to see how to interface 4 digit 7
segment display with arduino. We are going to use a
different method to control this Four digit display. Let’s
see the pinout of this 4 digit 7 segment display.

Figure 6-3. 4-Digit &-Segment Pin Out Diagram


As you can see in this pin out diagram of 4 digit 7
segment led display, there are a total of 32 led segments.
But as you can see there are only 12 pins. As shown in the
circuit diagram there are 4 common anodes and also
cathodes of same segments are connected together. So if
we connect all the segment pins to negative (ground) and
common pins to positive, you can see all the segments of
all four digits are turned on. By switching between the
four common anodes we can choose which display to turn
on. But as you can see we can’t display four different
digits the same time in this display as cathodes are same
for all four digits.
Multiplexing Technique
So how we are going to display a number like 1234 on
this 4 digit display? For this we are going to use a method
called multiplexing. What multiplexing does is simple –
show one digit at a time on a display unit and switch
between display units very fast. Due to persistence of
vision, human eye can not differentiate between which
display is ON/OFF. The human eye just visualizes all the
4 display units to be ON all the time. Let’s say we need to
show 1234. First we turn on the segments relevant to “1”
and turn on the 1st display unit. Then we send signals to
show “2”, turn off 1st display unit and turn on 2nd
display unit. We repeat this process for next two numbers
and switching between display units should be done very
fast (about within one second delay). As our eyes can’t
pick a change occurring repeatedly to any object within 1
second, what we see is 1234 appearing on the display at
the same time.

Figure 6-4. 4-Digit 7-Segment Display to Arduino board


As you can see in the diagram we are using an IC named
74HC595N in addition to arduino uno and 4 digit seven
segment display. 74HC595N – is a shift register IC and it
converts serial data to parallel data. This shift register IC
is used to reduce the number of digital I/O pins of arduino
required to control the 7 segment display. As obvious
from the circuit diagram, we need only 3 arduino digital
pins (connected to shift register IC) to control 8 segment
lines of 4 digit seven segment display.
Name of the pins and their functions of shift register
74HC595N are mentioned below:
• Q0 – Q7 – Parallel Data output
• SRCLK – Shift Register Clock Input pin, a clock
pulse should be send to this pin from arduino. If not
shift register can’t identify the starting and end points
of the data
• RCLK – Storage clock also known as the Latch pin,
this pin is used to set the mode of shift register. When
latch pin is set to LOW shift register reads input
values.
• OE – Output Enable, this pin should be connected to
ground for the shift register to output values.
• SRCLR – Shift Register Clear – when this pin is
connected to Vcc, all the data stored in shift register
will be cleared
• SER – Serial data input
• Q7” – Serial data output. This pin outputs serial data
given to SER pin. Normally used to connect another
shift register – i.e cascading of shift registers.
All the segments of 7 segment display are connected to
the parallel data output pins of the shift register. Clock,
latch and serial data pins of the shift register are
connected to arduino digital pins 6,5 & 4 respectively.
Each of the four common anode pins are connected to a
unique arduino pin (9,10,11 and 12) through a 220Ω
resistor to limit the current.
1. Construct the given circuit shown in figure 6-4.
2. Write the code provided below.
#include "Timer.h" //include timer
library
Timer t; // craete a timer object
long number = 0; //declear the
variables
int first_digit = 0;
int second_digit = 0;
int third_digit = 0;
int fourth_digit = 0;
int timer_event = 0;
int CA_1 = 12;
int CA_2 = 11;
int CA_3 = 10;
int CA_4 = 9;
int clk = 6;
int latch = 5;
int data = 4;
int count = 0;
int digits[4] ;
int CAS[4] = {12, 11, 10, 9};
byte numbers[10] {B11111100,
B01100000, B11011010, B11110010,
B01100110, B10110110, B10111110,
B11100000, B11111110, B11110110};
//byte combinations for each number 0-
9
void setup() {
Serial.begin(9600); //serial start
and pin config
pinMode(CA_1, OUTPUT);
pinMode(CA_2, OUTPUT);
pinMode(CA_3, OUTPUT);
pinMode(CA_4, OUTPUT);
pinMode(clk, OUTPUT);
pinMode(latch, OUTPUT);
pinMode(data, OUTPUT);
digitalWrite(CA_1, HIGH);
digitalWrite(CA_2, HIGH);
digitalWrite(CA_3, HIGH);
digitalWrite(CA_4, HIGH);
Serial.println("please Enter a number
from 0 to 9999");
}

void loop() {
t.update(); //timer update
if (Serial.available()) { // read
from serial
t.stop(timer_event); //stop timer
if anythign to read
cathode_high(); // blank the screen
String s = Serial.readString();
//read the serail value
number = (long)s.toInt(); //convert
it to int
if (number > 9999) { //check the
number is 0-9999
Serial.println("Please Enter
Number Between 0 - 9999");
} else {
break_number(number);
timer_event = t.every(1,
display_number); // start timer again
}
}
}
void break_number(long num) { //
seperate the input number into 4
single digits
first_digit = num / 1000;
digits[0] = first_digit;
int first_left = num - (first_digit *
1000);
second_digit = first_left / 100;
digits[1] = second_digit;
int second_left = first_left -
(second_digit * 100);
third_digit = second_left / 10;
digits[2] = third_digit;
fourth_digit = second_left -
(third_digit * 10);
digits[3] = fourth_digit;
}
void display_number() { //scanning
cathode_high(); //black screen
digitalWrite(latch, LOW); //put the
shift register to read
shiftOut(data, clk, LSBFIRST,
numbers[digits[count]]); //send the
data
digitalWrite(CAS[count], LOW); //turn
on the relevent digit
digitalWrite(latch, HIGH); //put the
shift register to write mode
count++; //count up the digit
if (count == 4) { // keep the count
between 0-3
count = 0;
}
}
void cathode_high() { //turn off all 4
digits
digitalWrite(CA_1, HIGH);
digitalWrite(CA_2, HIGH);
digitalWrite(CA_3, HIGH);
digitalWrite(CA_4, HIGH);
}

8×8 LED Matrix

LED matrix displays can be used to display almost


anything. Most modern LED sign boards uses various
types of matrix boards with controllers. In this tutorial we
are going to interface a single color 8×8 LED matrix with
Arduino and display few characters in it.

8×8 matrix consists of 64 dots or pixels. There is a LED


for each pixel and these LEDs are connected to total of 16
pins. You can identify the pin out and circuit diagram of it
using the following figure.

Figure 6-5. 8x8 Dot Matrix Pin Out Diagram


As you can see all anodes of same row is connected to
one pin and all cathodes of same column are connected to
another pin.We have 8 row pins and 8 column pins. If a
positive voltage is applied to R1 pin and negative to C1,
we can see that the first pixel turns on. If we apply
negative to C2 then the second pixel turns on. Like this
we can turn each pixel by hanging the supply pins.
However we have 64 supply combinations, and doing it
manually is practically impossible. This is why Arduino is
interfaced with the 8×8 matrix.

1. Construct the circuit diagram below.

Figure 6-6. 8x8 Dot Matrix and 74HC595 to Arduino


board
2. Write the code and upload it to Arduino board.
int latchPin = 4; // pis connected to
shift registors
int clockPin = 5;
int dataPin = 3;
int pins [8] = {6, 7, 8, 9, 10, 11,
12, 13}; // common cathode pins
byte A[8] = { B00000000, // Letters
are defined
B00011000,// you can
create your own
B00100100,
B01000010,
B01111110,
B01000010,
B01000010,
B00000000
};

byte B[8] = { B00000000,


B11111100,
B10000010,
B10000010,
B11111100,
B10000010,
B10000010,
B11111110
};

byte blank[8] = { B00000000,


B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000
};
byte R[8] = { B00000000,
B01111000,
B01000100,
B01000100,
B01111000,
B01010000,
B01001000,
B01000100
};

void setup() {
Serial.begin(9600); // Serial begin
pinMode(latchPin, OUTPUT); // Pin
configuration
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
for (int i = 0; i < 8; i++) { // for
loop is used to configure
//common cathodes
pinMode(pins[i], OUTPUT);
digitalWrite(pins[i], HIGH);
}
}

void loop() {
for (int k = 0; k < 1000; k++) { //
showing each letter for 1 second
display_char(A);
}

for (int k = 0; k < 1000; k++) {


display_char(B);
}
for (int k = 0; k < 1000; k++) {
display_char(R);

// add more letters show method here


}
void display_char(byte ch[8]) { //
Method do the multiplexing
for (int j = 0; j < 8; j++) {
digitalWrite(latchPin, LOW);
digitalWrite(pins[j], LOW);

shiftOut(dataPin, clockPin,
LSBFIRST, ch[j]);
digitalWrite(latchPin, HIGH);
//delay(1);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin,
LSBFIRST, B00000000); // to get rid
//of
flicker when
digitalWrite(latchPin, HIGH);
digitalWrite(pins[j], HIGH);
}
}

Laboratory Task:

1. Make necessary changes on the 4-Digit 7-Segment to


make it as a Counter with a second delay.
2. Make necessary changes on the 8x8 Dot matric that
will display the characters “U” – “I” – “C” repeated
with a second delay.

References:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy