Introduction: HOW-TO Use the ARDUINO SERIAL MONITOR
The Arduino IDE has a feature that can be a great help in debugging sketches or controlling Arduino from your computer's keyboard.
The Serial Monitor is a separate pop-up window that acts as a separate terminal that communicates by receiving and sending Serial Data. See the icon on the far right of the image above.
Serial Data is sent over a single wire (but usually travels over USB in our case) and consists of a series of 1's and 0's sent over the wire. Data can be sent in both directions (In our case on two wires).
Step 1:
You will use the Serial Monitor to debug Arduino Software Sketches or to view data sent by a working Sketch. You must have an Arduino connected by USB to your computer to be able to activate the Serial Monitor.
To get familiar with using the Serial Monitor, Copy and Paste the following example Sketch into a blank Arduino IE window. Then Verify it and if it's OK, Upload it. The next step will show you what to expect.
EXAMPLE SKETCH: CUT and PASTE
/* YourDuinoStarter_SerialMonitor_SEND_RCVE<br> - WHAT IT DOES: - Receives characters from Serial Monitor - Displays received character as Decimal, Hexadecimal and Character - Controls pin 13 LED from Keyboard - SEE the comments after "//" on each line below - CONNECTIONS: - None: Pin 13 built-in LED - - V1.00 02/11/13 Questions: terry@yourduino.com */ /*-----( Import needed libraries )-----*/ /*-----( Declare Constants and Pin Numbers )-----*/ #define led 13 // built-in LED /*-----( Declare objects )-----*/ /*-----( Declare Variables )-----*/ int ByteReceived; void setup() /****** SETUP: RUNS ONCE ******/ { Serial.begin(9600); Serial.println("--- Start Serial Monitor SEND_RCVE ---"); Serial.println(" Type in Box above, . "); Serial.println("(Decimal)(Hex)(Character)"); Serial.println(); } //--(end setup )--- void loop() /****** LOOP: RUNS CONSTANTLY ******/ { if (Serial.available() > 0) { ByteReceived = Serial.read(); Serial.print(ByteReceived); Serial.print(" "); Serial.print(ByteReceived, HEX); Serial.print(" "); Serial.print(char(ByteReceived)); if(ByteReceived == '1') // Single Quote! This is a character. { digitalWrite(led,HIGH); Serial.print(" LED ON "); } if(ByteReceived == '0') { digitalWrite(led,LOW); Serial.print(" LED OFF"); } Serial.println(); // End the line // END Serial Available } } //--(end main loop )--- /*-----( Declare User-written Functions )-----*/ /*********( THE END )***********/
Step 2: What the Serial Monitor Looks Like
When you click on it, the Serial Monitor will pop up in a new window. Above is what our example Serial Monitor Sketch looks like with the Monitor opened.
Look at the Serial Monitor window.
- - The small upper box is where you can type in characters (hit or click "Send")
- - The larger area (Corner can be dragged to enlarge) is where characters sent From Arduino will be displayed.- At the bottom are two pulldowns:
- - One sets the "line ending" that will be sent to Arduino when you or click Send
- - The other sets the Baud Rate for communications. (If this does not match the value set up in your sketch in Setup, characters will be unreadable). Example: Serial.begin(9600); Some sketches or other applications may use a different Baud Rate.
Step 3: DEBUGGING WITH THE SERIAL MONITOR:
If you are testing a new sketch you may need to know what's happening when you try to run it. But "Software Is Invisible ! ". So you need the tell the software to tell you what it's doing, and sometimes the value of changing variables. You do this my using the Serial Monitor and adding code to your sketch to send characters that you can see.
SETUP:
In Setup you need to begin Serial Communications and set the Baud Rate (speed) that data will be transferred at. That looks like this:
Serial.begin(9600); // Other baud rates can be used...
Serial.println("My Sketch has started");
The second line is optional...
LOOP:
Here you can print helpful info to the Serial Monitor. Examples:
Serial.println("Top of loop"); Serial.println("Reading Temperature Sensor"); Serial.print("LoopCounter value = "); Serial.println(LoopCounter);
For details of how to show different data, see "Serial_Print.html" in the Reference section of your Arduino IDE:
Top menu: Help>reference/Serial_Print.html
Experiment with changing the Sample Software Sketch.
More Arduino How-To on the Arduino-Info.Info WIKI!
18 Comments
3 years ago on Step 1
"Arduino IDE has a feature that can be a great help in debugging sketches"
This feature itself is not always working and relying on it to debug a sketch is not practical, forget a bout single LED demos sketches and few line sketches and try a real few hundred line sketch, you quickly see the first bug seem to be Serial monitor freeze. Serial monitor is not a reliable software itself, trying to troubleshoot the code with it, just compound the problem.
4 years ago
I found a problem on the MEGA 2650 in that the serial monitor seems to the 16 MSBs when printing an unsigned long (unit32_t). I've tried various methods and always same, whereas on a ProMini the results are correct.
Question 4 years ago
How can we see this on a graph?
4 years ago
Greetings, I set it up as indicated in the topic, but it shows not correctly and not always ... in the end I decided to use third-party software. https://www.virtual-serial-port.org/products/serialmonitor/ a good job with monitoring.
4 years ago
It was a very nice demo, but the LED logic didn't work when just copying and pasting what is here (Perhaps that was a part of the source got mangled). Anyway I managed to fix it in my own way (the original stuff is 96% intact). BTW I'm a recently retired C/C++/C#/Java/Pascal (and other langs) programmer (with too many years of experience,was getting burned out). I bought an Arduino Uno from Ebay and just started playing with it. Anyway I will post my fixes if anyone is interested.
Question 4 years ago on Introduction
Am I able to send data to the blynk app?
and how?!...and again from blynk app am I able to receive data ?
5 years ago on Step 1
still missing the
pinMode (led, OUTPUT) ;
to make Copy -> Paste working right away - this might be confusing to newbees :.(
5 years ago on Step 1
still missing the
pinMode (led, OUTPUT) ;
to make Copy -> Paste working right away - this might be confusing to newbees
5 years ago
Hey,
If some1 is looking for a more advanced tool with logging capabilities, this one might be it
https://www.eltima.com/arduino-serial-monitor-alte...
5 years ago
thanks for code but when i type in serial monitor 0 or 1 serial monitor update as follows
--- Start Serial Monitor SEND_RCVE ---
Type in Box above, .
(Decimal)(Hex)(Character)
49 31 1 LED ON
13 D
48 30 0 LED OFF
but led remain in ON state.
help me
6 years ago
Thanks 4 sharing. How long each printing takes?
6 years ago
Nice tutorial. It might even be better to buffer incoming characters to some char array ans recognize complete commands using strstr function.
Or even better to use non ASCII characters to be more efficient. But for that you can not use built in Arduino IDE terminal , but you need some more advances RS232 terminal program such as
https://docklight.de/
Even with free version you can see all data in binary format and even set automatic strings for answer to be sent from PC that is triggered by incoming word from Arduino.
6 years ago
I have a question...
If I have uploaded a code on an Arduino mini pro from my mac using a USB and FTDI, with data that prints to the serial port.
Then next time I plug in the Arduino, select the correct port ect, can i just open the serial monitor and see the data being printed to the serial monitor? Or do i need to upload the code again?
The reason I ask is because the code that was uploaded on the Arduino originally has not been saved, so I would like to use the sensor without uploading anything again. Plus i keep having issues with uploading so it would be good just to know that I dont have to upload again and again each time I connect the sensor to the computer!
Thanks in advance!
7 years ago
hey i placed a ir receiver and opened the serial monitor the codes going on it is not stoping i want want know my remote frequency but it the codes are going on plz help me
7 years ago
There is another solution to monitor serial port. Check http://www.eltima.com/products/serial-port-monitor/
7 years ago
Hi Terry,
I’m a newbie to Arduino……..in the past I used Flowcode V4 ….
I have a problem viewing the Serial Monitor, the pop-up
window does not appear….I have tried it
using your “How to use Arduino Serial Monitor” which I download from …. (https://www.instructables.com/id/HOW-TO-use-the-ARDUINO-SERIAL-MONITOR/step3/DEBUGGING-WITH-THE-SERIAL-MONITOR/) I’m sure I have carried out your instructions
correctly …I did a “copy / paste” of the sketch then “Cntrl R” to verify and “Cntrl U” to upload without a hitch but the
pop-up does not appear when I click on the sketch…..
Please help ….
Cheers for now
Manie
8 years ago on Introduction
setup is missing:
pinMode(led, OUTPUT);
9 years ago on Introduction
The Example Sketch is updated; it was mangled somehow by Instructables.