Trains.com

Subscriber & Member Login

Login, or register today to interact in our online community, comment on articles, receive our newsletter, manage your account online and more!

Another question of resistance for LEDs

1896 views
13 replies
1 rating 2 rating 3 rating 4 rating 5 rating
  • Member since
    December 2016
  • 168 posts
Posted by speedybee on Saturday, January 7, 2017 7:32 AM

No problem! If you want to operate high currents through all the Arduino pins you can do so with a transistor such as the popular PN2222A.

It basically acts like a switch that can carry much more current than an Arduino pin. Where your LED circuit would connect to ground you can instead connect it to the transistor collector. The transistor emitter connects to ground. At this point, the switch is off, the transistor will not let current through, and your LEDs are dark. Then, when a voltage is applied to the transistor base, the switch is on and the LEDs are lit.

This is useful because the transistor requires very little current to activate the switch but it can carry a lot of current through it. So your Arduino digital pin can go through 4k resistor and then to the transistor base. This limits the Arduino pin current around one little mA and you can have as much as you want (up to 600mA on the PN2222A) flowing through the transistor.

The details of transistor chemistry are kinda complicated but using them is easy. Basically, to use a transistor as a switch, there are two rules:

1. Emitter must be wired to ground, and whatever load you're trying to control gets attached to the collector. You can't have the any load like LEDs or resistors or whatever between emitter and ground.

2. It'll work fine only for simple on/off loads such as LEDs and resistors. Things that behave not simply such as solenoids and motors won't work quite like a simple on/off switch and need additional planning. http://amasci.com/amateur/transis.html if you want a nice intro to transistors! but it can be heavy stuff

 

 

 

  • Member since
    June 2016
  • 81 posts
Posted by Ron Hume on Saturday, January 7, 2017 5:47 AM

Thanks speedybee and all for the helpful responses. It seems that twelve LEDs may stretch the chip a little, so I'll wire three structures with the street lamps circuit that stays on constantly, and nine on the chip for random lighting. That should work.

Ron from down under.

  • Member since
    July 2009
  • From: lavale, md
  • 4,677 posts
Posted by gregc on Saturday, January 7, 2017 4:25 AM

Ron Hume
Am I able to regulate the current on the Arduino? Or is it better to use the 3.5 volt output of the Arduino?

unless your Arduino has a current regulator circuit, the LED current depends on the resistor. 

1 ma is pretty low.   Sound like you've found the resistor value that works (higher is better).

with a higher voltage (5V) you may be able to put LEDs in series with a single resistor; fewer parts and constant brightness. 

greg - Philadelphia & Reading / Reading

  • Member since
    December 2016
  • 168 posts
Posted by speedybee on Friday, January 6, 2017 8:56 PM

edit: Good lord I wrote a lot of text that didn't actually answer your question. To get around 0.5 to 1 mA on a standard little LED, use a resistor of around 4k ohm on a 5V supply or 1.7k ohm on a 3.3V supply. But it depends on the LED voltage drop, as discussed below, which should be in the LED datasheet or you can measure it pretty easily.

 

 

You can't regulate current with the Arduino, you just have to figure out the correct resistor to allow current you want through the LED. It's a fairly easy calculation if you know the voltage drop of your LED.

The standard Arduinos have a 5V power pin and a 3.3V power pin. All of the digital outputs on Arduino Unos, Megas, and most others operate on 5V. I like to use 5V for all LEDs and logic circuitry, because some LEDs have a voltage drop of 3.7V, meaning they cant properly be operated on anything less. You can always drop your voltage and current down with resistors but you can't readily boost it up.

When using LEDs it's important to understand how they work. They do not behave like ohmic devices like incandescent bulbs, resistors, etc. An LED has an (approximately) constant voltage drop. For the common little red/yellow/green LEDs, this is around 2V. If you have 5V on the anode you will have 3V on the cathode. Doesn't matter how much current runs through the LED (unless it is so much that it burns it out and the whole circuit stops working).

LEDs are given a voltage drop and a max current. You must give them a resistor that limits the current running through the LED. Example: Your red LED has a voltage drop of 2.1V. It has a max current of 20mA and you want to supply that. You're using a 5V Arduino output. So:

The LED drops 2.1V from the 5V. The resistor is the only other element between the Arduino and ground; thus the resistor must drop 2.9V. The question is, what resistance will make 20mA run through the circuit?

Ohm's Law: R=V/I. R=2.9/0.02=145ohm

So you need a 145ohm resistor in series with your red LED.

 

Or, say you want two of these red LEDs. You can put them in series, because their total voltage drop will be less than your supply voltage of 5V. Now the total LED voltage drop is 2.1+2.1=4.2, meaning your resistor will drop 0.8V. The same calculation as above shows that your resistor in this circuit needs to be R=0.8/0.02=40ohm.

