papous
Posts: 72
Joined: Fri Jan 05, 2018 5:50 am

2 LED wiring

Mon Jan 21, 2019 12:32 pm

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 885 times

User avatar
Burngate
Posts: 6100
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: 2 LED wiring

Mon Jan 21, 2019 12:36 pm

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

papous
Posts: 72
Joined: Fri Jan 05, 2018 5:50 am

Re: 2 LED wiring

Mon Jan 21, 2019 12:52 pm

Thank you for clarifying the situation

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

Re: 2 LED wiring

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.

User avatar
Mortimer
Posts: 924
Joined: Sun Jun 10, 2012 3:57 pm

Re: 2 LED wiring

Mon Jan 21, 2019 1:17 pm

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.
--------------
The purpose of a little toe is to ensure you keep your furniture in the right place.

papous
Posts: 72
Joined: Fri Jan 05, 2018 5:50 am

Re: 2 LED wiring

Mon Jan 21, 2019 2:50 pm

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
Attachments
2LED_bb.jpg
2LED_bb.jpg (142.37 KiB) Viewed 839 times

pcmanbob
Posts: 7295
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: 2 LED wiring

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

Image
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

PhatFil
Posts: 1437
Joined: Thu Apr 13, 2017 3:55 pm
Location: Oxford UK

Re: 2 LED wiring

Mon Jan 21, 2019 8:29 pm

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.

User avatar
DougieLawson
Posts: 36578
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: 2 LED wiring

Mon Jan 21, 2019 8:45 pm

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)
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

papous
Posts: 72
Joined: Fri Jan 05, 2018 5:50 am

Re: 2 LED wiring

Mon Jan 21, 2019 9:12 pm

Thank you all very much for taking the time to help

hippy
Posts: 6281
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: 2 LED wiring

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.
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.

pfletch101
Posts: 545
Joined: Sat Feb 24, 2018 4:09 am
Location: Illinois, USA

Re: 2 LED wiring

Tue Jan 22, 2019 3:44 pm

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.

Return to “Automation, sensing and robotics”