bumper car disco effect led polarity

I have spent a long time wiring up LEDs to have a disco effect but have made a mistake. Perhaps it is easily fixed with your help.
The lights flash well but only one at a time if I put the negative into the output pin and the positive, from individual bulbs, into the 5v output.
I have wired the polarity around wrong I assume. Can I change the output from negative to positive?

I doubt I have explained this properly.
The sketch works, but The polarity is wrong.

Attache a usual wiring diagram. Your Shakepseare like diagram is not good enough.

First and foremost what limits the current to the LEDs? I have a feeling you have a lot more then about 6 LEDs connected to the Arduino. Each LED will draw more current then the Arduino pin is rated to supply and together they draw way more then the max output current of the microprocessor and possibly the regulator as well. This connection can cause a momentary drop in VCC causing the processor to reset. Consider using a driver board such as the 2007 or a HEF4794B device. There are a lot of choices that are very inexpensive. You will also need an external power supply, the arduino does not have much power available for outboard devices. Be sure to connect all the grounds together. You might consider downloading KiCad and creating a schematic of your project. KiCad is a very powerful cad package that is free but donations are asked for when downloading.
Good Luck & Have Fun!
Gil

Thanks Gil. I have a resistor and the grounds are all connected right. The power is from a 12v or 9 v battery. Don't worry about replying, it would just waste your time. I will sit back and think about it more.
Cheers
Richard

Hi,
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png of how you aimed to make your project.

The fact that you can light each on up each LED means they are all wired the same.
Do you have DMM to test your circuit.

If you have individual resistors on your LEDS and have them connected to a common line , then you should be able to rescue your project but using them connected between controller output and 5V.
Then edit your code.
What model Arduino are you using?
How many LEDs?

Thanks.. Tom... :slight_smile:

richardvanraay:
I have spent a long time wiring up LEDs to have a disco effect but have made a mistake. Perhaps it is easily fixed with your help.
The lights flash well but only one at a time if I put the negative into the output pin and the positive, from individual bulbs, into the 5v output.
I have wired the polarity around wrong I assume. Can I change the output from negative to positive?

I doubt I have explained this properly.
The sketch works, but The polarity is wrong.

The short lead goes to GND and the long lead gets VCC through a resistor is how a led should be wired.

If you connect the long lead to 5V and the short lead to an IO pin, the led should light when the IO pin is OUTPUT LOW since that would allow the 5V to push current through the led. Wired like that, the IO pin made HIGH should turn the led off since with 5V at both ends no current will flow through the led.

What else to tell you depends on how many leds you’re running in any instant and how much current they get.

Thank you very much for your friendly replies. I know I am vague so just ignore me and that is really okay.
I have a photo and will load it.
I have five different coloured leds, two of each. Two red, two yellow, two green, two blue, two white. I have five wires, on each wire are two leds. It is connected to the long prong ( annode?). The sixth wire is ground or negative. This wire has a resistor. It goes to each led, the short prong on the led (cathode?).
I have colour coded the wires.
If I plug a green wire into ground and the black wire into a digital pin (1,2,3,4,5,) it works.
If I unplug the green and put in a red it works. Red into earth, black wire (earth) into any pin 1,2,3,4 or 5.
My sketch is flashing on pins 1,2,3,4,5.
What I want though is to put my coloured wires into pins 1,2,3,4,5 and my earth or negative into the earth. This does not work. I have the polarity around the wrong way I think.
I really thank you for being so kind.
I don’t want to be any trouble.
Cheers
Richard.

Thanks Gofor smoke and Tom George. I have done it wrong.
"The short lead goes to GND and the long lead gets VCC through a resistor is how a led should be wired.

If you connect the long lead to 5V and the short lead to an IO pin, the led should light when the IO pin is OUTPUT LOW since that would allow the 5V to push current through the led. Wired like that, the IO pin made HIGH should turn the led off since with 5V at both ends no current will flow through the led."

I thought the 5volt came out of the pins 1,2,3,4,5.
I have an UNO. There are ten globes, two on each wire. I have only put in one resistor and that is on the negative wire.

Can I fix it easily?
If not I will do it another day.
Cheers,
Richard

