L led turns on automatically when I open serial monitor

I am a beginner of Arduino. Recently, I found that when I opened the serial monitor, the L led lighted on by itself. My code had nothing to do with L led (although it was executed correctly). I am confused.

Can anyone give an explanation? What happened when I open the "Serial Monitor" Dialog? I know my code will be executed from the very beginning, but why L led is on? I am using Arduino MEGA 2560.

Thank you in advance.

Perhaps your code is doing it and you don't realize it. If you show your code we can check.

Here is my code. The "Dimmer" Demo in tutorial.

const int led = 9;      // the pin that the LED is attached to

void setup()
  // initialize the serial communication:
  // initialize the ledPin as an output:
  pinMode(led, OUTPUT);
  Serial.println("I am ready");

void loop() {
  byte brightness;

  // check if data has been sent from the computer:
  if (Serial.available()) {
    // read the most recent byte (which will be from 0 to 255):
    brightness = Serial.parseInt();
    brightness = constrain(brightness,0,255);
    Serial.print("Set the led to ");
    // set the brightness of the LED:
    analogWrite(led, brightness);

Looks like nothing in your code hits Pin 13 (the 'L' LED). I'd guess it has something to do with the bootloader which runs whenever you re-start the Serial Monitor. If it's a problem you can turn Pin 13 off in setup().

The R3 boards use an op-amp to buffer the LED from the pin. Occasionally noise will cause the LED to turn on unintentionally.

Yes, and the user can test for this by either wiring a say 10k ohm resistor from pin 13 to ground or adding the following to his start up function

digitalWrite(13, LOW);

If either of those methods keeps the L led off then he/she will know that the cause is the floating input pin condition to the op-amp driving the L LED.


digitalWrite(13, LOW);

That's the state the pin is left in: INPUT with pull-up disabled. So that won't help.

The only thing that will help is the 10k resistor to ground.

Your right I had a brain fart. I meant to post:

digitalWrite(13, LOW);


Thank you, retrolefty.

digitalWrite(13, LOW);

Works perfectly to turn off the L led.
However, wired pin 13 to ground via a 10k resistor don't have any effect.
I measure the voltage between pin 13 and ground and I found that, before I opened the "Serial Monitor", it was almost 0, but when the dialog was opened, the voltage jumped to 5V immediately. I guess it is caused by my boot loader. It is some problem in initialization. However, press the "Reset" button in my board will turn off the L led. It seems contradictory.