Multiplexing LEDs with Arduino and TLC5940

Controlling Many LEDs with Few I/O Pins

Have you ever built a large LED matrix or cube and realized that your microcontroller doesn't have enough I/O pins to control each LED individually? In this article, we will explore how to control many LEDs with only a few I/O pins using an Arduino Nano, TLC5940 LED driver, P-channel MOSFETs, and resistors.
Introduction The problem arises when we want to control each LED individually in a large matrix or cube. For example, a 10x5 LED matrix contains 50 LEDs, while a 4x4x4 RGB LED cube has 192 LEDs. This is where the concept of multiplexing comes into play.
Building an LED Matrix To demonstrate the principle, let's build a simple LED matrix. We connect all cathodes (negative pins) of all LEDs in one column and repeat this process for all columns. Then, we connect the anodes (positive pins) of all LEDs in one row, making sure that the anodes and cathodes don't touch.
Multiplexing When we want to light up multiple LEDs, we use multiplexing. We light up each row individually and one after the other, but we go through the rows so fast that our eyes don't notice, and we see a static complete picture.
Hardware Components To control the LEDs, we use an Arduino Nano, TLC5940 LED driver, five P-channel MOSFETs (F9540N), one 2k resistor, and five 1k resistors.
Connections The connections are as follows:
  • Gate of MOSFET row A to Nano pin 8
  • MOSFET row B to pin 7
  • MOSFET row C to pin 6
  • MOSFET row D to pin 5
  • MOSFET row E to pin 4
  • TLC pin 28 to column 1
  • TLC pin 1 to column 2
  • TLC pin 2 to column 3
  • ...
  • TLC pin 9 to column 10
Code We use a TLC library from the Arduino playground to simplify the code. The code is available for download, and it includes comments to explain each line.
Results When we upload the code, we see a moving sine wave on the LED matrix. We can also create static images like the word "HOW" or a moving letter "E". By increasing the on time of a row, we can clearly see that it's not one complete picture but single rows lighting up one after the other.
Conclusion In conclusion, controlling many LEDs with few I/O pins is possible using multiplexing and the right hardware components. This concept can be applied to larger LED matrices or cubes, and we will explore this in future articles.


LED Multiplexing is a technique used to control multiple LEDs using a reduced number of pins on a microcontroller or other digital circuitry.
Background In the early days of electronics, LEDs were controlled individually using separate pins for each LED. However, as the number of LEDs in a design increased, so did the number of required pins on the microcontroller or other digital circuitry. This led to increased cost, complexity, and size of the overall system.
Need for Multiplexing The need for a more efficient way to control multiple LEDs arose from the limitations of individual LED control. As designs became more complex and space-constrained, it became clear that a method was needed to reduce the number of pins required while maintaining control over each LED.
How Multiplexing Works In an LED multiplexing system, multiple LEDs are arranged in a matrix with rows and columns. Each row and column is connected to a single pin on the microcontroller or other digital circuitry. By carefully controlling the timing of the signals sent to each row and column, individual LEDs can be turned on and off independently.
Benefits Multiplexing offers several benefits, including reduced pin count, increased efficiency, and simplified design. By reducing the number of pins required to control multiple LEDs, designers can create more compact and cost-effective systems.
Applications LED multiplexing is commonly used in a wide range of applications, including display screens, lighting systems, and automotive electronics. It is particularly useful in situations where space is limited or power consumption must be minimized.


Multiplexing LEDs with Arduino and TLC5940

Introduction:
LED multiplexing is a technique used to control multiple LEDs using fewer pins on a microcontroller. This method can be useful when working with a large number of LEDs and limited I/O pins. In this article, we will explore how to multiplex LEDs using Arduino and the TLC5940 LED driver IC.
What is Multiplexing?
Multiplexing is a method of transmitting multiple signals over a single communication channel. In the context of LEDs, multiplexing involves connecting multiple LEDs to a single pin on a microcontroller and using a technique called time-division multiplexing (TDM) to control each LED individually.
TLC5940 LED Driver IC:
The TLC5940 is a 16-channel, constant-current sink LED driver IC. It has built-in PWM (Pulse Width Modulation) and can be controlled using a serial interface. The TLC5940 can drive up to 16 LEDs with a maximum current of 120mA per channel.
How it Works:
The TLC5940 has two main components: the LED driver and the PWM generator. The LED driver is responsible for sinking current from the LEDs, while the PWM generator produces a high-frequency signal that is used to modulate the current through the LEDs.
Connecting the TLC5940 to Arduino:
To connect the TLC5940 to an Arduino board, you will need to make the following connections:
  • VCC (TLC5940) -> 5V (Arduino)
  • GND (TLC5940) -> GND (Arduino)
  • SCL (TLC5940) -> SCL (Arduino)
  • SDI (TLC5940) -> MOSI (Arduino)
