## How to calculate resistors...

Posts: 89
Joined: Fri Feb 22, 2019 5:43 pm
Location: Eastern - USA

### How to calculate resistors...

I know the equations. Let me explain my confusion. I understand that the RPi has a maximum of 16mA output on a GPIO pin. Say I have an LED that is rated for 20mA. Do I use Ohms law and say I=16mA (0.016A), V=3.3V, and thus R=206ohms? So, if I use a 206ohm resistor, does that mean that this circuit is using 16mA - thus nearly maxing out this GPIO pin output? If this is correct then would the decision to use a large resistor lower the amps being used? So, say I swap the resistor to 1kOhm - does this mean V=3.3V, R=1000ohms, thus I=3.3mA? Does this mean that I would only be drawing 3.3mA instead of the 16mA the pin is capable of? The indirect question here is that I understand the maximum amps for the GPIO pins all together is 51mA. So, does this mean if I use 4 of these LEDs simultaneously using 206ohm resistors for each of them that I would be pulling 16mAx4=64mA and over stress the RPi? And, in turn, if I use 1kOhm resistors instead, does that mean I would be pulling 3.3mAx4=13.2mA - which would leave me more RPi GPIO capacity to do other things as well? I have always been sort of egg before the chicken or chicken before the egg in this matter. Does the given power source specs (16mA GPIO output) define the logic or do the comonents?
"When money ceases to be the tool by which men deal with one another, then men become the tools of men. Blood, whips and guns–or dollars. Take your choice–there is no other..."
- Ayn Rand - Atlas Shrugged

Andyroo
Posts: 2996
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

### Re: How to calculate resistors...

Cheat and use this http://led.linear1.org/1led.wiz/

Have a look at https://www.instructables.com/id/Choosi ... With-LEDs/ for three ways to calculate the values. The first is the same as above, the second is a neat gadget to print but the third is the way to do it manually.
Need Pi spray - these things are breeding in my house...

klricks
Posts: 6375
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

### Re: How to calculate resistors...

Wed Apr 17, 2019 11:37 pm
I know the equations. Let me explain my confusion. I understand that the RPi has a maximum of 16mA output on a GPIO pin. Say I have an LED that is rated for 20mA. Do I use Ohms law and say I=16mA (0.016A), V=3.3V, and thus R=206ohms? So, if I use a 206ohm resistor, does that mean that this circuit is using 16mA - thus nearly maxing out this GPIO pin output? If this is correct then would the decision to use a large resistor lower the amps being used? So, say I swap the resistor to 1kOhm - does this mean V=3.3V, R=1000ohms, thus I=3.3mA? Does this mean that I would only be drawing 3.3mA instead of the 16mA the pin is capable of? The indirect question here is that I understand the maximum amps for the GPIO pins all together is 51mA. So, does this mean if I use 4 of these LEDs simultaneously using 206ohm resistors for each of them that I would be pulling 16mAx4=64mA and over stress the RPi? And, in turn, if I use 1kOhm resistors instead, does that mean I would be pulling 3.3mAx4=13.2mA - which would leave me more RPi GPIO capacity to do other things as well?
Generally yes to all the above.
But a LED may be very dim or not work if the chosen resistor is too large.
The forward voltage spec of the LED is important. The FV must be less than the supply (3V3). eg a blue LED likely won't work from a GPIO.
Resistors come in standard values so you may not be able to get the exact resistor that you calculate.
Wed Apr 17, 2019 11:37 pm
I have always been sort of egg before the chicken or chicken before the egg in this matter. Does the given power source specs (16mA GPIO output) define the logic or do the comonents?
Not sure exactly what you are asking?... but components must be chosen so as to not to excede the maximum spec (16mA). A bad choice of components or miscalculation could damage or destroy the RPi.
Unless specified otherwise my response is based on the latest and fully updated Raspbian Stretch w/ Desktop OS.

Posts: 89
Joined: Fri Feb 22, 2019 5:43 pm
Location: Eastern - USA

