You are on page 1of 3

Arduino Workshop http://www.thebox.myzen.co.uk/Workshop/LED_Matrix.

html

Arduino What choices do you have when trying to make an LED matrix and how do you go
about driving them.
Workshop
INTRODUCTION ROTARY MAX MOTORS 1 MOTORS 2 MOTORS 3
MOTORS 4 LED SENSING LED MATRIX

LED Matrix
The LED matrix, while not an absolute beginners projects, is one all must come to grips with
sooner rather than later. However, it includes some concepts that can take some getting used to.
So let’s see what a LED matrix is and how to make one.

A matrix is an arrangement of objects, in this case LEDs, arranged in a grid of rows and columns.
This is just the electrical topology, physically it can be arranged in any pattern or grid as you see
fit. The point is that with a matrix arrangement we can control a lot of LEDs with just a few output
pins. The number of LEDs you can control is the product of the number of columns and rows.
That is, suppose you have four columns and six rows you can control 4 X 6 = 24 LEDs. The most
usual arrangement is an eight by eight matrix that gives a total of 64 LEDs from 16 output pins.
There are ways of reducing this requirement even further as we will see later on.

One of the main points about a matrix is that we can’t control all the LEDs at the same time. You
can only turn on the LEDs that lie on one row or columns at any instant. Whether it is a row or
column depends on how the matrix is wired up. What ever way round you have it you can only
have one set on at a time. However, you can play a trick, by flashing each one in turn fast enough
so that they appear to be on all at the same time. This is done by the persistence of vision of the
eye, and if it is done fast enough it doesn't appear to be flickering.

The basic idea is that both ends of the


LED are under control, it is only when
the anode is high and the cathode is low
that the LED lights up. Here we see one
LED lit (green).

1 de 3 25/11/2018 08:44 p. m.
Arduino Workshop http://www.thebox.myzen.co.uk/Workshop/LED_Matrix.html

