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.
const int led = 9; // the pin that the LED is attached to
void setup()
{
// initialize the serial communication:
Serial.begin(9600);
// 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 ");
Serial.println(brightness);
// 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().
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
pinMode(13,INPUT);
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.
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.