### Re: How to calculate resistors...

Well, like in my original post - one way to approach this is to take the maximum power supplied (16mA), the source voltage 3.3V, and the load (in this case LED - but not focused specifically of LEDs here) and based on the load amps, 20mA in this case - you calculate the resistor as 206 Ohms. I know that the closest resistor to this is 220Ohms, but I'm looking at calculations for the moment. But, you could go the other direction and say I only want the circuit to draw 3.3mA, based on 3.3V and calculate a resistor of 1kOhm. Which way it is? Which way is correct? Is the power source what determine the amps for calculations - or can I choose the amps I want and calculate the resistor to get it? What one determines which? And am I correct that the 1kOhm resistor would only draw 3.3mA even thought the GPIO is supplying 16mA? Does increasing the resistor actually reduce the amps drawn by the circuit?
Now, to this specific case. I am testing with 3.0 - 3.2V blue 20mA LEDs. With a 220Ohm resistor they are pretty bright on a GPIO. With a 1Kohm resistor they are still VERY clearly visible. If I can do this (1kOhm) - am I reducing the amp pull on the GPIO? Does this then give me more available amps from to RPi to use other GPIOs for other purposes - such as relays, temperature sensors, etc?
Based on the links provided by Andyroo - 3.3v-3.0 =0.3V with 20mA LED - would be 15Ohm and 3.3v-3.2v = 0.1v with 20mA LED - would be 5.6Ohm resistor. But like I said even 1kOhm is looking good to me with these and based on these calculations - I have no idea how to actually calculate what my real amp draw is using these LEDs with the 1kOhm resistors. Or if that's even the right way to think about it.
"When money ceases to be the tool by which men deal with one another, then men become the tools of men. Blood, whips and guns–or dollars. Take your choice–there is no other..."
- Ayn Rand - Atlas Shrugged

Imperf3kt
Posts: 2252
Joined: Tue Jun 20, 2017 12:16 am
Location: Australia

### Re: How to calculate resistors...

A single GPIO pin can supply more than 16mA, it's just that's the number that we were given as a safe limit, not to be exceeded.

Recently, there was some discussion about where the figures even came from and if they still applied to all Pi models. I believe Jamesh said he would look into it, however so far, there has been no reply as far as I know.
Google is ubiquitous - Try it today, it's free!

klricks
Posts: 6375
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

### Re: How to calculate resistors...

Thu Apr 18, 2019 2:35 am
Well, like in my original post - one way to approach this is to take the maximum power supplied (16mA), the source voltage 3.3V, and the load (in this case LED - but not focused specifically of LEDs here) and based on the load amps, 20mA in this case - you calculate the resistor as 206 Ohms. I know that the closest resistor to this is 220Ohms, but I'm looking at calculations for the moment. But, you could go the other direction and say I only want the circuit to draw 3.3mA, based on 3.3V and calculate a resistor of 1kOhm. Which way it is? Which way is correct? Is the power source what determine the amps for calculations - or can I choose the amps I want and calculate the resistor to get it? What one determines which? And am I correct that the 1kOhm resistor would only draw 3.3mA even thought the GPIO is supplying 16mA? Does increasing the resistor actually reduce the amps drawn by the circuit?
Now, to this specific case. I am testing with 3.0 - 3.2V blue 20mA LEDs. With a 220Ohm resistor they are pretty bright on a GPIO. With a 1Kohm resistor they are still VERY clearly visible. If I can do this (1kOhm) - am I reducing the amp pull on the GPIO? Does this then give me more available amps from to RPi to use other GPIOs for other purposes - such as relays, temperature sensors, etc?
Based on the links provided by Andyroo - 3.3v-3.0 =0.3V with 20mA LED - would be 15Ohm and 3.3v-3.2v = 0.1v with 20mA LED - would be 5.6Ohm resistor. But like I said even 1kOhm is looking good to me with these and based on these calculations - I have no idea how to actually calculate what my real amp draw is using these LEDs with the 1kOhm resistors. Or if that's even the right way to think about it.
You are over thinking this......
This is just simple Ohms law that applies to all DC power circuits.