Software
There
If you
int The
IfTo
Notice
are
There
want
to
you
rowCount animate
drive
column
Row
twohave
toare
that
=ways
source
drive
a0;higher
matrix
two
sink
what
the of
aways
circuit
walking
matrix
circuit
making
you
current
depends
ofare
can
making
can
with
bit
sure
displaying
requirements
use
on
be
isan
that
ahow
the
aawalking
arduino
high
matrix,
this
ULN2803
the
onsided
function
matrix
the
one
with
you
row matrix
driver
on
must
which
the
scanning
isthe
iswired
LEDs
called
use
like
all
rows,
consists
you
an
the
up
If
or
you
regularly,
we
external
at
column
but
have
ULM2981
are
each
of
have
basically
eight
using
tostep
two
do
scanning.
driver
oneDarlington
is
or
you
the
columns
is
it
toBCR450
for
to
has
may
column
keep
have
the
With
tohave
changing
low
do
current
drivers
an
however
is
each
two
then
to
fed
interrupt
use
data
things.
with
source
conveniently
twoan
these
isdata
external
timer
orare
that
call the
byte rowPin[ ] = { 2, 3, 4, 5, 6, 7, 8, 9}; // change these to the pins you use
1) Change
function
currentinthe
more
driver
define
supplied
one
the
sink.
and
data
expensive
LEDs
for
package.
the
the
Despite
in
both
topattern
other
the
currently
onecurrent
the
The
than
some
side
isdisplayData
of
to
collective
current
of
LEDs
on.
tutorials
have
source
the itthat
matrix
sink
as
and
current
suggesting
array
part
you
circuits.
sink.
and
see.
of
every
that
the
a In
walking
It
otherwise,
these
main
eight
this
is easyexample
chips
loop.
refreshes
bitenough
applied
you
can
Using
LEDseach
will
switch
or
tointerrupts
to
on
any
over
use
row
the
the
is
multiple
adriver
stress
adjacent
about
PNP
rowhas light
transistor
the
has
650mA
ofthe
side.
arduino
eight
to
up.advantage
supply
Note
A
ator
walking
any
by
P-channel
that
the
many
oneof
current
the
bit
time
nottimes
isbeing
FET
and
for easy
byte colPin[ ] = { 10, 11, 12, 13, 14, 15, 16, 17}; // note pins 14 to 17 are the analogue pins used in
2) to
Know
above
disrupt
so
torefreshes.
up
when
simply
the
supply
allows
towith
absolute
eight
toaathe
change
other
sequence
However,
maximum
LEDs
drive
limit
program
them.
at
for
where
ifany
the
current
you
thedisplay
one
functions
rows.
try.
there
time
of
These
These
is
will
650
where
one
but
tutorials
flicker
/ also
different
8
it =
as
can80mA
invert
the
orbe(one
pause
columns
abit
the
per
bit
on
that
if
tricky
signal
LED.
the
the
high
changes
only
official
rest
However
and
so
line
have
the
ofcomplex
(row)
position
Arduino
the
walking
to in
stuff
sink
has
practice
to
each
site)
the
in
to
one
setyou
supply
current
step
up
are
pattern
this
main
the
very
of(source)
istimer.
for
the
limited
must
badoneandAlso
be
the
LED.
byawill
spending
the
a digital mode
aeventually
longwalking
amount
loop
time
sequence.takes
destroy
inofzero
ancurrent
longer
So
interrupt
sent
your
a walking
from
that
the
Arduino
service
arduino
the
the onerefreshTime
Arduino.
although
is
routine
pins
a lineon is
of
you
the
generally
to
bits
might
execute.
rows
thatcanthink
are
notsource.
all
aitgood
current
zero
works This
idea.
except
for
forshould
Putting
some
two
one,LEDs
time
be
this
itless
inposition
where
eventually
the
thanmain
as40mA.
changes
the
loop
the Arduino
Where
isateasyas to do,
byte displayData [ ] = { B11111111, B10000001, B10111101, B10100101, B10100101, B10111101, B10000001,
Changing
simply
will fail.
an In
each
set
the
LED
The
this
a LEDs
step
long
normally
other
next
B11111111 }; // display pattern
like
int
isexample
point
best
variable
this:-
takes
done
is that
theacalled
in
maximum
column
current
a function
say scan
refreshDue
through
of with
20mA
is used.
athe
descriptive
of
for
LED
The
continuos
thewalking
must
nextcolumns
name
be
time
current
bit
limited
like
is
you
only
athe
refresh();
walking
need
some
have
fact tothat
how.
torefresh
zero
the
connect
any
The
data
and one
the
simplest
the
that
to display.
LED
ground
data
defines
isway
that
only
Thenof
the
on
matrix
compare
doing display
for
There
defines
this
10000000
one
it is
toshould
are
eighth
with
the
the manycurrent
pattern
a of
be
series
the
variations
held time
is
time
resistor.
in
applied
angiven
means
on
array
However,
this
to
byyou
the
so
millis(),
code
that
rows.
cantheand
you
put
after
Here
resistor
itmore
can
isyou
the
by
access
current
no
must
have
row means
(sink)
itonly
be
called
sequentially.
ininit,
only
sources
the
thethe
this
best
the
line
refresh
isthe
current
in
known
that
This
any
current
function
only
should
way
as
fortakes
the
for
other
onedothen
pulsed
one
LED.
the
theLED
set
current
following:-
current
theat time
any
for
oragain
1) Remove
for
onethe
void LED.
peak
then,
one
01000000
next
the
setup(){ If
current.
instant
Irefresh
walking
itbelieve,
wereofItlike
otherwise
bit
time
is
it’snormal
so
this:-
understandability.
where
thatthen all
toasoverdrive
LEDs
the column
brightness
are Remember
the
off.has
LEDs of
tothe sink
like
what
LEDs
this
theevercurrent
to
would
compensate
youchange
do,
of up it is
todepending
for
your
eight
theproject,
LEDs.
facton that
Link
how
soas formany
they if are
you
2)Increment
LEDs
// setonly
understand
can’t
are
00100000
up on asee
the count
for
atpins
this
any
onewhat
that
animation.
one
aseighth
tells
you
time.
outputs of
are
youThe
the
Link.
doing.
what
time
simplest
state
theythearrangement
do walking
not appear bitwith
as
is in,
bright
anitArduino
also
as tells
LEDs isyou
to
thathave
what
areadata
on
column
fortoall use.
scan
the time.
with an
3) Change
external
for(int However
00010000
the
icurrent
= data
0; there
lines
sinkare
i<8; in
to many
i++){this
reflect form.
other
the nexttypes group
of current
of data. sink circuits like simple transistors or FETs. Note that
4) SetpinMode(rowPin[i],
the
these
00001000
walking
Other driverNotesbitcircuits OUTPUT);
so that are
LEDs inverting,
are on.that means you need a logic one to sink the current. Therefore the
pinMode(colPin[i], OUTPUT);
5) Return walking
00000100
Prefrom Made the
zero function.
pattern has to be a walking one pattern
Matrices
}
00000010
You similar
can buy thingvarious onsizes
the of matrix pre built in a single package. If they are square then
// the rest of the stuff in your setup
This example
Ifthere
00000001
you current
assumes
want
is no to sink
goa walking
problem. forcircuits,
aHowever,
Row one Scan
is driving
ifmatrix
they are current
then you sinks
rectangular needon anthe
then external
columns,
you current
should and
paythesourcedatadriver,
attention is topresented
theusing ato the
} // end of setup
rows. circuit The The
data
like 74LS
is
this:-
the series
bit pattern
of chips that defines what the
two types column anode or column cathode as it will define the way you can drive it. More pattern the matrix shows. Here is an example of
a pattern
complex
void refresh(){ will are happily
produced
the onessink bywith
20mA
a row twoscan. Link LEDs
coloured for if you in eachcan’tposition
see this and animation.
even anLink RGB LED in
so
each position.
byte tempData; they can be connected
directly to the columns.
digitalWrite(colPin[rowCount], LOW); // turn off the LEDs
rowCount ++; // support
Hardware increment to next line
if (rowCount == 8)
If you dorowCount = 0;row
this on both // wrap it round so it only counts 0 to 7
There are chips like the MAX7219 which will do the refreshing for you in hardware. This
// now set the data on the rows
savesand
a lotcolumn
of CPUthen
timeyou
butcan
the chips tend to be expensive. Note that if you use them to
tempData = displayData[rowCount];
drive common
seven the enable
segment line you have to get the correct type of display, in the case of this
displays
for(int i=0 ; i<8; i++){
chip aoncommon
if((tempData
each chip
& 1) ==
and
cathodesodisplay.
0) digitalWrite(rowPin[i], LOW); else digitalWrite(rowPin[i], HIGH);
} reduce the number of
lines to control an 8 by
Brightness
digitalWrite(colPin[rowCount], 8
HIGH); // turn on the LEDs
matrix
Controlling
} // end of refresh down from
the brightness of individual LEDs in a matrix is just about possible using
sixteen
software but to seven. leave time to do much else with the processor. Brightness control is
it doesn't
best done with hardware support. But that’s another page.
Instead of using these
Goodchips
luck. you can also use
shift registers to drive the
matrix, this ca reduce the
pin count even further
down to three lines if you
cascade two of them.
Note this will take longer
to refresh and normally a
shift register can only
source or sink enough
current for one LED.

2 de 3 25/11/2018 08:44 p. m.
Arduino Workshop http://www.thebox.myzen.co.uk/Workshop/LED_Matrix.html

3 de 3 25/11/2018 08:44 p. m.

You might also like