You can run LEDs in parallel but each LED must have some kind of resistor in series with it and only it. This is because uncontrolled LEDs will gladly let as much current run through them as they can, and then burn out. Even "identical" LEDs should not be run in parallel without a resistor as differences in manufacturing may mean that some of them are getting more than their rated max current.

If you don't know the voltage drop of your LED, it's not a problem, you can just measure it with a voltmeter. Just put it in series with a resistor high enough to be safe (eg, around 700 ohms on 5V) and use a voltmeter to measure the drop across the LED. It won't change a great deal no matter how much current you put through the LED... it might change by a few tenths of a volt but nothing drastic.

  • Member since
    June 2016
  • 81 posts
Posted by Ron Hume on Friday, January 6, 2017 8:31 PM

The LED brightness on a tester is ok at 0.5 or 1ma for oil lamps and candles. Am I able to regulate the current on the Arduino? Or is it better to use the 3.5 volt output of the Arduino? 

  • Member since
    December 2016
  • 168 posts
Posted by speedybee on Friday, January 6, 2017 5:50 PM

More details are required about what you're trying to do. What LEDs are these, do you have the datasheets? Do you want them to be individually controlled? And how bright do they need to be? Personally I run most LEDs on my layout between 3 and 10 mA, depending on the application. They look silly if they're too bright.

  • Member since
    July 2009
  • From: lavale, md
  • 4,677 posts
Posted by gregc on Friday, January 6, 2017 4:35 PM

not if you put them in series.   Not sure there's enough voltage.   Assuming LEDs are from the same batch, they should have the same brightness since the same current is passing thru each.    And, less power is used for the same number of LEDs.

greg - Philadelphia & Reading / Reading

  • Member since
    February 2007
  • From: Christiana, TN
  • 2,134 posts
Posted by CSX Robert on Friday, January 6, 2017 12:47 PM

DigitalGriffin
And to be honest, I'm not sure arduino uno supports that much current. (20ma*12 = 360 ma * 5V = 1.8 Watts)

Good point.  Of course if they are bright enough at a low enough current he could still run them straight off the Arduino.

  • Member since
    February 2007
  • From: Christiana, TN
  • 2,134 posts
Posted by CSX Robert on Friday, January 6, 2017 12:32 PM

hon30critter

 

 
CSX Robert
will depend on how LEDs are lit.

 

CSX Robert:

I think you meant to say "will depend on how 'many' LEDs are lit" (at the same time).

Dave

 

Yep!

  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Friday, January 6, 2017 12:26 PM

 Yes, fully loading all pins will exceed the chip's maximim rating of 200ma. The maximum current for the whole chip is 200ma, that's all active pins plus the internal systems themselves, so you can't load even 10 pins to maximum.

                   --Randy

 


Modeling the Reading Railroad in the 1950's

 

Visit my web site at www.readingeastpenn.com for construction updates, DCC Info, and more.

  • Member since
    December 2004
  • From: Pa.
  • 3,361 posts
Posted by DigitalGriffin on Friday, January 6, 2017 12:00 PM

Short answer: No it will not.  You will need individual resistors for each LED.

And to be honest, I'm not sure arduino uno supports that much current. (20ma*12 = 360 ma * 5V = 1.8 Watts)  I think you might need a transistor driver circuit from a separate 5V source.   The base would connect to the neg terminal on the arduino and the emmiter would go to ground outside the arduino.

Don - Specializing in layout DC->DCC conversions

Modeling C&O transition era and steel industries There's Nothing Like Big Steam!

  • Member since
    July 2006
  • From: Bradford, Ontario
  • 15,797 posts
Posted by hon30critter on Friday, January 6, 2017 11:31 AM

CSX Robert
will depend on how LEDs are lit.

CSX Robert:

I think you meant to say "will depend on how 'many' LEDs are lit" (at the same time).

Dave

I'm just a dude with a bad back having a lot of fun with model trains, and finally building a layout!

  • Member since
    February 2007
  • From: Christiana, TN
  • 2,134 posts
Posted by CSX Robert on Friday, January 6, 2017 7:29 AM

Use a seperate resistor for each LED, otherwise the brightness of the lit LEDs will depend on how LEDs are lit.

  • Member since
    June 2016
  • 81 posts
Another question of resistance for LEDs
Posted by Ron Hume on Friday, January 6, 2017 7:05 AM

If I common the pos 5 volt pin on an Arduino Uno screw shield to a bus terminal block via a resistance, and connect twelve LEDs to the pos bus and neg pins on the Arduino, will that suffice for all LEDs that light randomely, or should I use twelve resistors on the neg leads?

Ron from down under.

Subscriber & Member Login

Login, or register today to interact in our online community, comment on articles, receive our newsletter, manage your account online and more!

Users Online

There are no community member online

Search the Community

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
Model Railroader Newsletter See all
Sign up for our FREE e-newsletter and get model railroad news in your inbox!