# Controlling 100 LEDs with a PC?

• C/++/#
I would like to turn on and off 100 external (non screen) LEDs through my PC.
I was thinking to assign each pin on my serial port an LED, because apparently you can control the power on serial port pins if I understand correctly.

The problem is that even if I do control each pin on a port, what if I have more LEDs than I have pins to control them?

For example how would one control 100 LEDs with 32 pins?

phinds
Gold Member
2021 Award
... apparently you can control the power on serial port pins if I understand correctly.
You do not understand serial ports at all. Check out what the 9 pins in a PC serial port do:
https://en.wikipedia.org/wiki/Serial_port

You do not understand serial ports at all. Check out what the 9 pins in a PC serial port do:
https://en.wikipedia.org/wiki/Serial_port
Ah I see, so in that case it would communicate one bit at a time. Even then how would I create a circuit that cycles through each LED and turns it on or off?
Each LED would be like a variable that needs to maintain its value.

phinds
Gold Member
2021 Award
You are going to need some kind of external circuit that is controlled by the pc and then itself controls the LEDs. There are various kinds around but I have no recommendation.

I would like to turn on and off 100 external (non screen) LEDs through my PC.

You are going to need some kind of external circuit that is controlled by the pc and then itself controls the LEDs.

Two possible ways would be:
1) Communicate using the PC's USB port to a separate "USB interface board." The board would be treated as a peripheral device--via HID protocol.
2) Communicate to an Arduino (or equivalent).

There are a lot of variables here: how powerful are the LEDs, how many would you control at the same time, how many are on at the same time, ....

Two possible ways would be:
1) Communicate using the PC's USB port to a separate "USB interface board." The board would be treated as a peripheral device--via HID protocol.
2) Communicate to an Arduino (or equivalent).

There are a lot of variables here: how powerful are the LEDs, how many would you control at the same time, how many are on at the same time, ....
Basically the small current coming from the computer would activate a transistor, so the power supply would be separate.
The LEDs don't need to be updated at the same time, they can be updated iteratively, 0,1,2,3,4....

I know that I can achieve this with a pin for each LED's transistor but is that really the best solution?

Tom.G
Gold Member
I know that I can achieve this with a pin for each LED's transistor but is that really the best solution?
Welll... it depends.

Usually high-count LED's are wired as a matrix.
To do that, think of your 100 LEDs as a 10×10 array.
Each row of LEDs has one of their pins connected to a bus.
Each column of LEDs has their other pin connected to a bus.
This allows you to uniquely address 100 LEDs using 20 wires; apply power and ground to a row and a column and one LED will turn on.
You sequentially energize the ON LEDs rapidly enough that your eye doesn't detect they are really switching on and off.
This approach is called Multiplexing.

The other approach is individual control of each LED, with a wire and usually with some memory element (a flip-flop or a storage register) for each LED.

• Multiplexing
• requires continuous refreshing, i.e. it is a dynamic solution so a faster driver and controller is needed.
• the perceived brightness is proportional to the current and to the duty cycle of each LED
• only one LED is ON at a time so little power is needed
• simpler wiring
• fewer parts for the driver
• Individual Control
• can use a slower driver and controller since it is used only when a display change is needed
• since the duty cycle is 100%, brightness is proportional only to LED current
• high power needed to supply all the LEDs at once.
• more wiring but easier to troubleshoot
• more parts for the driver

In any case, you are going to need more control lines than the typical computer has these days. That means some sort of additional electronics, whether it is a plugin card to a tower or rack computer, an external microcomputer with sufficient I/O, or a few ICs wired together on a breadboard.

A work-around for the Multiplex brightness problem is to increase the LED current to compensate for the short ON time (duty cycle). Of course there are limits to this to keep the LEDs cool enough to survive. Generally, keep the average current in an LED well within its maximum rating. If the 1% duty cycle just does not meet your needs for brightness, it can be increased up to 10% with a few more ICs for the driver and some careful programming.

Almost all displays larger than 16 elements use the Multiplexing approach, even the screen you are reading this on is multiplexed.

If you could explain more about your project, perhaps we could help with some of the unstated trade-offs.

Cheers,
Tom

p.s. An alternative to a 10×10 array is to use four 5×5 arrays which needs 14 wires instead of 20... but it is harder to think about!

Klystron, russ_watters, .Scott and 1 other person
Welll... it depends.

Usually high-count LED's are wired as a matrix.
To do that, think of your 100 LEDs as a 10×10 array.
Each row of LEDs has one of their pins connected to a bus.
Each column of LEDs has their other pin connected to a bus.
This allows you to uniquely address 100 LEDs using 20 wires; apply power and ground to a row and a column and one LED will turn on.
You sequentially energize the ON LEDs rapidly enough that your eye doesn't detect they are really switching on and off.
This approach is called Multiplexing.

The other approach is individual control of each LED, with a wire and usually with some memory element (a flip-flop or a storage register) for each LED.