The recommended current capacity of a single GPIO is UP TO 16mA.

The actual current supplied by the GPIO, (or any other power source), is determined by the component values that YOU choose.
If your circuit draws 10mA then the GPIO will provide 10mA... no more .... no less.
You will then have a budget of 6mA left over on that GPIO to do whatever you want. (The 6 mA would also be available for use by other GPIO).

If your circuit(s) on a single GPIO draw more than 16mA then you risk damage to your RPi.
Unless specified otherwise my response is based on the latest and fully updated Raspbian Stretch w/ Desktop OS.

rpdom
Posts: 14173
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

### Re: How to calculate resistors...

Thu Apr 18, 2019 2:35 am
Based on the links provided by Andyroo - 3.3v-3.0 =0.3V with 20mA LED - would be 15Ohm and 3.3v-3.2v = 0.1v with 20mA LED - would be 5.6Ohm resistor. But like I said even 1kOhm is looking good to me with these and based on these calculations - I have no idea how to actually calculate what my real amp draw is using these LEDs with the 1kOhm resistors. Or if that's even the right way to think about it.
It's a simple calculation. With your 3.0V LED the voltage across the resistor is still 0.3V. So using Ohms law (I = V/R) you get I = 0.3 / 1000 or 0.3mA. With the 3.2V resistor it would be I = 0.1 / 1000 = 0.1mA. Not a lot for an LED, but some of them can light up with very low currents these days.
Signature is on holiday.

drgeoff
Posts: 9262
Joined: Wed Jan 25, 2012 6:39 pm

### Re: How to calculate resistors...

In your LED plus resistor case it is the combination of those two plus the voltage that determines the resulting current. While Ohm's Law applies to the resistor (ie voltage, current and resistance are linearly related) the same is not true of the LED. It has a "forward voltage" which is relatively constant over its usable current (and brightness) range. That forward voltage does depend on the colour of the LED. http://lednique.com/current-voltage-rel ... iv-curves/

For a red LED a figure of about 1.7 volts applies. That needs to be subtracted from the total voltage to ascertain the voltage across the resistor. If the GPIO is outputting 3.3 volts then the resistor has about 3-3 - 1.7 = 1.6 across it. If you want 5 mA through it (and the LED) that requires a 320 ohm resistor. 330 is the nearest preferred value.

Posts: 89
Joined: Fri Feb 22, 2019 5:43 pm
Location: Eastern - USA

### Re: How to calculate resistors...

Ok. I get what you all are saying - that makes sense - but I still get confused in this way... If the circuit only pulls the amps needed - then why for example is a resistor even needed with the LED? Why wouldn't it only pull the amps it wants as opposed to burning out because the power source overloads it? I've seem small components that work fine with a AAA 1.5V battery - but if you connect it to a D 1.5V battery - it will kill it - and my understanding of why was because the D battery can supply a higher amperage than the AAA battery. It seems to me that the power supply amperage effects the load as well - not just letting it draw only what it wants. I guess from that line of thinking, that is why I'm always inclined to think the components have to be sized to work with the source as opposed to creating a circuit that is only pulling the amps it wants.

Oh, and as a bit of a side question - will running the LEDs on lower amps, like with the 220Ω or 1kΩ resistors, damage the LEDs?
"When money ceases to be the tool by which men deal with one another, then men become the tools of men. Blood, whips and guns–or dollars. Take your choice–there is no other..."
- Ayn Rand - Atlas Shrugged

scotty101
Posts: 3583
Joined: Fri Jun 08, 2012 6:03 pm

### Re: How to calculate resistors...

You need an electronics book/online tutorial

