I have an Arduino Uno whose LED, which is connected to pin 13, is not turning off and it always stays on, and it annoys me.
Touching any exposed pins turns off the LED after removing my hands from the pins it turns back on slowly.
However it works perfectly with the programs. This program does turn the LED off and it stays that way while the program is running.
void loop() {
digitalWrite(13, LOW);
}
When I upload other programs that don't use pin 13 then it stays on again. How can I fix this?
2 Answers 2
If you don't tell it to turn off, it behaves "as it wants". If you don't write a 0 on its pin, how can you force it to stay shut down?
If you want it to be in an off state, force it: in your setup function write
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
No need to refresh it every loop, just in the setup.
-
Yeah i know. that was the example i am giving to tell it behaves that way when the pin is not defined/set. Means i have not set
pinMode(13,OUTUPT/INPUT);
and still it stays on.. but when i do define it withpinmode
than it works the way it supposed to workSkyyy– Skyyy2015年11月30日 12:50:48 +00:00Commented Nov 30, 2015 at 12:50 -
Yes, that's because if you want the board to do (or not to do) something you have to explicitely say it. Otherwise you will have a behavior that can change between runsfrarugi87– frarugi872015年11月30日 13:18:21 +00:00Commented Nov 30, 2015 at 13:18
-
i have another arduio uno who doesn't behave like this one.. its led stays off.Skyyy– Skyyy2015年11月30日 16:11:18 +00:00Commented Nov 30, 2015 at 16:11
-
Again, " you have to explicitely say it. Otherwise you will have a behavior that can change between runs". If you don't tell it to pull it down, it will be in a floating state. Floating means that no one knows what state it will have. So pull it down. Or solder a resistor (any value above 10k are fine) between the 13 pad and ground. Or place a resistor of the same value in the header between pin 13 and ground. But you have to set a valuefrarugi87– frarugi872015年11月30日 16:29:31 +00:00Commented Nov 30, 2015 at 16:29
You could try to actually remove the LED with a soldering pen... I haven't tried it however, so you could end up disabling pin 13 (or worst).
-
-
1As I referred to in my comment on the question ( arduino.stackexchange.com/questions/17675/… ) this behaviour is normal because of the op-amp they use to drive the LED. The output state is undefined if the pin is configured as an input, and the op-amp may or may not turn on the LED. To be sure, configure the pin as an output. Soldering a resistor or removing the LED seems an overkill. Define the pin as an output if it is not used for anything else, and write LOW to it.2015年11月30日 20:11:48 +00:00Commented Nov 30, 2015 at 20:11
-
1@AkashKumar you could just put a small square of electrical tape over it, which is also temporary. Don't overthink it!Anonymous Penguin– Anonymous Penguin2015年11月30日 23:56:12 +00:00Commented Nov 30, 2015 at 23:56
pinMode(13, OUTPUT);
) in yoursetup
function?pin 13
only then i set it asoutput
else its not even defined any where in the code