Control 100 LEDs (by Matlab/Simulink)


for a study project we build up a demonstrator. There are several model-making buildings (e.g. 20cm high houses).

In the hardware models we install around 100 LEDs (light-emitting diodes) which should be controlled by the simulation software Matlab/Simulink in real time. Currently we have the plan to use a couple of boards with which you can control electrical relays by a PC. But these are expensive and I think it's no beauty solution.

So I got the alternative idea to use Arduino hardware for our project. In a magazin I read an article about, but have no experience with it. Addidionally we just have 6 weeks. Then everything [u]must[/u] be ready.

I can't evaluate the feasibility and effort. I searched in the web and also in this forum, but couldn't find out. So I ask you the basics.

1.) Hardware:

We have about 100 LEDs. Most of them needs 20mA. Some more needs a higher electric current, up to 150mA. All LEDs needs a voltage of 5V. We need a possibility to control them (on/off only, no brightness value). The best would be if we can control them individually. If we make some LED groups, we need at least 40 output pins. The standard Arduino has not so much out pins. Is there a Arduino version with 40 up to 100 out pins? Maybe in combination with a hardware extension? (For the few LEDs with higher need of current we could interpose small relais or transistors.)

There seems to be possibilities, as I see in the video Arduino + HT1632 LED Panel Spectrogram.

Can you say us what's the explicid name of the needed hardware? Maybe also a cost estimate.

2.) Software:

We use the simulation software Matlab/Simulink. In most easy case, we just insert an output block there, add an input (1 or 0) and the hardware pin of the Arduino goes on or off. In the Matlab website I found a library with which this seems to be possible. Arduino Target - Develop applications for the Arduino platform using Simulink.

Is it generally possible to control the hardware pins by a PC software in realtime? (Maybe it's only possible to save applications/scetches to Arduino, which run independent of the PC)

If realtime operations are possible - how much is the effort of programming in Arduino language? Just a small setup (pin assignment)? Or a complex code in the loop?

Does somebody have experience with the library Arduino Target?

We would be happy about answers (or links to related threads or websites). If you have questions, just tell us.

Greetings from Germany


Form the hardware point of view you need some form of port extender to give you 100 outputs. Probably this is best done by using 13 chained shift registers. See this for how to do it:- That will handle the case of the 20mA LEDs (remember you need a resistor in line with each LED) For the higher powered LEDs you need to drive them through a transistor or buffer to get the required current.

The software is perfectly possible as well. The code is easy to medium complexity at the arduino end.

As Grumpy says, this is absolutely possible with Arduino and shiftregisters.

You would have individual control of each led (consider each shiftregister as 8 additional out pins)

There's lot's of code samples around for controlling shiftregisters.

Your biggest problem is going to be the wiring of 100 LED's :-)

Thanks for your quick answers and the very helpful tutorial link :)

The last days I spend many hours with Arduino related pages, tons of datasheets and made a simple project with Fritzing (what's nice, but I'm sad that it can't simulate the behaviour).

We decided to order an Arduino beginner package (with breadboard, etc.) to make some practical tests.

Unfortunately we don't know which additionally electronic components we should use. There are so many and we aren't shure, which will fit. The main problem is that we can't connect LEDs directly to the 74HC595 when they need a higher current. (In the Philips data sheet is not even one note about the allowed current. In the Motorola data sheet of the 74HC595 I read about 35mA per pin, but I'm not shure.)

One way would be to use a transistor to enhance the possible current. I read that this transistors (including resistors) are called Drivers or LED drivers.

An other way would be to use similar shift register types that contains drivers or just support higher currents at the pins.

Hour problem is that we don't know which components we could use. I read several data sheets, but I'm not shure if I understand the specifications right. For example if Vcc is 50V I don't know if this meands the maximum and if it's possible to use it for 5V or 12V, too.

Here is a list of our LEDs which we need to handle:

  • 20 mA ..... 30 pieces (or maybe a few more)
  • 40 mA ..... 3 pieces
  • 60 mA ..... 1 piece
  • 80 mA (100 mA maximum currency) ..... 4 pieces
  • 160 mA ..... one group of 8 parallel LEDs (of each 20 mA) ...... alternatively we could attach them in 2 groups of 4 LEDs to 2 pins (= 2x 80mA))
  • 250 mA ..... 2 pieces

Ok, this are not 100 LEDs. We reduced the number, because basically we wanted to buy a couple of expensive controller cards with relais and more controlled LEDs would result in much higher costs.