Consider a simple circuit, an ideal circuit where wires have no resistance and batteries can supply infinite current. In this circuit, we connect the battery terminals together by our zero resistance wires. Battery voltage is 1.5V.
I = V/R
I = 1.5/0
I = Infinity! (Infinite current).

In reality, batteries and wires have resistance so the current will be limited, but the battery and wires will get warm because the resistance is dissipating the heat.

An LED has a very low internal resistance so connected to a battery directly, it will just burn itself out drawing too much current.

Running an LED with a lower current won't damage it but there is a minimum current required to actually illuminate the LED.

(No doubt someone will come along and correct some minor element of my post)
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

Posts: 89
Joined: Fri Feb 22, 2019 5:43 pm
Location: Eastern - USA

### Re: How to calculate resistors...

scotty101 wrote:
Thu Apr 18, 2019 11:26 am
You need an electronics book/online tutorial

Consider a simple circuit, an ideal circuit where wires have no resistance and batteries can supply infinite current. In this circuit, we connect the battery terminals together by our zero resistance wires. Battery voltage is 1.5V.
I = V/R
I = 1.5/0
I = Infinity! (Infinite current).

In reality, batteries and wires have resistance so the current will be limited, but the battery and wires will get warm because the resistance is dissipating the heat.

An LED has a very low internal resistance so connected to a battery directly, it will just burn itself out drawing too much current.

Running an LED with a lower current won't damage it but there is a minimum current required to actually illuminate the LED.
I agree - but like I am running into here as well as electronics books/online tutorials/and even a digital logic theory class I had in college decades ago, this is the which came first - the chicken or the egg scenario I have never been able to get my mind around because I get inconsistent answers. The "theory" is explained without real world application - just fill in the blanks on Ohms Law equations. And then, people with opossing comments - including the instructor - the circuit will only draw the current it wants...

I understand you first example - that's an example that is thoery - but like you said - not reality. People say - design the circuit to pull the amps you are targeting and it will draw only that amount of current - but reality shows that if you put a power supply that can provide more current than the components can take - it blows up. I want to understand this from a design perspective. I want to create a circuit to do X - but I have never seen how - or at least not without contradictory concepts like I just stated.

You made exactly my point with the LED example - it is designed to use up to a certain amount of current before it burns it out. It will not ONLY DRAW the amps it desires - it will allow too much amps to cross it and burn itself out. Basic Ohms Law and available specs (and the new knowledge of subtracting the forward voltage from the supply voltage: 3.3v - 3.0V tot 3.2V) would be R = 0.1V / 0.02A = 5Ω to R = 0.3V / 0.02A = 15Ω. So somewhere between 5Ω and 15Ω. But if I do this - then this circuit would in fact be pulling the near max of the GPIO output. So, the resistor and the LED together have been sized based on the high end of the capacity of the power source (16mA) - not the amp draw preferred. Thus using the most power and effectively pushing the load to it maximum potential.

So, is it a matter of using the given specs - calculating the resistors and such based on power source capacity and load in question, so you know the absolute minimum size resistors to use - and then sizing them larger after that to reduce the amp draw to the preferred levels?
"When money ceases to be the tool by which men deal with one another, then men become the tools of men. Blood, whips and guns–or dollars. Take your choice–there is no other..."
- Ayn Rand - Atlas Shrugged

drgeoff
Posts: 9262
Joined: Wed Jan 25, 2012 6:39 pm

### Re: How to calculate resistors...

Thu Apr 18, 2019 12:48 pm
but reality shows that if you put a power supply that can provide more current than the components can take - it blows up.
Not quite.

The power supply itself should not (in normal operation) be the part that limits the current to what the load can take without endangering the load. A power supply (at the correct voltage) that is able to supply more current than the load should take will not force extra current into the load.

