Guneshs
Posts: 48
Joined: Sun Jun 25, 2017 4:18 pm

Connecting 5 white LEDs to raspberry pi for remote on/off

Mon Dec 25, 2017 2:42 pm

Hi,
I have build a car with raspberry pi and a camera .
I have a 5 white bright LED ckt. board which I had salvaged from a battery.
IMG-20171225-WA0021.jpg
IMG-20171225-WA0021.jpg (95.15 KiB) Viewed 1864 times
I want to add these group of led to my Raspberry pi and switch it on / off remotely.

I have attached the LED ckt. Board image file.
IMG-20171225-WA0020.jpg
IMG-20171225-WA0020.jpg (198.13 KiB) Viewed 1864 times
I am using two 18650 batteries for powering my smart car and 2 rc motors.
Please help me with this connection of LEDs to RPI.
Thanks.

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

Re: Connecting 5 white LEDs to raspberry pi for remote on/off

Mon Dec 25, 2017 4:54 pm

It appears your LEDs are connected in parallel, as white LEDs normally operate at 3.3 v with a forward voltage of 20-25mA you will have a current draw of 100-125mA.

So you can control these using a 2N2222 transistor with a 470 ohm resistor in series with the gpio and the base leg.

You will also need a series resistor to limit the LED current but as you have not said what voltage the battery is you intend to power this from I cant tell what value that will need to be.

You will need to connect it battery positive to resistor to LED positive.
LED negative to transistor collector .
Transistor emitter to battery ground and pi ground.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

beta-tester
Posts: 1237
Joined: Fri Jan 04, 2013 1:57 pm
Location: de_DE

Re: Connecting 5 white LEDs to raspberry pi for remote on/off

Tue Dec 26, 2017 12:41 pm

pcmanbob wrote:
Mon Dec 25, 2017 4:54 pm
It appears your LEDs are connected in parallel, as white LEDs normally operate at 3.3 v with a forward voltage of 20-25mA you will have a current draw of 100-125mA.
I thought, if the LEDs are parallel, you do not have to limit the current to 100-125mA, you still have to limit the current to 20-25mA. because otherwise in parallel, the weakest LED draws more current. when the limit is set to 100mA, that is far above the 20mA that LED can handle, then it blowes. then the 100mA is divide between the remaining LEDs and then there, the weakest blow ... and so on ...

each parallel path hast to be limited separately to 20-25mA then...

... isn't it, or am I completely wrong in my guesses?
{ I only give negative feedback }
RPi Model B (rev1, 256MB) & B (rev2, 512MB) & B+, RPi2B, RPi3B, RPi3B+, RPiZeroW, ...

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12224
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Connecting 5 white LEDs to raspberry pi for remote on/off

Tue Dec 26, 2017 1:09 pm

beta-tester wrote:
Tue Dec 26, 2017 12:41 pm
pcmanbob wrote:
Mon Dec 25, 2017 4:54 pm
It appears your LEDs are connected in parallel, as white LEDs normally operate at 3.3 v with a forward voltage of 20-25mA you will have a current draw of 100-125mA.
I thought, if the LEDs are parallel, you do not have to limit the current to 100-125mA, you still have to limit the current to 20-25mA. because otherwise in parallel, the weakest LED draws more current. when the limit is set to 100mA, that is far above the 20mA that LED can handle, then it blowes. then the 100mA is divide between the remaining LEDs and then there, the weakest blow ... and so on ...

each parallel path hast to be limited separately to 20-25mA then...

... isn't it, or am I completely wrong in my guesses?
sorry but yes you are (sort of) wrong.
parralleling LED's only works (well) when LEDs have nearly identical forward voltage (curves), so the current distributes evenly between the LED's, then the current drawn is just the sum of the current each LED needs to emit light, which with about 20mA per led and 5 LED's comes to 100mA. But true, if you parallel LED"s of different color, and each has a different forward voltage then each LED needs its own resistor, which isn't the case here as the PCB shows.

beta-tester
Posts: 1237
Joined: Fri Jan 04, 2013 1:57 pm
Location: de_DE

Re: Connecting 5 white LEDs to raspberry pi for remote on/off

Tue Dec 26, 2017 2:01 pm

mahjongg wrote:
Tue Dec 26, 2017 1:09 pm
... or am I completely wrong in my guesses?
sorry but yes you are (sort of) wrong.
no problem...
always good when somebody tells me what i am doing/thinking wrong.
so i can learn something new... :idea:
{ I only give negative feedback }
RPi Model B (rev1, 256MB) & B (rev2, 512MB) & B+, RPi2B, RPi3B, RPi3B+, RPiZeroW, ...

Guneshs
Posts: 48
Joined: Sun Jun 25, 2017 4:18 pm

Re: Connecting 5 white LEDs to raspberry pi for remote on/off

Tue Dec 26, 2017 2:16 pm

Hi Guyz,
Thanks for you replies and it was really helpful.
about my battery voltage ,
I am using two 4.2v 18650 batteries connected in series . so total voltage is 7.4v.
I am also using a step down DC-DC converter which converts voltage to 5v for my raspberry pi and 2 servo motors to operate.
i am also using a servo motor driver for motors.
i am also using a Servo Controller which is built based on PCA9685. PCA9685 is a 16-channel LED controller with I2C bus interface.
I have a query that , can we use this led controller by any means.
and also i am attaching circuit schematic of my car.
Please take a look at this and help me with this.
I am keen on learning new things. :)
Screen Shot 2017-12-26 at 7.12.55 PM.jpg
Screen Shot 2017-12-26 at 7.12.55 PM.jpg (202.07 KiB) Viewed 1748 times

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

Re: Connecting 5 white LEDs to raspberry pi for remote on/off

Tue Dec 26, 2017 4:55 pm