Additionally we want to control a few electric motors (maybe 4 pieces). Basically it would be ok, when we can switch them just on and off. But more beautiful would be to control its speed. This could be done by the PWM output pins. But also here the interesting question is which transistor (or other electrical component) we should use.

  • One motor is specified for [u]70 mA[/u] common, up to [u]400 mA[/u] maximum.
  • The other 3 (or more?) motors are specified for [u]100 mA[/u] common, up to [u]200 mA[/u].

I suppose the maximum values are the dead end of control and we don't need such a high current. On the other hand it could be that this currents [u]has[/u] to be supported by the electronic, because when starting a motor it needs a higher current for speedup (a simple physical rule).

We have a power supply of 5V and 12V for each 4A.

By my research I found out that these electrical components could be useful:

  • STPIC6C595 ..... - shift register ..... - 8 outputs ..... - up to 100 mA per out pin (all can be "on" at the same time) ..... - 5 V voltage Vcc (I hope this is the right value, because on the first page of the data sheet is written [u]33V[/u] output clamp voltage. So I'm [u]unshure[/u] if this IC fits to our project.) ..... - registers are cascardable

  • STP16CL596 ..... - shift register ..... - 16 outputs ..... - up to 90 mA per output ..... - up to 7V voltage (recommended is only 3 bis 3.6 V (but I suppose this is only for maximum clock frequency what we don't need)) ..... - registers are cascardable ?? ..... - practically: with only one resistor you can control all output currencies. So you don't need a resistor for each LED. ..... - On the other hand: Can this register handle [u]different LED types at its output pins?[/u] I suppose it's possible when we add additional resistors to output pins of LEDs with smaller current. But I'm not shure if this works well with this register.

  • TPIC6595 ..... - shift register ..... - 8 outputs ..... - up to 250 mA per output pin (and all can be "on" at the same time) ..... - 5 V for logic (Vcc) ..... - 45 V "Output Clamp Voltage" ..... - Again [u]I'm not shure[/u] if this register is usable for our project, because we only have 5V and 12V power supply. Maybe this register is only usable for higher voltages. ..... - registers are cascardable

On the other hand we could use the 74HC595 registers and attach "drivers" Maybe some of these types are usable for our case:

  • ULN2803 ..... - this IC contains 8 gains (seems to be transistors) ..... - up to 500 mA current ([u]per pin or amount of all together*??*[/u]) ..... - 50 V output voltage (again I [u]don't know[/u] it this means the maximum or if it's also usable for 5V or 12V)

Also I found an interesting forum thread (German only) with the topic Which transistor for 500mA at 5V.

There were several suggestions. Here are only the listed transistor types: ..... * BC141, BC817, BC337, BD135, BC635, BCW66 H, ULN2803 ..... * BC639 (up to 1A) ..... * IRFD9110 (up to 0.7 A) ..... * IRF7401 (up to 5V at 5A) ..... * FDC6327 (2 transistors in one IC for 5A (each or all??)) ..... * ULN2804 (for 6V up to 15V) ..... * ULN2003D (contains 7 transistors with resistors for direct connection with logic components; up to 500 mA per transistor (I suppose))

Also someone wrote that MOSFETs or Darlingtons are the best choice. Ok, these transistors could be over-the-top, but maybe one of them is usable for our project.

A good page about [u]transistor basics and practical notes[/u] I found here: (German only)

You see, there are so many different electric components (only a few of them I listed) so that I can't decide what to choose. Additionally we need to know which resistors we need for the choosed components, but for now this is just a secondary problem. When we know which registers and driver/transistors we choose, we can search for matching pages in the internet.

There is much information on the Arduino website. But(!) unfortunately there is no comfortable search function like on many other forums. For example I wanted to search for "buffer" (because I don't know what this is). But the visited results of the search function contained only buffers in context of programming. I found no way how to search only in the hardware section. Also it would be good to have an option to search only in the topic titles. So it's a pain to find the wanted information, even I'm shure there are useful threads related to our questions. Maybe the search functionality will be improved in the future.

So, this was much information. Maybe this also helps some other people. We would be very happy if somebody helps us with our choice.

If possible, please tell us only components, which are compatible to breadboards.

I found a nice e-book: The Complete Beginners Guide to the Arduino

There is an example (project 11, page 66) where the Arduino controls a motor. They use the transistor TIP 120 STM (NPN, Darlingston, TO-220, 60V, 5A, 65W) The transistor specification is about 60 V, but in the example it's just used with 3.3 V and it works. So I suppose this is a usable choice for our motors (although this should be overkill) and additionally in the example I see which resistor values will (could) fit. Also we could handle the 250 mA LEDs with it. The transistor costs just 0.30 Euro.

If you think this transistor is bad for our case, feel free to say it ;)

That is an excellent book and should get you on your way with your project.