In the case of the LED without resistor, it is a characteristic of the LED that the current and voltage are not linearly related. Once the voltage reaches a "knee" a small change in voltage across it can cause a much larger current to flow through it. It is impractical to custom match a power supply voltage to an individual LED to accurately achieve the desired current. And anyway it would vary with temperature. So the engineering solution is to swamp out the LED's characteristic with the a resistor's characteristic. AS the LED voltage doesn't change much and the PSU is fixed voltage (more or less) then the voltage across the resistor is more or less fixed and known too. Known voltage across a known resistance gives a known current through both resistor and LED. So in this case the design steps would be. Select the LED colour and brightness required. Consult the LED data sheet to find the required current to achieve that brightness. Note the LED voltage for that current. Subtract that LED voltage from the power supply voltage to find the voltage across the resistor. From the voltage across the resistor and the current through it, use Ohm's Law to calculate the required resistor value.

There is no chicken and egg. Circuits are designed to draw certain current (within component tolerances) when operated at a specified voltage. The power supply is designed to supply that voltage and at least the intended current.
Last edited by drgeoff on Thu Apr 18, 2019 1:27 pm, edited 2 times in total.

klricks
Posts: 6375
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

### Re: How to calculate resistors...

Thu Apr 18, 2019 12:48 pm
.......
....
You made exactly my point with the LED example - it is designed to use up to a certain amount of current before it burns it out. It will not ONLY DRAW the amps it desires - it will allow too much amps to cross it and burn itself out. Basic Ohms Law and available specs (and the new knowledge of subtracting the forward voltage from the supply voltage: 3.3v - 3.0V tot 3.2V) would be R = 0.1V / 0.02A = 5Ω to R = 0.3V / 0.02A = 15Ω. So somewhere between 5Ω and 15Ω. But if I do this - then this circuit would in fact be pulling the near max of the GPIO output. So, the resistor and the LED together have been sized based on the high end of the capacity of the power source (16mA) - not the amp draw preferred. Thus using the most power and effectively pushing the load to it maximum potential.

So, is it a matter of using the given specs - calculating the resistors and such based on power source capacity and load in question, so you know the absolute minimum size resistors to use - and then sizing them larger after that to reduce the amp draw to the preferred levels?
A LED is a special case. A LED must have a current limiting resistor... So as for Ohms law think of a LED and the resistor as one device.
Unless specified otherwise my response is based on the latest and fully updated Raspbian Stretch w/ Desktop OS.

PeterO
Posts: 4585
Joined: Sun Jul 22, 2012 4:14 pm

### Re: How to calculate resistors...

See the attached graph which shows a typical red led's voltage/current characteristic.

It shows that at 10mA the led will have ~2.1V across it. So that leaves 3.3V - 2.1V = 1.2V to drop across the resistor.

Apply ohms law to get the resistor value : R = V / I and get R = 1.2V / 10mA = 120Ω

Full datasheet here : http://www.farnell.com/datasheets/1498852.pdf

PeterO
Attachments
LED.png (20.66 KiB) Viewed 593 times
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

drgeoff
Posts: 9262
Joined: Wed Jan 25, 2012 6:39 pm

### Re: How to calculate resistors...

Figure 2 on the page i linked to in my first post in this thread has typical curves for 8 different LED colours.

Posts: 89
Joined: Fri Feb 22, 2019 5:43 pm
Location: Eastern - USA

### Re: How to calculate resistors...

Ok, but in this case - designing with the RPi - we do have to consider the power source capacity. So based on a previous comment - now I'm not sure - I have seen many sources at this point saying the RPi has a max output on GPIOs - collectively - of 51mA and individually 16mA. So this has to be taken into account when developing circuits so they draw amps in ranges that will allow them to all run. Right?

