How to wire up 6 led's on one 20mA pin question - SORTED

Edit 02/11/2010


And what a buzz when it worked.

Thank you all so much for your help, especially ignoblegnome (+others). I have yet to fit the board to my bot, but will do that tomorrow.

Although it uses the same chassis as my first robot, it is entirely different. I am trying to do an AmandaLDR as fritsl's, (except with LED's), so I will probably put it in the robot section (if it works).


I want to put 6 led's on my bot, in a row, and have them flash at a certain interval. I think the coding will be fine, but I have a problem with wiring.

I would rather not put each led onto a seperate pin on my microcontroller, but I can't put all 6 onto one pin, because of the current.

The array of 6 will draw 60 mA, and each pin is only rated for 20 mA.

Can someone suggest a way around it please, bearing in mind I know nothing about electronics

I'm told this is how they should be wired up.



Thank you.

perfect opportunity to learn a basic transistor circuit

This is why the picaxe is so popular with beginners. The manuals explain this nicely. I stole a circuit schematic from a different source: wikipedia.


Imagine your controller is the switch. When the output pin goes high, a current flows through the Base to the Emitter of the transistor. This only needs to be a tiny current. That's why a 1000 Ohm resistor sits there. This protects the transistor against currents higher than say 10 mA.

The tiny current "opens up" the big flow of electrons though the lamp. The transistor is acting as a switch. Replace the lamp with your LED/resistor pair(s). The LED current, from Collector to Emitter, can be hundreds times larger than the tiny current coming from the micro controller. But in your case, we only need to ramp it up from ca 5 mA to 60 mA. The resistors in series with the LEDs will limit the resulting current.

So, will this enable you to actually build this solution? Probably not. You will further need to learn:
- which transistor to choose;
- which pin is which;
- how to hook up all components so they form this circuit;

You're a smart guy. And you know where to ask for help. Learn it. And like it.

Many thanks, rik, for taking

Many thanks, rik, for taking the time and trouble to do that for me. I think I may actually see it (surprisingly).

Am I right in thinking that the array as shown in my picture goes in where the “lamp symbol” is in your circuit? I presumably then just connect the positive to a live pin and the negative to the corresponding data pin? Is the switch shown in the circuit a software switch for me?

I think I can also see the connections for the transistor, presumably where the blue arrow is above, is the flat side of a transitor, but how do I work out what transistor I need? (I have a few old circuit boards with transistors on, so I may have one ).

I’ll do some more searching and see if there is any Circuit Designing Software available (free!).

Any NPN transistor would

Any NPN transistor would probably do as a switch. I bought 20 x 2N3904 from eBay at $0.99
Remember, you still need the current limiting transistors and probably a pulldown resistor at the base as well.

As for circuit design software i use 

Transistor tutorial

There is even a link on that page that shows you some common transistors and their relevant specs.

Many thanks for that, Geir,

Many thanks for that, Geir, I just found that one before reading your post. I’ll try it out.

Thanks, birdmun, I’ll have a

Thanks, birdmun, I’ll have a good read.

If you’re powering this

If you’re powering this array from a stable voltage source like a plug-in transformer then the array you have is fine, but if you’re going to run this off batteries or anything where the voltage will drop gradually over time this arrangement will keep your LEDs bright for longer (at the cost of higher current consumption). Working off the drawing you posted, your LEDs have a forward voltage drop of 2.17V each?


R1-R6 control the amount of current each LED receives, you can vary them to trade brightness for reduced current. Giving each LED it's own limiting resistor helps keep them at the same brightness, and allows you to mix-and-match different coloured LEDs, but it does require a few more parts and more circuit space.
R7 controls the NPN transistor's base current, which in turn controls the collector current. The ideal value will depend on the actual transistor chosen, but 1kΩ as rik posted is almost always a good value for transistors of this size running @ 5V.
As for the transistor itself, the main thing you need to make sure of is that the collector current (Ic) can handle more than the LEDs require - I'd aim for anything over 200mA. The other transistor specs can be useful, but that's the critical one in this case.

Thank you, Telefox. That

Thank you, Telefox. That looks perfect.

The batteries to my M/C are 6v 3300 mAh, but the M/C pins are only rated at 20mA. The power supply will be 5v regulated, and the LED’s have a forward voltage of 2.2v (according to their datasheet).

I think that’s it, I’ll have a rummage in my shed tomorrow and see if I can come up with a suitable transistor, the resistors I already have.

Thank you all so much for your help, I’ll let you know how it pans out.

Since the NPN transistor is

Since the NPN transistor is acting like a buffer between the LED circuit and the micro you could actually connect the +5V on the above schematic directly to your 6V supply, which would reduce the load on your regulator and give your LEDs more available voltage.
Using the 6V supply the 3 x 2 LED array becomes a more attractive option too: 6V - 2*2.2V - 0.7V = 0.9V across the limiting resistors (0.7V is a pessimistic value for voltage drop across the transistor). If your battery voltage drops by 0.45V your LEDs will still receive at least half the original 20mA.
If you stick with one resistor per LED you end up with: 6V - 2.2V - 0.7V = 3.1V across the limiting resistors, so your battery voltage has to drop by at least 1.55V before the LED current drops to half, but you’ll be consuming more power overall.

