Using output pin as GND

Why does PWM output pins is acting like GND when it’s state is LOW but non-pwm pins is not?

For example, if I connect led’s positive pin to arduino’s pin 8 (non-pwm on Duemilanove) and led’s negative pin to arduinos pin 9 (pwm on Duemilanove) and run this code:
void setup() {
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
}

void loop() {}
<— diode lights 100% bright

BUT

If I put led’s positive pin into arduino’s pin 9 and negative into 8 and run this code:
void setup() {
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
}

void loop() {}

← then diode lights on for about 0.1% of total brightness…

It most likely has nothing to do with either pin being a PWM pin. The polarity cases you show should light in both instances. You really should name/call the two LED leads as anode or cathode, not positive or negative.

Now the reason it doesn't light in one direction could be that pin 8 is damaged and stuck in a low state, or that pin 9 is damaged and stuck in a high state, or that both pin 9 and 8 are damaged and stuck high and low respectively.

I guess my first question to you would be did you use a current limiting resistor wired in series with the LED? If not that would be one easy way to damage an Arduino output pin(s).

An arduino output pin has a maximum allowable output current draw of 40ma and if there is a LED wired with no resistor then there is nothing to limit the current to stay below that value. Once an LED is forward biased it acts pretty much like a short circuit.

Lefty

How do I repair damaged pins? Will new chip with burned boot loader will do the job?

How do I repair damaged pins? Will new chip with burned boot loader will do the job?

Yes, that is the only way to repair a damaged pin. Around $6 from several vendors.

Lefty

You have to be very careful when hooking stuff up like motors and anything that sucks power to a port pin. Just because there is 5V there when its set to high doesnt mean it can handle the current.

This is one of the limitations of the Arduino IMHO that makes it less noob proof, but the only work around would be extra circuitry and when you look at the cost of an ATMega its simply more feasible to have replaceable chips. The only problem is for those boards which use surface mount ATMegas