Okay, so now we see how the brightness of an LED
On most Arduino boards (those with the ATmega168
or ATmega328), PWM is available on pins 3, 5, 6, 9, 10,
and 11. On the Arduino Mega, it works on pins 2-13 and
44-46. Older Arduino boards with an ATmega8 only
support PWM on pins 9, 10, and 11. On the Teensy 3.1
microcontroller that I typically use, PWM is available on
pins 3, 4, 5, 6, 9, 10, 20, 21, 22, 23, 25, and 32.
So, as you can see, on typical microcontrollers there
are only a small number of PWM outputs available for
driving LEDs. If you only want to drive single color LEDs,
you may be okay, but if you want to drive a large number
of RGB LEDs the outlook is bleak.
FIGURE 2. The demonstration hardware.
volts; assume we want 20 mA (0.02 amps) of current for
the LED, and the voltage drop across the LED is 1.8 volts.
Using Ohm's Law, we can calculate the required resistance
with the formula:
R = (Vs - Vf) / I
There are many options available for driving larger
numbers of LEDs using hardware external to but
controlled by a microcontroller. If you search the Internet,
you will see many examples. Many designs use 74HC595
shift register chips to drive the LEDs, but my current
solution of choice is the Adafruit 24-channel 12-bit PWM
LED driver with SPI interface (product #1429; available for
$14.95). With its 24 channels, you can control 24 single
color LEDs or eight RGB LEDs with the added advantage
of 12-bit PWM, giving finer grain control than the eight-bit
PWM described previously.
which works out to be around 160 ohms. If the resistor
value you calculate turns out not to be a standard value,
pick the next larger value to be safe.
Qty Part Description Source
1 Display 1 Common anode 8x8 RGB LED matrix eBay
1 U2 24-channel PWM controller Adafruit
1 U1 Teensy 3.1 controller pjrc.com
8 R1-R8 4.7K 1/4 watt resistor Radio Shack
8 Q1-Q8 P channel power MOSFETs SparkFun
1 Breadboard RadioShack
1 USB cable with five-pin micro-B plug
for connecting Teensy to a computer
or USB power supply pjrc.com
1 Optional USB power supply
capable of at least 1A 5V RadioShack
An additional advantage is that each PWM output
provides constant current, so current-limiting resistors are
unnecessary. In fact, one resistor on this driver board
controls the current through all channels which is set at
the factory to 15 mA. Up to 30 mA of drive current per
channel is possible by changing the resistor.
NOTE: This device is a current sink. It sinks
current to ground; it cannot source current.
The Adafruit device is really just a breakout
board for the TLC5947 controller chip from TI.
This breakout board makes all of the TLC5947
signals available in an easy-to-use configuration
without having to deal with surface-mount
The TLC5947 chip is a cascadable shift
register with built-in PWM counters and PWM
54 April 2015