I guess the LED arrangement you should choose depends on whether LED brightness or power consumption is the major concern. If you’ll be keeping the LEDs on for a large portion of the time you might want to go for the efficient 3 x 2 array, but if you want nice, bright flashing LEDs the 1 x 6 is best.

Sorry to make things more complicated, but I think you’ll pick up some useful bits and pieces that will help with other circuits too =)

I’d say use a 74hc595 shift

I’d say use a 74hc595 shift register…you could control 8+ led’s.

Thanks for the suggestion,

Thanks for the suggestion, voodoobot.

I had to look it up, as it sounded like an alien language, to me! I actually have plenty of spare pins on my board - it has 58 I/O and 16 ADC pins. (Shouldn’t ever run out!). I just wondered if there was a way to do it using one set of pins to make it easier for me to programme. (That’s going to be another big problem for me :(  )

Hi rik. Hope you read this.

Well, I’ve finally got all the bits I need to make this (my first) circuit.

I will be using a 5v positive pin for the positive line in your schematic above, and a data pin for the negative (when it goes low - 0v, it will be grnd).

My question is, can I ignore the switch in the above schematic, and connect the grnd to the emitter on the transistor, and then the positive to both the top of the array and the resistor? So in effect the “switch” will be just between positive and grnd, using the microcontroller. Is that OK?


Notice that rik said replace

Notice that rik said replace the lamp in his schematic with a LED/resistor pair. This is important, because without a current limiting resistor, 5 or 6 volts across your LED will burn it out very quickly!

The way you have your circuit connected is… well, not usual. Normally you will use the microcontroller to control the base of the transistor, rather than the emitter. The reason is that the base only needs a very small current (limited through the 1k res), while the emitter is going to sink the entire current Ice that the LED/resistor pair need.

Since a single LED only needs about 20mA, this may be fine. However, you can control an LED with much less current drain on your microcontroller by allowing it to control the base instead of the emitter.

This would also allow you to use the same output of your micro to control several LEDs (each with its own limiting resistor) with one transistor, as long as you don’t need individual control of your LEDs. For example, if your transistor can source or sink 200 mA, you can run 10 LEDs at 20mA. The microcontroller is connected to the base of the transistor through the 1k resistor. The emitter is connected directly to ground. Each LED is connected to supply voltage (say 5V) through its very own current limiting resistor, and then from the resistor to the collector of the transistor.

Please forgive the quality of the schematic below. I was working from my wife’s computer, and I only had MS Paint at my disposal. Also, it was almost midnight, and I was drinking rum and Coke. However, I believe the quality of my advice managed to maintain a level of sobriety.



Many thanks, IG, for

Many thanks, IG, for breaking off from your supping time, to answer my question. I have to say, I saw no evidence of slurring in your post :wink:

OK, a bit more explanation from me.

I have already connected some led’s/resistors  up to my controller, which work fine. The three pins are grnd, 5v pos, and data. Connecting these to the 5v pos and data pin works fine, as when the pin goes low (0v), using software, it completes the circuit.

I have finished my board to how I think it should be, as shown below.



The red wire goes from the 5v pos pin to the top of the led/resistors array., which in turn go to the collector of transistor. The black wire goes from the grnd pin to the emitter of the transistor.

The white wire, and this is the one I'm concerned about, goes from the data pin to the top of the 1k resistor, which in turn goes to the base of the transistor.

Am I right in thinking that I can turn that side of the circuit on with the data pin using software? (By making the pin go high?)

I'm loathe to try it as I'm scared of blowing up my controller 8-)

Edit   I've just had a thought about using 2 sets of pins. Connect the grnd and 5v pos to one set of pins, so it will be live continuously, and then use another set using the 5v pos and data as the switch in the original schematic. Would that be better?

OK, Kelpy it sounds like you

OK, Kelpy it sounds like you have it.

I don’t think you need two sets of pins from your controller to do this, as you mentioned in your edit. If all the LEDs will be on/off together, there’s no reason to use two data pins.

It sounds like you have the following as your circuit:


The NPN transistor acts as your switch. The 1 kohm resistor at the base helps protect your microcontroller by limiting the current. Even if your digital output pin was set high and grounded through a 1 kohm resistor, it will be safe. Here's why:

Voltage / Resistance = Current

5 volts / 1000 ohms = 0.005 amps, or 5 mA.

Your microcontroller shouldn't have any problem sourcing 5 mA.

When the transistor is turned on with a high signal at the base resistor, your LEDs get a path to ground through the transistor. However, this is isoltated from your signal pin.


Testing before risking your mcu

Consider this test to see i it’s safe for your mcu.

Remove the mcu from the picture. Connect 5V and GND as indicated by IgnobleGnome. Now touch your would-be-connected-to-datapin-wire with the 5V and see if the LEDs light up. Then touch it with GND and see they are off. The LEDs should also be off when the wire is free from any touching.

If you have a current meter (multi thingey), you could put that in series between 5V and your wire. Check if the current stays under 5 mA. Yes? You’re good to go!