Maybe one thing here that is throwing me off a bit is these LEDs say they are 20mA - already over the max 16mA GPIO - but now understanding the forward voltage subtraction from GPIO voltage - that calculates 5Ω to 15Ω resistors (lets say a 10Ω middle ground). But, this would still cause the resistor and LED to draw 20mA - too much for a single GPIO and would stop me in my tracks in designing the overall project that I'm trying to create. So I must re-design the circuit to fit the power source specifications in this case. So, taking the average difference between power supply 3.3v and the LED range 3.0V to 3.2V - this is 0.2V. So instead of using this along with the 20mA LED rating to calculate the resistor needed - I can decide that I only want the circuit to draw say 1mA, With this, I use R=0.2v/0.001A = 200Ω. At 200Ω (well 220Ω actual resistor) - these LEDs are bright and I'm using only 1mA which gives me much more flexibility to provide power to remaining circuits. Right?

So, in design - initially taking the component specs and using Ohms law will pull maximum amps - but this is only a first step before re-design to fit overall design - right? I mean that's what I'm doing here and it makes for having to pick somewhat arbitrary numbers and tweak stuff accordingly and just see if it works? I mean, I could recalculate the resistor for anywhere from the 0.2mA I'm pulling right now with these 1kΩ resistors lighting up the LEDs all the way up to 5Ω resistors that are maxing out the LED (and also pushing the 16mA GPIO to a 20mA draw) which it might be able to do - but possibly causing damage. Correct?

Also, I think I have had a misconception of resistors for a LONG time - since reading on resistors since I was a young kid - I always thought that the resistors were basically using up some of the power going through them so as to limit the power getting to the load of interest - protecting it from the full power. Thus - my misconception was leading me to think that adding resistors in the circuit did not free up available power to the power source for other things to use - but instead was just using up power and dissipating it as heat. But no - it is simply limiting the current flow - and yes using some of the power dissipating it as heat - but basically allowing to power source to retain more of its power output capacity to power additional things.

I get stuck with concepts like that sometimes. I had programmed for years before going Algebra - and my introduction to Algebra made me crazy looking at the use of variables in a completely different way - once it finally sunk in - Algebra was a breeze - but with the programming mindset going in - it gave me difficulties. Seems so simple in hindsight - but it was a real roadblock.

I think working through this example is helping.
"When money ceases to be the tool by which men deal with one another, then men become the tools of men. Blood, whips and guns–or dollars. Take your choice–there is no other..."
- Ayn Rand - Atlas Shrugged

PeterO
Posts: 4585
Joined: Sun Jul 22, 2012 4:14 pm

### Re: How to calculate resistors...

drgeoff wrote:
Thu Apr 18, 2019 1:59 pm
Figure 2 on the page i linked to in my first post in this thread has typical curves for 8 different LED colours.
Didn't read the whole thread because there was so much wrong info being given !

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

PeterO
Posts: 4585
Joined: Sun Jul 22, 2012 4:14 pm

### Re: How to calculate resistors...

Thu Apr 18, 2019 2:29 pm
Maybe one thing here that is throwing me off a bit is these LEDs say they are 20mA - already over the max 16mA GPIO - but now understanding the forward voltage subtraction from GPIO voltage - that calculates 5Ω to 15Ω resistors (lets say a 10Ω middle ground).
What calculation are you doing to get 5-15Ω ?

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Posts: 89
Joined: Fri Feb 22, 2019 5:43 pm
Location: Eastern - USA

### Re: How to calculate resistors...

PeterO wrote:
Thu Apr 18, 2019 2:42 pm
Thu Apr 18, 2019 2:29 pm
Maybe one thing here that is throwing me off a bit is these LEDs say they are 20mA - already over the max 16mA GPIO - but now understanding the forward voltage subtraction from GPIO voltage - that calculates 5Ω to 15Ω resistors (lets say a 10Ω middle ground).
What calculation are you doing to get 5-15Ω ?

