Page 1 of 1

2 LED wiring

Posted: Mon Jan 21, 2019 12:32 pm
by papous
I need to connect 2 LEDs to a pi3b
Does the image below show the correct wiring or does each led need to connect to ground through a 330 resistor?
2LED_bb.jpg
2LED_bb.jpg (138.01 KiB) Viewed 749 times

Re: 2 LED wiring

Posted: Mon Jan 21, 2019 12:36 pm
by Burngate
Each LED requires its own resistor.

As far as the two GPIOs is concerned, they're independent - they light their own LED what ever the other one's doing - and each wants to see its own LED and resistor.
No resistor means broken GPIO

Re: 2 LED wiring

Posted: Mon Jan 21, 2019 12:52 pm
by papous
Thank you for clarifying the situation

Re: 2 LED wiring

Posted: Mon Jan 21, 2019 1:07 pm
by drgeoff
You can use one resistor if only one LED will be on at a time. Anode of each LED to their GPIOs. Cathodes of LEDs and one end of resistor all joined together. Other end of resistor to ground.

Re: 2 LED wiring

Posted: Mon Jan 21, 2019 1:17 pm
by Mortimer
drgeoff wrote:
Mon Jan 21, 2019 1:07 pm
You can use one resistor if only one LED will be on at a time. Anode of each LED to their GPIOs. Cathodes of LEDs and one end of resistor all joined together. Other end of resistor to ground.
he wouldn't be able to use the circuit as shown even in those circumstances. The right hand LED is depicted wired directly to ground, and therefore doesn't have a resistor in its circuit anyway.

Re: 2 LED wiring

Posted: Mon Jan 21, 2019 2:50 pm
by papous
Thank you all for your replies. The pi pins are 16 and 20. So how about this?
And how would it be if I wanted both lets to switch on together?
Thank you

Re: 2 LED wiring

Posted: Mon Jan 21, 2019 8:01 pm
by pcmanbob
If you want to power more than 1 LED from a gpio pin then you need to use a transistor like this as one gpio pin will not power 2 or more LED's

Image

Re: 2 LED wiring

Posted: Mon Jan 21, 2019 8:29 pm
by PhatFil
looks better, yes. and to switch both on together just issue the command to switch one on followed by the 2nd.
the time it takes to execute the 2nd command is imperceptible regardless of language/tools used both led lights will appear to turn on together.
some/most languages will allow multiple assignments on a single command line but when starting out KISS ;) (Keep It Simple Stupid)
Since a lot of coding involves copy and paste, its easy to miss a multiple assignment on a line embedded within code,
When starting/learning i would suggest keep multiple assignments to initial declarations or setup functions as applicable.

Re: 2 LED wiring

Posted: Mon Jan 21, 2019 8:45 pm
by DougieLawson
Try this:

Code: Select all

#!/usr/bin/python3
import time

from gpiozero import LED

led01 = LED(16)
led02 = LED(20)

while True:
    led01.on()
    print ("01")
    time.sleep(1)
    led01.off()
    led02.on()
    print ("02")
    time.sleep(1)
    led02.off()
For Bob's wiring with a transistor try this:

Code: Select all

#!/usr/bin/python3
import time

from gpiozero import LED

led01 = LED(25)

while True:
    led01.on()
    time.sleep(1)
    led01.off()
    time.sleep(1)

Re: 2 LED wiring

Posted: Mon Jan 21, 2019 9:12 pm
by papous
Thank you all very much for taking the time to help

Re: 2 LED wiring

Posted: Tue Jan 22, 2019 1:18 am
by hippy
drgeoff wrote:
Mon Jan 21, 2019 1:07 pm
You can use one resistor if only one LED will be on at a time.
Whenever I've tried that, all cathodes commoned through a single resistor to 0V it has worked for me. It's handy for wiring up 7-Segment displays. The only problem is, the more LED's are lit, the dimmer each becomes. That can however be mitigated by varying the duty cycle depending on how many LED's or segments are lit.
pcmanbob wrote:
Mon Jan 21, 2019 8:01 pm
If you want to power more than 1 LED from a gpio pin then you need to use a transistor like this as one gpio pin will not power 2 or more LED's
Depends on what current they are drawing. Many LED's are super bright these days and only draw a couple of mA with good enough illumination.

I was tinkering with some 75W 12V LED modules and I was amazed how little they draw and how much light they put out when not supplied with a full 12V.

Re: 2 LED wiring

Posted: Tue Jan 22, 2019 3:44 pm
by pfletch101
hippy wrote:
Tue Jan 22, 2019 1:18 am
drgeoff wrote:
Mon Jan 21, 2019 1:07 pm
You can use one resistor if only one LED will be on at a time.
Whenever I've tried that, all cathodes commoned through a single resistor to 0V it has worked for me. It's handy for wiring up 7-Segment displays. The only problem is, the more LED's are lit, the dimmer each becomes. That can however be mitigated by varying the duty cycle depending on how many LED's or segments are lit.
This will work OK as long as the 'paralleled' LEDs are more or less identical - specifically as regards their forward voltage drops. This will, of course, generally be true for individual segments of a 7-segment display. However, different colored LEDs typically have somewhat different forward voltage drops, and, if they are connected 'in parallel' with a common resistor, the one with the lowest drop (typically the red one) will be much brighter when both/all are turned on.