Arduino Mega 1280 Pin 3 behaving really strange...

Ok, so i'm having a really awkward problem here... I recently build a Pool light, that has 5 3W RGB LEDs that are all individually controlled by 15 PWM Pins on an Arduino Mega 1280, since each LED had 4 pins, and instead of all Cathodes (-), all Anodes (+) where connected together (i figured this is probrally for when you want/need to control the RGB Pins with Transistors, since Transistors usually control ground), the brightness i've got from the Arduino Pins directly (witch are limited to about 40 mA) was enough for my, or lets say i didn't think it was worth it to have to use 15 Transistors and on top of that even have to heat sink the LEDs, anyhow, since i wanted them to PWM fade the LEDs between different colors i connected the + pin from each LED to 5V and each - pin to a digital pin (witch supports PWM of course), and since the 0 to 255 brightness in this case was obviously inverted since i was controlling the - poles instead of the + poles, i just did something like analogWrite(pin, map(brightness, 0, 255, 255, 0)); witch works fine...
Now to the problem (sorry for the long explanation), i've noticed that the color of one LED was often a little different from others after observing and testing things for a while i found out that the Green of that LED was allways a little weaker then the Green of the others, i tried changing the pins and found out that even if i only connect two LEDs (any LEDs, small, big, there was no difference) to 5V, pin 2 and 5V, pin 3, and upload this sketch:

void setup() {
analogWrite(2, 150);
analogWrite(3, 150);
}

void loop() {
}