PeterO
The RPi 3.3V GPIO. The LED is blue 20mA, 3.0V to 3.2V (forward voltage based on previous reply). Also based on previous reply and calculator link it would be source voltage less forward voltage. So in this case 3.3V - 3.0V = 0.3V to 3.3V - 3.2V = 0.1V. Given 0.3V and 0.1V with 20mA R = 0.3V / 0.02A = 15Ω to R = 0.1V / 0.02A = 5Ω - but again, this would be a 20mA draw - I don't want that and if these methods are correct - I like the 1kΩ resistor which is 0.2mA and still lights up the LEDs so that they are perfectly visible - not bright - but clearly on
Last edited by ameador1 on Thu Apr 18, 2019 3:03 pm, edited 1 time in total.
"When money ceases to be the tool by which men deal with one another, then men become the tools of men. Blood, whips and guns–or dollars. Take your choice–there is no other..."
- Ayn Rand - Atlas Shrugged

Posts: 89
Joined: Fri Feb 22, 2019 5:43 pm
Location: Eastern - USA

### Re: How to calculate resistors...

PeterO wrote:
Thu Apr 18, 2019 2:38 pm
drgeoff wrote:
Thu Apr 18, 2019 1:59 pm
Figure 2 on the page i linked to in my first post in this thread has typical curves for 8 different LED colours.
Didn't read the whole thread because there was so much wrong info being given !

PeterO
Is my understanding wrong from beginning to end? I mean, is my progression in understanding correct - or am I now off track further? Please keep in mind we're on an LED example - but I was also questioning general design approaches / logic - more so than the LED example.
"When money ceases to be the tool by which men deal with one another, then men become the tools of men. Blood, whips and guns–or dollars. Take your choice–there is no other..."
- Ayn Rand - Atlas Shrugged

PeterO
Posts: 4585
Joined: Sun Jul 22, 2012 4:14 pm

### Re: How to calculate resistors...

Thu Apr 18, 2019 2:55 pm
The RPi 3.3V GPIO. The LED is blue 20mA, 3.0V to 3.2V (forward voltage based on previous reply). Also based on previous reply and calculator link it would be source voltage less forward voltage. So in this case 3.3V - 3.0V = 0.3V to 3.3V - 3.2V = 0.1V. Given 0.3V and 0.1V with 20mA R = 0.3V / 0.02A = 15Ω to R = 0.1V / 0.02A = 5Ω - but again, this would be a 20mA draw - I don't want that and if these methods are correct - I like the 1kΩ resistor which is 0.2mA and still lights up the LEDs so that they are perfectly visible - not bright - but clearly on
You said it was bright enough with a 220Ω in series ?

What was the voltage across the LED when you had a 220Ω resistor in series with it ?

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Posts: 89
Joined: Fri Feb 22, 2019 5:43 pm
Location: Eastern - USA

### Re: How to calculate resistors...

PeterO wrote:
Thu Apr 18, 2019 3:16 pm
Thu Apr 18, 2019 2:55 pm
The RPi 3.3V GPIO. The LED is blue 20mA, 3.0V to 3.2V (forward voltage based on previous reply). Also based on previous reply and calculator link it would be source voltage less forward voltage. So in this case 3.3V - 3.0V = 0.3V to 3.3V - 3.2V = 0.1V. Given 0.3V and 0.1V with 20mA R = 0.3V / 0.02A = 15Ω to R = 0.1V / 0.02A = 5Ω - but again, this would be a 20mA draw - I don't want that and if these methods are correct - I like the 1kΩ resistor which is 0.2mA and still lights up the LEDs so that they are perfectly visible - not bright - but clearly on
You said it was bright enough with a 220Ω in series ?

What was the voltage across the LED when you had a 220Ω resistor in series with it ?

PeterO
It's at home - I'm at work - I can check it later. I didn't measure it. It is in series. GPIO to resistor, resistor to leg of LED, other leg of LED to GND.
Actually they are lighting up perfectly visibile with a 1kΩ resistor in place - 220Ω it strong.
I feel like I am questioning everything I thought I knew about electronics lately. Where should I measure the voltage of the LED? On either side of the LED - between resistor and GND? Or GPIO to GND side of LED? Other?

This is the LEDs I'm using: https://smile.amazon.com/gp/product/B07 ... UTF8&psc=1
"When money ceases to be the tool by which men deal with one another, then men become the tools of men. Blood, whips and guns–or dollars. Take your choice–there is no other..."
- Ayn Rand - Atlas Shrugged

