# On my Arduino, why is this LED always on, even though I told it to turn off?

I am a software developer trying to understand how computers work at a lower level.

I have purchased the Arduino Uno Microcontroller and I have followed all of the tutorials from LadyAda.

I have noticed that the LED (not the power LED) is always ON unless it is flashing even if I supply the following program, which clears the memory and should switch off the LED:

#include <EEPROM.h>

void setup()
{
// write a 0 to all 512 bytes of the EEPROM
for (int i = 0; i < 512; i++)
EEPROM.write(i, 0);

// turn the LED on when we're done
digitalWrite(13, LOW);
}

void loop()
{
}


Why is the LED always on? I have Googled this and have read a few similar questions on another forum like this, but I have not yet found an answer.

• Why would you expect it to be off? And what do you mean, "unless it is flashing?" Where's the flashing? – Phil Frost Jan 5 '13 at 20:56
• You'll wear out the EEPROM if you are continuously writing it, I guess it is fine in your setup but be aware of limited number of writes to EEPROM. Don't do it unless absolutely necessary. – jippie Jan 5 '13 at 21:20
• If you want to turn off the LED, reduce your program to the absolute minimum: remove the for loop, add a pinmode(13,OUTPUT); – jippie Jan 5 '13 at 21:24
• @woo51977 The comment says you are turning it on. "LOW" doesn't necessarily mean "OFF", depending on how the LED is connected. – Phil Frost Jan 5 '13 at 21:28
• It only runs during setup() and I initially didn't notice that. But, EEPROM has a limited number of programming cycles (100,000) and Arduino is easily capable of wearing it out in a short time span if it is written over and over again. – jippie Jan 5 '13 at 21:29

I believe your problem is that your not setting that pin as an output. Use pinMode(13, OUTPUT) to configure the pin 13 to be used as a digital output. Since GPIO pins can be used as a input or outputs on/off, you need to let the micro controller know what mode that pin needs to be set to.

#include <EEPROM.h>
int led = 13;

// the setup routine runs once when you press reset:
void setup()
{
// initialize the digital pin as an output.
pinMode(led, OUTPUT);

// write a 0 to all 512 bytes of the EEPROM
for (int i = 0; i < 512; i++)
EEPROM.write(i, 0);

digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
}

void loop()
{
}


You can see the basic Hello World example here, that goes over blinking the pin 13 LED.

Also, you should be careful about writing to the EEPROM, as pointed out in the comments, it only has ~100k cycle lifetime.

• Thanks. I am referring to A. The statement in your answer does not seem to turn it off. – w0051977 Jan 5 '13 at 22:00
• @w0051977 I updated my answer. – Garrett Fogerlie Jan 5 '13 at 22:09
• Thanks. Could you elaborate on what you mean by: "you should be careful about writing to the EPROM"? I bought this as a board to "play" with in order to enhance my understanding. Wouldn't I have to write to the EPROM every tine I create a program in c? – w0051977 Jan 5 '13 at 22:47
• @w0051977 Atmel's AVRs have 3 different types of memory: Flash, EEPROM, and RAM. Normally when you program the board it is only writing to the AVR's Flash memory, so the EEPROM stays fairly untouched. There is also a bootloader in the Flash area, your program gets added to the Flash after the bootloader. The bootloader allows you to program the Atmega processor through serial (or USB to serial.) But don't be afraid to play with it, just be aware that it does have a limited lifetime. – Garrett Fogerlie Jan 5 '13 at 23:00
• Thanks. The program in your answer switched off the LED. – w0051977 Jan 5 '13 at 23:01

Nobody has actually answered the question. Why does the LED only extinguish when pin 13 is set to OUTPUT with digital write LOW? Sure I understand that in the INPUT-PULLUP mode there is voltage supplied to the pin through a pull up resistor which theoretically can make the LED glow dimly. But the reality is that the LED glows brightly when pin 13 is an INPUT, low or high. If pin 13 is set to INPUT/LOW (which is the default on power-up) where is the voltage and current coming from to drive the LED? And don't anyone dare crap on about the pull-up resistor again. As I said the LED is bright regardless whether pin 13 is INPUT-LOW or INPUT-HIGH.

It appears that the UNO r3 works differently from earlier versions. REF schematic: http://arduino.cc/en/uploads/Main/Arduino_Uno_Rev3-schematic.pdf Pin 13 is an input for an op-amp. If there is a voltage on pin 13 the op-amp will match that voltage on its output which drives the LED. Because INPUT pins have high impedance, without a pull-down resistor their voltage will float, or perhaps there is a miniscule leakage from the micrcontroller and without a pull-down resistor there will be voltage on the pin. Op-amp inputs have a theoretical infinite impedance.

This is a design improvement. With the old version you couldn't use pin 13 as INPUT-PULLUP because the voltage would only be 1.7V because the LED was draining the current coming through the pull-up resistor. With the UNO R3 the op-amp won't drain the pull-up current allowing us to set pin 13 as INPUT_PULL-UP. The Pro-mini still has the old design however, and if you want to use pin 13 as INPUT-PULLUP you have to flick the resistor off the board.

• Just FYI. There is a stack dedicated to Arduino arduino.stackexchange.com – Nick Alexeev Feb 26 '15 at 5:34
• This should be the accepted answer. The question was "why" is something happening. The other response just shows a workaround. – Petrus Sep 13 '17 at 11:37

Everybody who is facing problem with L (pin 13) on your Arduino Uno, put this code as it is on a blank screen on the IDE window. It will solve the problem.

const int led = 13;

void setup() {
pinMode(led, OUTPUT);
}

void loop() {
digitalWrite(led,LOW);
}


Hope this helps :)