the LED on pin 2 always glows brighter than the LED on pin 3, i've also tried digitalWrite(2 and 3, LOW); and got the same results except of course both LEDs where brighter, what is even stranger is that in both examples this doesn't occur when i try the same thing connecting the LEDs to GND, pin 2 and pin 3, in that case both LEDs allwas have same brightness.
Another thing i found strange about pin 3 was that all other Pins while uploading something and before setting the pin high or low or 'analog'Writing something to it are not high or low, they are just not connected to anything (by the way, i always wondered if it is possible to bring a pin back to that state once it was set to something, it could be useful sometimes, something like digitalWrite(pin, NEUTRAL); is that possible? I assume it isn't) but pin 3 while uploading and before setting it is low, however it is not as low as possible if you set it low it gets a bit lower but the LED in the pool (or any other LED) connected to pin 3 does glow before i set it HIGH in the setup(), thats all i found out until now...

Does anybody know why this could be, and if it is possible to "fix"?

Thanks, Delphiño

Without a schematic drawing to look at it's pretty hard to convert a thousand words into a single picture. A schematic drawing is the universal language of electronics, ignore that at your own risk.

That aside, I suspect your problems are related thinking you can control leds by voltage control Vs the proper current control. Higher power LED absolutely require constant current drivers to prevent damage to the leds. Some LED constant current driver modules have a TTL voltage level PWM input to allow for variable brightness control and therefore easy to interface to a Arduino PWM output pin.
Also be aware that for RGB leds the same current in each color lead does not mean equal brightness to the human eye. So those are only possible hints. Post a good schematic and I'm sure many here can help you with the project.

Lefty

@retrolefty Thanks for your reply, sorry if i didn't explain myself to well, i'm not so good at that :slight_smile:
I know it would be difficult to find out what the problem is (assuming this isn't normal for pin 3) in my Pool Light circuit/programm, but the thing is, i've also tried connecting two of the exact same LEDs (just normal red 5mm LEDs, nothing special) to 5V with their + lead, one to pin 2 (or any other pin), with it's - lead, and the other to pin 3 with it's - lead, and then i uploaded a sketch that only "analogWrote" pin 2 and 3 to 150 (duty cycle) in the setup function, and the LEDs had different brightnesses, i also tried uploading a sketch that set pin 2 and 3 LOW, and there was stil a brightness difference, the brightness of the LED on pin 3 is always lower then the other pins, but when i connect the LEDs the other way around (both - leads to gnd, and the + leads to pin 2 and 3) for some reason then the brightness is suddenly the same, and also normally all the pins that have not been used in the sketch (not been set high or low or anything) are neither low nor high, their just neutral, but pin 3 is always low already... Hope you understand what i mean, i really don't think i need to draw a schematic for this! Basically there are 2 strange things going on with that pin, first, it doesn't matter if i'm uploading a sketch or whatever, as long as the Sketch doesn't set pin 3 HIGH it's just LOW, instead of being none, and second, pin 3 can't get "as low" as the other pins, i know a pin can't be lower or higher then another since there is just low or high, but it's like when a pin high it's at 5V, and when it's low it's at 0V, but when pin 3 is high it's at 5V and when it's low it's at 0,3V or something (i havent meassured).

Hope you understand me now... :slight_smile:

Delphiño

First not all led's will provide the same light output as others. Second How can a pin be High and "Measure?" 0 V? and when Low measure .3V.
AS you were advised current sources are required for high power LED's not following that advice is up to you and so are your results.
If you used transistors or better yet Mosfets you might achieve a workable design.
The other point is because of the typically LOW Rdson A Mosfet will heat up a great deal less. The origin of the name transistor is Transfer Resistance (or)
A transistor is a resistive device that conducts CURRENT in one direction. A Mosfet is a voltage operated device and that is the Crux of the problem.
A transistors DC CURRENT gain or Beta is the ratio of base current to collector current and there lies the real heating issue.
Any Transistor's DC gain is current dependent and the dependency is in the Base Emitter Junction... The Base current sums with the emitter current and is wasted, further is the concept that as the emitter current increases the internal base emitter junction sums the two currents and thus raises the required current necessary to control the base.
Mosfets aren't affected by this phenomena unless the source (emitter) is not grounded and if it isn't them only the voltage will change...

Doc

Ok guys, look, i appreciate your concerns about the Pool LEDs Power consumption and such, but that is not my problem... Just forget about the whole Pool LED thing, just imagine i for some reason need to connect two connect one small 20mA LED to a pwm pin 2 and PWM it, i guess we would all agree that wouldn't be a problem, don't we? Ok, but in my case i have to connect the LEDs Anode to 5V and control the Cathode with pin 2, but because the 0-255 duty cycle in analogWrite refers to the time the pin is high, in relation to the time it is low, we have to invert the duty cycle value we Write to pin 2 (eg. value = map(value, 0, 255, 255, 0):wink: since where are controlling the negative lead of the LED, otherwise the LED will be at it's full brightness when we analogWrite 0 to pin 2 and completely off when we analogWrite 255 to pin 2. Agreed?
Ok, and that works beautifully with every pwm pin, except pin 3, with pin 3 the brightness of the same LED is allways less then when we do the exact same thing with any other pwm pin. Thats my problem!

And now, another thing about that pin that i've observed, and thought may help one find out what the problem is, is that that specific Pin is always low before getting set to anything while the others aren't high or low...

My asumption is, that for example pin 3 before being set is at something like 0.5V, when you set it low, is at 0.3V, and when you set it high is at 5V... That would make sence since the LED is already on before setting it to anything, but gets a bit brighter when you set it low. It would also explain why this only occurs when i pwm the negativ lead and have the positiv lead connected to 5 V (the other wa around it works fine), that would then be because when you control the positive lead the led quickly gets full power and then a bit power (0.3V) but not enough to light up, and then gets full power again, and so on, but the other way around (when the pin is at 5V the LED is off, because we control the negativ lead), what happens is the LED gets no power (5V), and then get almost full power (0.3V), but not really full power, and then gets no power again, and so on... So the obviously when we control the LEDs negative lead it's not so bright because it never gets full power... Do you understand what i'm trying to explain?
Now, how can a fix this? Or is it even possible to fix? Did this ever happen to anybody else, maybe my Arduinos pin 3 just doesn't work right?

Delphiño

PS: Sorry, i meant 5V when high, and 0.3V when low... :wink: (i'll edit that)

(eg. value = map(value, 0, 255, 255, 0)

Ever heard of the subtract operator?

Ok, and that works beautifully with every pwm pin, except pin 3, with pin 3 the brightness of the same LED is allways less then when we do the exact same thing with any other pwm pin. Thats my problem!

Now, how can a fix this? Or is it even possible to fix? Did this ever happen to anybody else, maybe my Arduinos pin 3 just doesn't work right?

It certainly is possible that your past treatment of pin 3 caused it some damage and it's unable to sink the same amount of current that the other output pins can. I will ask you that when you performed the 'simple tests on the output pins' using a single 20ma led did you have a proper sized series resistor wired between the led and the output pin(s)? Lack of current limiting will and does damage output pins and or leds.

Lefty

It certainly is possible that your past treatment of pin 3 caused it some damage and it's unable to sink the same amount of current that the other output pins can.

It's certainly possible that even an undamaged pin might have a different maximum output current (current it will supply without any limiter) than some other pin. Without a current limiting resistor, a pin will typically provide more than the "allowed max" of 40mA, but exactly how much current will be provided (with or without damage) is NOT specified.

Yeah, i'd like to try this on another Arduino, to see if it does the same thing, the problem is, the only other Mega i have is controlling my Cars ignition and it would be kind of complicated to test it, but maybe i'll test that later, if i don't have anything better to do... Would be interesting to see if this is just my Arduino bevahing strangly, or if it's a general Mega thing.
@retrolefty: I don't think that any experiment i've done with this Arduino damaged it's pin 3, i actually didn't use this Arduino alot anyhow.
@westfw: I guess one pin having a different max output current then the others would be a possible, but kind of strage that it only has a lower output current when low, i mean, the output current shouldn't depend on whether the pin is high or low... And also, if that would be the reason, then whats with the pin always being low even while uploading until you set it high?

Delphiño

the output current shouldn't depend on whether the pin is high or low.

output current can VERY MUCH depend on whether the pin is high or low. MANY chips can drive much more current in one direction (usually when low) than the other (the limit being the 'open drain' output that can sink some current, but doesn't source (+V) any at all.)

@retrolefty: I don't think that any experiment i've done with this Arduino damaged it's pin 3, i actually didn't use this Arduino alot anyhow.

Well you didn't answer my question. When you tested pin3 (and tested the other pins) with a 20ma led did you have a resistor wired in series with the led and the output pin?

Lefty

Well you didn't answer my question. When you tested pin3 (and tested the other pins) with a 20ma led did you have a resistor wired in series with the led and the output pin?

Oh, sorry, no i didn't, that was because, i once measured the max output current (witch was about 75 mA) and then i tried it with a LED in series, and the current flowing through the LED was about 30-35 mA, because that is not so much more than the LED should have, usually when i only want to quicly try something out, i don't connect a resistor in series with the LED... I know, i know, the next thing you'll say is probrably, oh, well maybe that damaged the pin... But first of all since your just not supposed to used more than 40mA from the pins, and i was using 35mA, i really dought that could have damaged anything, and second of all, why did that then not damage the other pins? Ok, i suppose, the Pool LEDs witch in this case take as much power they can get from the poor Arduino, may have damaged the pin, but, again, way only that one pin?

Delphiño

Ok, i suppose, the Pool LEDs witch in this case take as much power they can get from the poor Arduino, may have damaged the pin, but, again, way only that one pin?

Perhaps because you were somewhat lucky? Your methods did expose your output pin(s) to abuse. Just the fact that you measured a maximum current draw of about 75ma in one situation means the datasheet warning about absolute maximum output current drawn from a pin were violated and means you did expose your chip to damage. How that damage exhibits itself is somewhat hard to quantify, but make no mistake you have reaped what you sowed. :wink:

Lefty