boyoh
Posts: 1276
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

### Re: How to calculate resistors...

My advice is put the Pi back in it’s box, Just do some basic
Electronics on a breadboard , get a 0 /12cdc 4a power supply
Get a selection of Led’s selection of resistors Study OHMs Law
You will need a Multimeter to do your checks Then you will know
How to Interface with the Pi,
Regards BoyOh Retired Electrical / Electronics Technician.
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

davidcoton
Posts: 3710
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

### Re: How to calculate resistors...

Thu Apr 18, 2019 4:24 pm
I feel like I am questioning everything I thought I knew about electronics lately. Where should I measure the voltage of the LED? On either side of the LED - between resistor and GND? Or GPIO to GND side of LED? Other?
It seems you are right to question what you thought you knew.

You need to distinguish between actual values, like GPIO on output voltage of 3V3, and limits like GPIO MAX current 16mA. The only relevance og the MAX current is to make sure your circuit does not draw more than that. For selecting the resistor, it is totally irrelevant. You need the GPIO voltage for your current calculations. What you CAN do, is to calculate the MINUMUM resitor value that is uncoditionally safe so that you do not exceed 16mA from 3V3. As you have found, that is a little over 200R. So using resistors of 220R or above will always be safe, regardless of the LED characteristic. In proctice, because of Vf, you can use a smaller resistor without exceeding 16mA, but then you need to do the calculations correctly.

Similarly, the Vf of an LED can vary significantly with batch and temperature. If the Vf is close to the GPIO voltage (3V3), then a small variation will make a large difference to the voltage across the resistor (components in series, voltages add). This makes it difficult to select a resistor value that will give consistent brightness from different individual LEDs.

Now, for where to measure voltage. Almost always you want to measure relative to ground (0V). Sometimes it is helpful to measure across an individual compont just to save sutracting the voltage at one end from that at the other. In your simple circuit of supply (3V3), resistor, LED, and ground, you can safely measure the volatge all ways rould. Draw the circuit anmd mark all the voltages you measur. Convince yourself that the voltage across the LED (Vf) and the voltage across the resistor always add up to the supply voltage (3V3). Use Ohm's law to calculate the current through the resistor. Note the LED brightness. Try different resistors, different LEDs. Draw up a table of what happens.

As to you design procedure, determine experimentally what resistor you need (220R or above) to light the LED sufficiently for your application. Then measure Vf, and calculate the curent. Remember that as a guideline for the LED current required in future applications. Knowing the required current, you can calculate the resistor for any given Vf and any given supply voltage.

Sorry that is so long, but hope it helps.
Signature retired

PeterO
Posts: 4585
Joined: Sun Jul 22, 2012 4:14 pm

### Re: How to calculate resistors...

Thu Apr 18, 2019 4:24 pm
PeterO wrote:
Thu Apr 18, 2019 3:16 pm
You said it was bright enough with a 220Ω in series ?
What was the voltage across the LED when you had a 220Ω resistor in series with it ?
PeterO
It's at home - I'm at work - I can check it later. I didn't measure it. It is in series. GPIO to resistor, resistor to leg of LED, other leg of LED to GND.
Actually they are lighting up perfectly visibile with a 1kΩ resistor in place - 220Ω it strong.
I feel like I am questioning everything I thought I knew about electronics lately. Where should I measure the voltage of the LED? On either side of the LED - between resistor and GND? Or GPIO to GND side of LED? Other?

This is the LEDs I'm using: https://smile.amazon.com/gp/product/B07 ... UTF8&psc=1
Without knowing the voltage across either the LED or the resistor you can't make any calculation of the current.
Either put you voltmeter across the LED or across the resistor. Also measure the voltage on the GPIO pin when the LED is ON.
With those readings we can do meaningful calculations without having to guess at anything.
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson