0% found this document useful (0 votes)
234 views10 pages

2-3 - The Serial Monitor

The serial monitor allows users to interact with an Arduino board through text input and output instead of just using LEDs. It is useful for debugging programs and communicating with a running program. To use the serial monitor, a program must initialize the serial connection and then can print messages or parse input. The user can view the serial monitor after a program is running to interact with the Arduino and provide input. An example program prints a prompt, parses the user's input to blink an LED that number of times.

Uploaded by

Darwin Vargas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
234 views10 pages

2-3 - The Serial Monitor

The serial monitor allows users to interact with an Arduino board through text input and output instead of just using LEDs. It is useful for debugging programs and communicating with a running program. To use the serial monitor, a program must initialize the serial connection and then can print messages or parse input. The user can view the serial monitor after a program is running to interact with the Arduino and provide input. An example program prints a prompt, parses the user's input to blink an LED that number of times.

Uploaded by

Darwin Vargas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

The Serial Monitor

mmm...
The purpose of the serial monitor

It is another way to interact with the Arduino.

The serial monitor provides a text-based output system (instead of just blinking
LED’s)

It is useful for debugging and giving extra information to the user from the
Arduino board while the project is running.
Serial Connection

A way to communicate with the Arduino

Goes through the USB cable.

You could also use pins 0 and 1 if you wanted to.

Used for:

Loading code onto the board

Communicating with a running program through Serial Monitor


First you initialize
the connection.
Then you read or,
more often, write
to it.
To use serial monitor

First, INITIALIZE it in the setup function:

void setup() {

Serial.begin(9600);

}
9600 is the baud rate - the speed at which your computer
communicates with the board.
After you initialize it, you may print to it:

Anywhere you want something printed:


Prints what is in the parentheses
Serial.print();
Prints what is in the parentheses
Serial.println(); AND THEN prints a “newline”
character

THAT IS AN L, NOT AN I
What to put in the parentheses:

Serial.print( “This is a string literal…” ); int x=99;

String literals get printed exactly as they’re Serial.print(x);


typed.
You may also have a variable between the
parentheses and its value gets printed.
Send int data It will only read one integer of data
at a time - that’s like a single

TO the Arduino number or character.

Using the Serial.pareseInt()


function int inputValue=Serial.parseInt();
How to actually
SEE the serial
monitor
AFTER you have a program RUNNING
on the Arduino,

Click the magnifying glass icon


located in the upper right
A program to void setup() {
// put your setup code here, to run once:
interact with your Serial.begin(9600);
pinMode(13,OUTPUT);
Arduino. }

void loop() {
int inValue;
In the Serial Monitor, the program // put your main code here, to run repeatedly:
should ask you how many times to Serial.println("How many times do you want the LED to blink?");
blink, and when the user enters the while(!Serial.available()) ;
number it blinks the onboard LED that inValue=Serial.parseInt();
many times. Serial.read();
Serial.print("Blinking onboard LED ");
Serial.print(inValue);
Serial.println(" times.");
for(int i=0; i<inValue; i++) {
Try it - you don’t need any components digitalWrite(13,HIGH);
connected to the Arduino to see it delay(200);
work. digitalWrite(13,LOW);
delay(200);
}
}

You might also like