Leave anode and cathode terms out of this please. We don't need the extra confusion, nothing is labeled anode or cathode.

The led long leg is the + leg and the short leg is the - leg. Current will only flow from + to - when the path is open and voltage is more than the forward voltage of the led. These are the same + and - on batteries.

Earth is not interchangeable with electric term ground. You can work it so but they are not always the same.

Your description of the wiring is not good enough for me to be sure just what you have. 2 leds on each of 5 wires... in series or parallel?

When you put the resistor on the ground they all use it limits how bright they can all be and something else --- different color leds have different forward voltages, the same resistor will make some brighter than others. A resistor that lets a blue led shine bright will likely let a red led burn up.

Do you know Ohm's Law or much about leds?

I thought the 5volt came out of the pins 1,2,3,4,5.

Digital pins (and analog pins used in digital mode) moded (using pinMode()) as OUTPUT can source current (be 5V) when made HIGH (using digitalWrite()).

The same pin made LOW will sink current (be 0V, as GND).

The same pin moded as INPUT and set LOW will be electrically neutral, the zero state.

The same pin as INPUT and set HIGH will source 5V through at least 20K Ohms, the best way for buttons/switches.

And using the on-chip port registers, the pin can be changed to any of these in less than 1 microsecond.

So now you know, digital pins can supply or drain current as OUTPUT pins.

Thanks very much for your detailed reply GoForSmoke. I have a better understanding. I do know a bit about LEDs and should have remembered they use different voltages. I noted that on the box.
No, I have read OHMs law a few times, and will study it again, but never really grasped it. It is all a bit hard for me.
Thanks again.
I will redo the wiring later if I feel it is worth the effort. My train room is really well lit and the effect of the LEDs is not as great as I had hoped. One on each pin would be better, but still it would be competing with a very well lit room.
Thanks for taking the time to reply.
Richard

richardvanraay:
Thanks very much for your detailed reply GoForSmoke. I have a better understanding. I do know a bit about LEDs and should have remembered they use different voltages. I noted that on the box.
No, I have read OHMs law a few times, and will study it again, but never really grasped it. It is all a bit hard for me.

I spent time on it off and on for days when going for my Electricity Merit Badge almost 50 years ago. I have to sit and write out the 3 forms when I haven't used it in months just to get solid again. What you don't use you can lose, practice reinforces the lesson against that.

Thanks again.
I will redo the wiring later if I feel it is worth the effort. My train room is really well lit and the effect of the LEDs is not as great as I had hoped. One on each pin would be better, but still it would be competing with a very well lit room.
Thanks for taking the time to reply.
Richard

You could take the resistor off the ground wire and put 1 resistor on each of the led + wires and then each led gets its own power that it doesn't have to share.... except for the 2 leds per pin part where 12V (instead of 5V) with 2 or 3 leds and 1 resistor in series allows full bright there. Could you get 12V from the track?
By the time the leds drop the 12V it may be safe to let a digital pin sink what's left.

I have a seperate 12 volt accessory wire , dc, running around the layout so that would be easy.
Thanks. I will have to take some time to mull this over.

When using 12V you need to drop at least 7V on the leds. A blue or white led might drop 3V or more, a red led drop 2V or less.

The cool part about leds in series is that the same current lights them all.

Got it going GoForSmoke.
Thanks for your help.
It is probably not completely correct, but it works.
I used 220k resistors on all output pins.
There are two leds on each pin. Could this burn out the Uno?
I will connect a Map3 player as well.
I will try to attach a simple diagram.
Cheers
Richard

richardvanraay:
I used 220k resistors on all output pins.
There are two leds on each pin. Could this burn out the Uno?

Are they in series or parallel?

In series the forward voltages add, in parallel the leds share current, either way the pins are ... ooops, way too safe!

The usual Arduino make the pin safe resistor is 220, you tell 220k (k is x1000) that would make very dim light.