So with that info.

Using the 7.4V as the supply to your LEDs you would need to use a 47 ohm 1 watt resistor as the current limiting resistor, if you used the transistor circuit I suggested.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Guneshs
Posts: 48
Joined: Sun Jun 25, 2017 4:18 pm

Re: Connecting 5 white LEDs to raspberry pi for remote on/off

Mon Jan 22, 2018 1:12 pm

Hi.
I have coonected all the components and tried to run this piece of code to light the led.
But it doesn't lit up.
I have connected base of npn222 transistor to GPIO21 and ground to last pin 40 (Ground )
Please take a look and help me .

Code: Select all

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(21, GPIO.OUT)
GPIO.output(21, True)

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

Re: Connecting 5 white LEDs to raspberry pi for remote on/off

Mon Jan 22, 2018 1:31 pm

So you should have you LED/Transistor connected like this.

Image

if it still does not work check you have the LED connected round the right way and also the transistor connected round the right way


Image


I post replies when I see your post please don't send PM's asking for help it will only make me ignore you.
Last edited by pcmanbob on Mon Jan 22, 2018 1:49 pm, edited 1 time in total.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12224
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Connecting 5 white LEDs to raspberry pi for remote on/off

Mon Jan 22, 2018 1:34 pm

Can't comment on your Python code, but are you sure you are turning on the right GPIO, there is sometimes some confusion in this regards, with the naming convention of GPIO's, there are at least two conventions in use, so make sure you are not confusing them.

Your transistor circuit should be a 2N3904 (I think a 2N2222 is a bit too weak), with an 1K resistor in its was, and a 47Ohm resistor in series with the LED.
Does the LED(s) turn on when you connect it(them) directly to power (with 47Ohm resistor in series obviously!) ?
What happens when you manually connect 3.3Volt to the base resistor?

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

Re: Connecting 5 white LEDs to raspberry pi for remote on/off

Mon Jan 22, 2018 1:43 pm

With a load of 100-125mA 2n2222 should be fine rated at 800mA max continuous collector current
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12224
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Connecting 5 white LEDs to raspberry pi for remote on/off

Tue Jan 23, 2018 10:13 am

Yeah, you are right, a 2N2222 should be fine.

Guneshs
Posts: 48
Joined: Sun Jun 25, 2017 4:18 pm

Re: Connecting 5 white LEDs to raspberry pi for remote on/off

Thu Jan 25, 2018 9:40 am

Sorry for sending personal msg to both of you.
I fixed the prob. as the 47 ohm 1 watt resistor was creating trouble .
Code worked when i removed the resistor.
Thanks for your replies.
Really appreciated.:)

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

Re: Connecting 5 white LEDs to raspberry pi for remote on/off

Thu Jan 25, 2018 11:25 am

In that case your LED's must have a current limiting resistor already on the pc that we cant see, as looking at your picture it still looks to me as if all the LED's are connected in parallel.

I would check on the voltage being applied to each LED just to make sure its not over 3.3V or you may shorten their life.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Guneshs
Posts: 48
Joined: Sun Jun 25, 2017 4:18 pm

Re: Connecting 5 white LEDs to raspberry pi for remote on/off

Thu Jan 25, 2018 12:40 pm

Ya you were right. I found a resistor hidden inside on ckt. board.
I tried measuing the voltage when lights were lit but it was showing 0 volt.
while my leds we lit , i could see that one led was dim.
Found out that the resistor on board is burnt.
Do u think is it a good idea to put that 47 ohm 1 w resistor in place of that burnt one?

texy
Forum Moderator
Forum Moderator
Posts: 5157
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: Connecting 5 white LEDs to raspberry pi for remote on/off

Thu Jan 25, 2018 1:35 pm

Guneshs wrote:
Mon Jan 22, 2018 1:12 pm
Hi.
I have coonected all the components and tried to run this piece of code to light the led.
But it doesn't lit up.
I have connected base of npn222 transistor to GPIO21 and ground to last pin 40 (Ground )
Please take a look and help me .

Code: Select all

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(21, GPIO.OUT)
GPIO.output(21, True)
Mahjongg already hinted as this, but to elaborate your code/wiring would not work because you have set GPIO as BOARD thinking you need to connect the LED's to physical pin 40 of the GPIO port. Wired that way the correct code should be

Code: Select all

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(21, GPIO.OUT)
GPIO.output(21, True)
Alternatively use the code as you have it and wire the LED to physical pin 21.
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

Guneshs
Posts: 48
Joined: Sun Jun 25, 2017 4:18 pm

Re: Connecting 5 white LEDs to raspberry pi for remote on/off

Thu Jan 25, 2018 1:42 pm

Ya I changed the code lil bit .
Used BCM which is broadcom's pin naming system.

Code: Select all

import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(18,GPIO.OUT)
print "LED on"
GPIO.output(18,GPIO.HIGH)
time.sleep(10)
print "LED off"
GPIO.output(18,GPIO.LOW)
It lights up leds for 10 seconds and turns off.

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

Re: Connecting 5 white LEDs to raspberry pi for remote on/off

Thu Jan 25, 2018 2:26 pm

Guneshs wrote:
Thu Jan 25, 2018 12:40 pm
Ya you were right. I found a resistor hidden inside on ckt. board.
I tried measuing the voltage when lights were lit but it was showing 0 volt.
while my leds we lit , i could see that one led was dim.
Found out that the resistor on board is burnt.
Do u think is it a good idea to put that 47 ohm 1 w resistor in place of that burnt one?
You need to work out how the resistor and LED's are connect on the circuit board. start at one end of one track and follow it along drawing each connection to a resistor or LED that way you can built up a diagram of the circuit board. from that you can work out if you need to replace the resistor or short out the faulty one and use the external one.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Return to “Beginners”