Multiplexing LEDs:
To multiplex LEDs using the TLC5940, you will need to connect multiple LEDs to a single channel on the IC. The TLC5940 has 16 channels, so you can connect up to 16 LEDs in this configuration.
Example Circuit:
Example circuit diagram
Code Example:
The following code example demonstrates how to use the TLC5940 library to control a single LED channel:
        #include 

        TLC5940 tlc = TLC5940();

        void setup() {
          tlc.init();
        }

        void loop() {
          for (int i = 0; i < 16; i++) {
            tlc.setChannel(i, HIGH);
            delay(100);
            tlc.setChannel(i, LOW);
          }
        }
      


Q: What is multiplexing LEDs? Multiplexing LEDs refers to the technique of controlling multiple LEDs with fewer output pins on a microcontroller, such as Arduino.
Q: Why use TLC5940 for LED multiplexing? TLC5940 is a 16-channel PWM LED driver IC that can be controlled using only 3 output pins from the Arduino, making it ideal for LED multiplexing.
Q: How does TLC5940 work with Arduino? The TLC5940 communicates with Arduino through a serial interface, allowing the Arduino to send PWM data to the TLC5940, which then drives the LEDs.
Q: What are the advantages of using TLC5940? The TLC5940 offers high-speed PWM control, 16-channel support, and low power consumption, making it a popular choice for LED multiplexing projects.
Q: Can I use TLC5940 with any Arduino board? No, the TLC5940 requires specific timing and communication protocols, so it's recommended to use it with Arduino boards that have a built-in SPI interface, such as Arduino Uno or Mega.
Q: How many LEDs can I control with one TLC5940? One TLC5940 can control up to 16 LEDs, but you can chain multiple TLC5940s together to control even more LEDs.
Q: Can I use TLC5940 for RGB LED strips? No, the TLC5940 is designed for single-color LED control. For RGB LED strips, you would need a separate IC or a more advanced controller.
Q: How do I connect multiple LEDs to a single TLC5940 output? To connect multiple LEDs to one TLC5940 output, use a current-limiting resistor and wire the LEDs in series or parallel configurations.
Q: Can I control the brightness of each LED individually with TLC5940? No, the TLC5940 controls all LEDs connected to a single output pin with the same PWM value. For individual brightness control, you would need separate ICs or more advanced controllers.
Q: What is the maximum current rating of TLC5940? The TLC5940 has a maximum output current per channel of 120mA, and a total maximum output current of 1.9A.




Rank Pioneer/Company Contribution
1 Texas Instruments (TLC5940 creator) Developed the TLC5940, a popular LED driver IC used in multiplexing applications.
2 Adafruit Industries Created the TLC5940 breakout board and provided extensive documentation and examples for using the chip with Arduino.
3 SparkFun Electronics Developed the SparkFun LED Driver Breakout, a popular board for driving LEDs with the TLC5940 and Arduino.
4 Massimo Banzi (Arduino co-founder) Contributed to the development of the Arduino platform, making it easier for makers to work with multiplexed LEDs using the TLC5940.
5 Phil Burgess ( Adafruit's founder) Created various tutorials and projects showcasing the use of TLC5940 with Arduino, popularizing its adoption in the maker community.
6 Nate Seidle (SparkFun's founder) Developed various LED-related products and tutorials, including those using the TLC5940 with Arduino.
7 Jonathan Oxer (Freetronics founder) Created various Arduino shields and modules, including some that use the TLC5940 for LED driving.
8 Dave Jones (EEVBlog creator) Produced in-depth reviews and tutorials on using the TLC5940 with Arduino, helping to educate the electronics enthusiast community.
9 Morgan McGuire (LED lighting expert) Developed various LED-related projects and shared knowledge on driving LEDs efficiently using multiplexing techniques with the TLC5940.
10 Jeri Ellsworth (maker and YouTube personality) Showcased creative uses of multiplexed LEDs in projects, inspiring others to explore this technology using Arduino and the TLC5940.




Multiplexing LEDs with Arduino and TLC5940
Overview Multiplexing is a technique used to control multiple LEDs using fewer pins on the microcontroller. The TLC5940 is a 16-channel PWM LED driver that can be used with Arduino to multiplex LEDs.
Hardware Requirements
  • Arduino Board (e.g., Arduino Uno)
  • TLC5940 IC
  • LEDs (16 or more)
  • Resistors (220Ω - 1kΩ each)
  • Jumper wires
TLC5940 Pinout
Pin Description
VCC Supply voltage (5V)
GND Ground
SIN Serial data input
SCLK Serial clock input
XERR Error flag output (active low)
OUT0-15 LED driver outputs
Arduino Pin Connections
Arduino Pin TLC5940 Pin Description
D2 SIN Serial data input
D3 SCLK Serial clock input
Multiplexing LEDs
  1. Connect the TLC5940 to the Arduino as shown above.
  2. Connect each LED anode to a TLC5940 output pin (OUT0-15).
  3. Connect each LED cathode to a resistor, then to GND.
  4. In your Arduino sketch, use the `TLC5940` library to set up the IC and control the LEDs.
TLC5940 Library Functions
Function Description
`TLC5940.begin()` Initialize the TLC5940 IC.
`TLC5940.setAllPWM(uint16_t pwm)`
`TLC5940.setPWM(uint8_t channel, uint16_t pwm)` Set an individual LED output to a given PWM value (0-4095).