The resistor to use depends on the leds you use and how they are wired. If I have 2 red leds with Vf 1.8V in series and wanted them to shine 25mA bright (won't hurt the pin to supply 25mA, but close up the led is ouch bright and could use a little heat sink) then

amps = volts / ohms

R = V / A = ( 5VCC - 1.8Vf - 1.8Vf ) / 0.025 = 56 Ohms by numbers BUT forward voltage drops as the led gets warm so get a standard size higher up like 100 that would be safe even with 10% tol. resistor.

Using 12V, ( 12 - 3.6 ) / .025 = 336 or higher standard 360 or 390.

The 12V can support more but take care the leds don't drop more than about 8V of the 12V. Forward voltage drops as the led warms up, more resistor is needed, size up and be safe.

Do you mean Marquee Lighting used by movie halls, etc?

Bumper cars is something I drove in a boardwalk amusement park. Everybody had a rounded electric car and bumped into others back and forth or zoomed around then bump, bumper cars at the shore.

Hi GoForSmoke, Parallel circuits for the two leds. I am silly, of course it is a 220 resistor. The lights are bright enough so I am happy.
I am supplying 12v to vcc and taking 5v from the Uno.
one circuit, two 3-3.4v. (3 of these independently wired)
one circuit, two 1.8-2.4v
one circuit, two 2-2.2v
All 20mA leds
So for the first; R=(5-3.2)/0.02=90
That is 90 Ohms?
Have I done the maths correctly?
What does that mean?
I really appreciate your help.
Thanks
Richard

"Bumper cars is something I drove in a boardwalk amusement park. Everybody had a rounded electric car and bumped into others back and forth or zoomed around then bump, bumper cars at the shore."
Yes, it is electric bumper cars in a fair scene. I have a youtube up showing it if you are interested.

I have also put up a short video showing the results of your help. smile.
The railway is run with a Raspberry Pi. There are 10 Nanos used to show locomotive speeds, welding scene, running an mp3 player, sending a signal from ir sensor to a relay.
I am really bad at the electronics and programming. Everything takes me weeks to do and I have trouble every step of the way.
Thanks again.
Richard
Tasmania

richardvanraay:
I am supplying 12v to vcc and taking 5v from the Uno.

Uno VCC, the common circuit voltage of the board is 5V.

I think that you feed the power jack 12V, does the board get warm in that corner? Older boards will with 12V, better to get a buck converter and feed the 5V output straight to board 5V and GND. New board has a converter instead of a regulator, is 90+% efficient so doesn't get warm, or barely so.

one circuit, two 3-3.4v. (3 of these independently wired)
one circuit, two 1.8-2.4v
one circuit, two 2-2.2v
All 20mA leds
So for the first; R=(5-3.2)/0.02=90
That is 90 Ohms?
Have I done the maths correctly?
What does that mean?
I really appreciate your help.
Thanks
Richard

A led is a light-emitting diode. Diodes let current flow one way through but not the other (until you push hard enough then you went for smoke and got it) and there's a voltage cost as if ground is raised, to get current flow. A led makes light then, as much as the current allowed, there is tiny resistance in the led junction.

The formula R = V / A is resitance = (volts - forward volts) / amps. We know volts, foward volts and desired amps (20 mA) and those tell us what resistance is required. You show Vf for your leds varies so take the cases that need the most resistance, forward volts is subtracted so take the smallest values, 3V, 1.8V and 2V.

And you have these leds wired not in series, one after the other but side by side in parallel?

In parallel the forward voltages do not add.

Resistance for led 1, 3-3.4Vf is (5V - 3V) / .02 = 100. Since the low value is used, 100 or so ohm resistor is good.

Resistance for led 2, 1.8-2.4Vf is (5V - 1.8V) / .02 = 160. Since the low value is used, 160 or so ohm resistor is good.

Resistance for led 3, 2-2.2Vf is (5V - 2V) / .02 = 150. Since the low value is used, 150 or so ohm resistor is good.

Wired in series, 5V could not light 2 of led 1 at all but 12V could do 1 of each with (12-3-1.8-2)/.02=260, 270 ohm resistor is the next standard size. The voltage going to ground is 5.2V, okay for Arduino pin at 20mA.

You need to study beginner electronics, maybe some physics. Are you out of school?

Thanks GoForSmoke. I left school a long time ago but am still learning. I have learnt a great deal from you, thanks.
I am finding it hard to learn new things. Early onset of Alzheimers or dementia, most likely just stupid.
Thanks for taking the time to help. It is really appreciated.
Richard