[SOLVED] Why does this code make my LED_BUILTIN glow?

Disclaimer:
I am a complete beginner and I apologize in advance if these are stupid questions.

Background:
I have been looking at the "Blink without delay" example in the Arduino IDE, and I wrote a short piece of code in an attempt to understand what happens to the timing of the blink when the millis() function reaches the end of its 49 day lifespan.
The interesting part is when [small number]-[big number]=[positive number]. I am trying to understand how the unsigned long variables in this equation make the answer positive.

  • And more importantly, why does my short sketch make the built-in LED on pin 13 glow. I have not called the Pin13 or the LED_BUILTIN.

  • Is this caused by "runaway" voltage or "noise", and should I be worried about that? (I.e. would it drain battery over time?)

  • If I tell pin 13 to shut up with a digital write(13, LOW), where will this electrical noise energy go?

Hardware:
Arduino UNO R3

**My code: ** Actually it doesnt matter what the code is. See edit below.

unsigned long previousMillis = 4294967295;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}
void loop() {
  // put your main code here, to run repeatedly:
  Serial.println(10 - previousMillis);
  //Serial.println(millis());
  delay(3000);
}

The Blink without delay example: (just for reference):

// constants won't change. Used here to set a pin number:
const int ledPin =  LED_BUILTIN;// the number of the LED pin

// Variables will change:
int ledState = LOW;             // ledState used to set the LED

// Generally, you should use "unsigned long" for variables that hold time
// The value will quickly become too large for an int to store
unsigned long previousMillis = 0;        // will store last time LED was updated

// constants won't change:
const long interval = 5000;           // interval at which to blink (milliseconds)

void setup() {
  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // here is where you'd put code that needs to be running all the time.

  // check to see if it's time to blink the LED; that is, if the difference
  // between the current time and last time you blinked the LED is bigger than
  // the interval at which you want to blink the LED.
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW) {
      ledState = HIGH;
    } else {
      ledState = LOW;
    }

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
  }
}

Edit: I noticed the code I posted is not the reason. The glow happens even with a bare minimum sketch.

Can you post a picture of the 'glowing' led on pin 13. I've never heard of this problem!

missdrew:
Can you post a picture of the 'glowing' led on pin 13. I've never heard of this problem!

Sorry it took me a while. I had to email myself the picture and crop/resize/compress image in photoshop. The image is added to the main post as an attachment now.

I should mention that the TX light is blinking, and doing so at full intensity. I assume this is related to serial communication.

The image doesnt do it justice, but the built-in LED glows dimmer, continously.
Edit: I would like to add that uploading the sketch or resetting the board (with the button on the top right), the light goes away for about two seconds, and then it slowly but steadilyly builds itself up to a set brightness (not full brightness). Allmost like there is a capacitor that must fill before it has enough juice to glow.
Edit: Also I noticed the code I posted is not the reason. this happens even with a bare minimum sketch.

Sounds like a physical fault! As I have said, I've never come across this before. I'll step back and hopefully someone else can help.

See this post found with a search for "arduino uno built in led on at boot".

groundFungus:
See this post found with a search for "arduino uno built in led on at boot".

Thank you. I don't understand how it works, but it seems that the glowing led is rather normal on the R3.

Does this mean I should write pin 13 LOW on every sketch I make from now on? (If I want to conserve battery and avoid shortages etc.).

You need to make pin 13 an output first, then write a low.

coffeeguy:
The interesting part is when [small number]-[big number]=[positive number]. I am trying to understand how the unsigned long variables in this equation make the answer positive.

Because of rollover. There's no sign to express negative values.
In the case of an unsigned long which is 32 bits. The largest value that can be expressed with 32 bits is 2^32 - 1 = 4294967295.
So 0 - 1 = 4294967295 and 4294967295 + 1 = 0

I have one like that, some unintended 'feature'.

To void setup ()
add --
pinMode(13,OUTPUT);
digitalWrite(13,LOW);

It's because the R3 drives the onboard LED with an op amp. If the op amp input is left floating, it can turn on.

I think the Duemilanoves weren't like that.

groundFungus:
You need to make pin 13 an output first, then write a low.

nicolajna:
Because of rollover. There's no sign to express negative values.
In the case of an unsigned long which is 32 bits. The largest value that can be expressed with 32 bits is 2^32 - 1 = 4294967295.
So 0 - 1 = 4294967295 and 4294967295 + 1 = 0

runaway_pancake:
I have one like that, some unintended 'feature'.

To void setup ()
add --
pinMode(13,OUTPUT);
digitalWrite(13,LOW);

aarg:
It's because the R3 drives the onboard LED with an op amp. If the op amp input is left floating, it can turn on.

Thank you all!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.