• Multiplexing
• requires continuous refreshing, i.e. it is a dynamic solution so a faster driver and controller is needed.
• the perceived brightness is proportional to the current and to the duty cycle of each LED
• only one LED is ON at a time so little power is needed
• simpler wiring
• fewer parts for the driver
• Individual Control
• can use a slower driver and controller since it is used only when a display change is needed
• since the duty cycle is 100%, brightness is proportional only to LED current
• high power needed to supply all the LEDs at once.
• more wiring but easier to troubleshoot
• more parts for the driver

In any case, you are going to need more control lines than the typical computer has these days. That means some sort of additional electronics, whether it is a plugin card to a tower or rack computer, an external microcomputer with sufficient I/O, or a few ICs wired together on a breadboard.

A work-around for the Multiplex brightness problem is to increase the LED current to compensate for the short ON time (duty cycle). Of course there are limits to this to keep the LEDs cool enough to survive. Generally, keep the average current in an LED well within its maximum rating. If the 1% duty cycle just does not meet your needs for brightness, it can be increased up to 10% with a few more ICs for the driver and some careful programming.

Almost all displays larger than 16 elements use the Multiplexing approach, even the screen you are reading this on is multiplexed.

If you could explain more about your project, perhaps we could help with some of the unstated trade-offs.

Cheers,
Tom

p.s. An alternative to a 10×10 array is to use four 5×5 arrays which needs 14 wires instead of 20... but it is harder to think about!
Thanks for the suggestions, I used LEDs as an example of an external device I would like to control, but since I need to be more specific, I would really like to control about 16 electromagnets, possibly more.

I'm not sure if multiplexing would work in this case since only one electromagnet could be on at a time, so some sort of individual control may be necessary.
Let me know what you think, thanks!

CWatters
Homework Helper
Gold Member
Your PC has a serial port? How old is it?

Rive
For a fast/cheap project I would pick an USB-SPI or USB-I2C cable and a bunch of addressable IO expander boards (with matching interface).
Some fiddling might be needed on the outputs to bring them up one by one to the requirements of the LEDs (or electromagnets or whatever).

.Scott
Homework Helper
Thanks for the suggestions, I used LEDs as an example of an external device I would like to control, but since I need to be more specific, I would really like to control about 16 electromagnets, possibly more.

I'm not sure if multiplexing would work in this case since only one electromagnet could be on at a time, so some sort of individual control may be necessary.
Let me know what you think, thanks!
First, in a 4x4 with electromagnets, any combination within a single row could be on.
But there are problems. You don't want to connect your PC circuitry directly to an electromagnet. You need some circuitry in between that is more robust and able to withstand current spikes. But you can still set them up in a matrix. Each EM will likely require a cap and diode to keep the current flowing between refresh cycles.

Do you want to build this gizmo - or buy one. There really are many ways to do this.

Do you want to build this gizmo - or buy one. There really are many ways to do this.
I would really like to just buy it and save time. The problem is I don't really know what to buy. I'm leaning towards a micro controller like PI3, but I want to be sure.

A Pi3 will kind of work, but that is a little different than controlling with a PC - With a Pi you can make a standalone or PC connected system, but each element makes it more complicated.

OK - so you have 16 or more electromagnets, you just want to turn them on and off, correct?
Anything else?

Could you make a block diagram or something?

A Pi3 will kind of work, but that is a little different than controlling with a PC - With a Pi you can make a standalone or PC connected system, but each element makes it more complicated.

OK - so you have 16 or more electromagnets, you just want to turn them on and off, correct?
Anything else?

Could you make a block diagram or something?
Here is a diagram I made that may make things clearer.

#### Attachments

• electromagnet circuit.jpg
28.9 KB · Views: 322
You might try looking into MIDI show controller (MSC) sequencers like those used for light shows and to trigger pyrotechnic displays.

Klystron
A complete (product) like this seems to fit the bill.... 24 Channel USB - I/O Module - This is powered by the USB, so see my note below about the ElectroMagnet load.

This can probably be done DIY for about $100. For PC control you can use a USB-GPIO ( General Purpose Input Output) Bridge. With at least 16 channels or Pins available. Example from Sparkfun You then need to find out what the power requirements are for the Electromagnets. And develop a simple driver circuit, or possibly a driver IC will work, since the outputs of the interface / controller probably can not support the load of the EMs. kolleamm A complete (product) like this seems to fit the bill.... 24 Channel USB - I/O Module - This is powered by the USB, so see my note below about the ElectroMagnet load. This can probably be done DIY for about$100. For PC control you can use a USB-GPIO ( General Purpose Input Output) Bridge. With at least 16 channels or Pins available.
Example from Sparkfun

You then need to find out what the power requirements are for the Electromagnets. And develop a simple driver circuit, or possibly a driver IC will work, since the outputs of the interface / controller probably can not support the load of the EMs.
That first product from Amazon seems to be exactly what I'm looking for!
(Although I'm not sure it has an SDK, since I need to write code for it)
I have no problem in developing the driver circuit, all it really needs is a transistor between one of the wires leading to the electromagnet that will control the flow of current, and possibly some EM noise protection.
I'm guessing if I wanted to control even more electromagnets I could just extend my USB ports and plug in more of these devices.
Thanks a lot

Last edited: