17 posts
I'm now starting to follow some very simple tutorials with electronic components and the GPIO pins. Somewhere I found the term 'current limiting resistor'.

My question is, when I dim a LED by placing a resistor in the circuit does the total current go down (as in that my battery lasts longer) or is the current that doesn't go through the LED changed into heat in the resistor?
Posts: 1090
Joined: Thu Mar 08, 2012 3:32 pm
There are 2 ways to connect 2 components, parallel and series.
In parallel connection both terminals of both components are connected to each other and that unit is then used in a circuit. In series connection one terminal of one component and one terminal of the other are connected and the "spare" terminals are used in the circuit.
So, in parallel the current splits between the 2, in series it passes through one, then the other.
In this case the resistor would be in series, it will reduce the current flowing through the LED, so your battery will last longer.
>)))'><'(((<

Posts: 431
Joined: Wed Dec 12, 2012 10:41 am
Location: Swine Town UK
A current limiting resistor should be carefully selected to ensure that the current going through the resistor is limited to the current specified for the LED.

Its basic ohms low to calculate what size resistor to use.
Ohms law is V=IR where Voltage = Current(Amps) * Resistance(Ohms)

We can transpose the above to get R = V/I

Let's say that the ideal current for the LED is 20mA which is 0.02 Amps
The LED will drop 1.2V across it's junction and the output of the GPIO will be 5V

The voltage across the resistor is 5-1.2 = 3.8V

So to get our resistor we simply divide 3.8/0.02
as R = V/I

which equals 190 Ohm

That's how to get the value for a resistor.

The power in a resistor P = VI which in this case is 3.8*0.02 = 0.076 Watts

If you drive an led straight from the GPIO pin you will most likely damage the PI or the LED will go bang.
Posts: 25
Joined: Thu Sep 13, 2012 11:25 am
If you drive an led straight from the GPIO pin you will most likely damage the PI or the LED will go bang.

Overloaded LED's usually get very bright very quickly, burn out & sometimes smell bad, I've not made one go bang yet :)

There are some handy calculators online if you want to simplify the process.
http://led.linear1.org/1led.wiz
The resistor is on the positive side, the anode a.k.a. the long leg or curved edge.
Posts: 39
Joined: Fri Jan 20, 2012 3:50 am
The resistor can be at any side of the LED.

You can also sink the current so that current flows from the 5v supply into the GPIO of the PI simply setting the GPIO High will turn off the LED setting it Low will turn the LED on

GPIO -------/\/\/\/\/\-------|<|---------------+5v
220ohm LED

Sourcing the current from the GPIO High to turn on Low to turn Off
GPIO -------/\/\/\/\/\-------|>|---------------GND
220ohm LED
Posts: 25
Joined: Thu Sep 13, 2012 11:25 am
A LED is a diode, so if you try to put more than the "forward voltage" of the LED on it (typically between 1 and 3 volt, depending on the type of LED) then an almost unlimited amount of current will run through it! You need a resistor in series with the LED to limit the current that runs through it, as the LED won't. And yes, the resistor will dissipate the difference between the forward voltage and whatever you power the LED/resistor combo with. Thats why sometimes many LED's are switched in series, when for example, they are all powered with 12V.

Forum Moderator
Posts: 4506
Joined: Sun Mar 11, 2012 12:19 am
poing wrote:... or is the current that doesn't go through the LED changed into heat in the resistor?

Think of the current as a bit like water in a pipe. If you squeeze the pipe, less water flows. It doesn't change into anything else or magically disappear.

Current is just electrons moving. They don't get lost, change into anything else, or even jump out of the wire.

Your battery can supply just so many electrons, (measured in mAh, where one of those contains approximately 22,500,000,000,000,000,000 electrons). Each one heads out from the negative end of the battery, goes through your resistor and LED, and arrives back at the positive end of your battery. When all of them have done that, your battery is flat

EDIT: actually, the wires and stuff contain alot more electrons than that, and the ones arriving back at the positive end aren't the ones that left the negative end, but the idea's the same
Hardware ace - level: Cowboy

Posts: 2351
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK
LOL. Nice basic introduction there.

I've never seen an LED shine bright for any time at all. In my experience when you put too much current through them you don't see anything... ever again.

Forum Moderator
Posts: 2890
Joined: Mon Jan 09, 2012 3:16 pm
Thanks for all the input guys.

My confusion was based on what we used to do with dedicated photographic light bulbs. As these are (were) quite expensive a common trick was to put two of them in series so the voltage for each was lowered from 220V to 110V making them less bright and last way longer. But they both still got warm and both obviously used energy.

Now I think that may be due to the actual construction of the resistor (lamp) as a light emitting product.

Another confusing thing is when playing guitar over a tube amp. To get that real rock&roll sound you have to crank it wide open, but as neighbors usually have axes we used a ceramic resistor (forgot the specific name) to reduce the power delivered to the speakers. In my recollection these became hot as well.

Anyway what I'm doing is this: http://www.raspberrypi-spy.co.uk/2012/08/reading-analogue-sensors-with-one-gpio-pin/#more-520 which works well with the photo resistor I knew I had lying around (and took me only an hour to find ). I wanted to make a light switch/trap where I can record and act open when a piece of paper is placed between the LED and the photo cell. But the LED (3.1-3.3V) was too bright, for it saturated the photo cell even when the paper was in place. Thus I needed to dim the LED and found that a 10K resistor did the trick, but then wondered where the energy went.

BTW how long does it take an electron to travel through a, say, 10cm piece of wire? And do they go slower when they travel upwards in a vertical piece of wire and faster if they travel downward? One fool...
Posts: 1090
Joined: Thu Mar 08, 2012 3:32 pm
I may be wrong on this, but I gather electrons don't actually travel very fast in wire. It's the electric/magnetic/whatever field that's real quick (speed of light?). (I studied engineering, not science.) So the overall signal is fast.

As for the electricity in our nervous system (ions flow rather than pure electrons, but it's still electricity) it's even slower, though the overall signal is slower too. (Though I am not a neurophysiologist either.)

To answer your original question, the resistor we put in series wastes a bit of potential (voltage). The most efficient way to light the LED would be to drive it directly off 3.3V or whatever, but pulsing it very fast and keeping it on only half of the time. Varying the on time will vary the brightness. But this is probably not worth the extra effort
Posts: 1233
Joined: Fri Feb 24, 2012 1:01 pm
Location: UK
Yes. electrons travel at a quite slow speed through the wire, (its called the drift velocity) but in fact they do not simply flow from a to b, they move randomly through the conductor at a speed of about 1500 km/s, but the progress they make in for example a 1mm thick wire through which 3A flows is just a meter per hour!

The propagation speed, that is if you put electrons in one end of a conductor, how fast electrons come out on the other end is actually dependent a bit on the insulator surrounding the conductor. normally its a very large fraction (95% or so) of light-speed, (300 million meters per second) but for coax cable it's just 66%

Forum Moderator
Posts: 4506
Joined: Sun Mar 11, 2012 12:19 am
poing wrote:... And do they go slower when they travel upwards in a vertical piece of wire and faster if they travel downward? One fool...

Of course! And that's why lightning strikes don't damage clouds - they're going too slowly. When they reach the ground, they bounce, and the noise is called Thunder.

It is April isn't it?
Hardware ace - level: Cowboy

Posts: 2351
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK
The movement of electrons is not electrical energy. Even in a DC circuit, the energy exists in the EM fields around the wires, not in the wires themselves.

See http://amasci.com/miscon/energ1.html

There are many ways to think about it, some ways more helpful than others and some easier to understand than others, but to answer all the questions requires Maxwell's Equations.

Put a pencil on the table. Push one end. Does the other end move immediately? If it did then we could make a pencil a million miles long and use it to send a message faster than the speed of light. But it doesn't; the force from the push causes a compression wave to travel down the pencil and only when it reaches the other end does that end of the pencil move. That compression wave only travels at the speed of sound, (which is higher in wood than in air,) but that is much faster than the individual atoms in the pencil are moving. Exactly the same effect happens when you drop a slinky.

In a circuit, the wave is an electromagnetic wave that travels across the circuit at near to the speed of light. The individual electrons, like the atoms in the pencil, respond to that wave, but move much slower.

Forum Moderator
Posts: 2890
Joined: Mon Jan 09, 2012 3:16 pm
poing wrote:
Anyway what I'm doing is this: http://www.raspberrypi-spy.co.uk/2012/08/reading-analogue-sensors-with-one-gpio-pin/#more-520 which works well with the photo resistor I knew I had lying around (and took me only an hour to find ). I wanted to make a light switch/trap where I can record and act open when a piece of paper is placed between the LED and the photo cell. But the LED (3.1-3.3V) was too bright, for it saturated the photo cell even when the paper was in place. Thus I needed to dim the
LED and found that a 10K resistor did the trick, but then wondered where the energy went.

Ahha.. And a bit of sticky tape over the LED or sensor wouldnt work?

Ravenous wrote:To answer your original question, the resistor we put in series wastes a bit of potential (voltage). The most efficient way to light the LED would be to drive it directly off 3.3V or whatever, but pulsing it very fast and keeping it on only half of the time. Varying the on time will vary the brightness. But this is probably not worth the extra effort

Would that work in this case? since while the LED is on it will still be too bright, its our eyes that make the switched LED seem dimmer.
>)))'><'(((<

Posts: 431
Joined: Wed Dec 12, 2012 10:41 am
Location: Swine Town UK
a good model for a LED is a valve, imagine a stream of water blocked with a flap (a valve) the water needs to push the flap open, so there must be a little bit more water on one side of the flap than the other. But once the water has enough force to open the flap, nothing else inhibits the water to flow through it. The "water push" is the voltage, only a little bit (1,2 Volt) is needed to overcome the flap, but if you push much harder (apply more voltage) the flap doesn't push back harder, so unlimited amounts of water (current) can flow through it.

Putting 3,3V on a 1,2V LED will still not limit the current, the current is then limited by something else, like what the power supply can deliver. The LED will get so much current that it will flash, and burn up (if there is enough energy).

In the water stream analogy above a resistor is just a thin pipe preventing more water too flow than what can be forced through the pipe. If you put the pipe "after the flap" then its the pipe that limits the water current, not the flap, unless the water force is too weak to push the flap open.

Forum Moderator
Posts: 4506
Joined: Sun Mar 11, 2012 12:19 am
Driving LEDs directly off 3.3V: What I was referring to when I mentioned this (not sure if people misunderstood me) is driving the LED off high voltage using PWM, as a dimmer. As I understand it the average current demand will be reduced quite efficiently and the LED won't blow. Am I wrong? (I've tried it on other stuff, the LED survived but I didn't do measurements to prove the efficiency.)

Electricity running uphill: General relativity has things to say about time frames in a gravitational well, and I wonder if this is relevant?
Posts: 1233
Joined: Fri Feb 24, 2012 1:01 pm
Location: UK
Ravenous wrote:Driving LEDs directly off 3.3V: What I was referring to when I mentioned this (not sure if people misunderstood me) is driving the LED off high voltage using PWM, as a dimmer. As I understand it the average current demand will be reduced quite efficiently and the LED won't blow. Am I wrong? (I've tried it on other stuff, the LED survived but I didn't do measurements to prove the efficiency.)

Electricity running uphill: General relativity has things to say about time frames in a gravitational well, and I wonder if this is relevant?

An LED can blow (with time to spare) in a nano-second or so, your PWM clock will give it plenty of time to give up the ghost.
>)))'><'(((<

Posts: 431
Joined: Wed Dec 12, 2012 10:41 am
Location: Swine Town UK