Serial Monitor Led 13 won't stay on.

I am trying to learn how to use Serial Monitor from Arduino 1.8.12 with Nano. I want to send one code to Nano to turn on Led 13. Later I will add more Led on it. Here is my code.

char data;
int led = 13; // Pin 13
void setup()
Serial.begin(9600); // baud rate
pinMode(led,OUTPUT); // Set pin 13 as digital out
void loop()
if (Serial.available())
data =;
if (data == ‘A’)
delay (500);

When sending A and it did blink once real fast. So I add Delay (500) and it did blink a little longer. But that is not what I want. I want to turn on LED and stay on till I send different code.

Seems you have the monitor's line ending set to something other than "no line ending". So which ever character arrives as your line ending after the A (either or both of \n or \r depending on the setting) causes the "else" to fire and the led goes off.

Set the line ending in the menu at middle bottom:

PS, run the example sketch from here with the line end set to various options, and you'll see what's arriving after you type and press Enter.

Here for example is the decimal ascii codes for A followed by carriage return and line feed:

I received: 65
I received: 13
I received: 10

It's those 13's and or 10's that were causing your problem.

I got it working now. Last night it was not working. I don't know what happen. Serial monitor on the line ending tab, I had to change from Newline to no line ending. I am not sure if that has to do with it or not.


When you send something from the serial monitor the characters are put into a buffer as they arrive. If line endings are enabled the line ending characters are sent along with what you type in. So if line endings are set to Newline and you type A, what is sent and put into the buffer is 'A', '/n'. So when your program is executed the available() function sees 2 characters in the buffer. The read() pulls the 'A' out and turns the LED on, delays 500 milliseconds then the loop runs again. Now the available() sees 1 character (the newline or '\n) left in the buffer. The read() pulls out the '\n' and since it is not an 'A' turns the LED off.