You are on page 1of 7

SERIAL MONITOR

LAB 2
Didam Ahmed
Serial Monitor
• Serial Monitor window to display data from the Arduino and send data
to the Arduino from the computer keyboard.
• Before we can use the Serial Monitor, we need to activate it by adding
this function to our sketch in void setup():
Serial.begin(9600);
• The value 9600 is the speed at which the data will travel between the
computer and the Arduino, also known as baud.
Sending Text to the Serial Monitor
• To send text to the Serial Monitor to be displayed in the output window,
you can use Serial.print:
Serial.print("Arduino for Everyone!");
• This sends the text between the quotation marks to the Serial Monitor’s
• output window. You can also use Serial.println to display text and then
force any following text to start on the next line:
Serial.println("Arduino for Everyone!");
Serial Communication - Reading
Serial.available()
Returns the number of bytes available to be read, if any
Example:
if (Serial.available() > 0)
{
data = Serial.read();
}
Serial Reading
• Serial.parseInt(): used for reading integer from serial port
• Serial.parseFloat(): for reading float from serial port
• Serial.readString(): reads characters from the serial buffer into a
string.
• Serial.read():use to reads incoming serial data

• Also
• Serial.flush():used to flush the data send through Arduino Serially
Project
• User enter number of blinks through serial port
int pin=12; // to define the red pin on circuit
int ondelay=1000;
int offdelay=500;
int blinks;
void setup(){

Serial.begin(9600);
pinMode(pin,OUTPUT);
}

void loop(){
Serial.println("HOW MANY TIMES YOU WANT TO BLINK RED LED ?"); //to ask foe input about the number of blinks of red led.
while(Serial.available()==0){ } //wait for the input value
blinks=Serial.parseInt(); //to take value of number of red blinks from the serial monitor
for(int j=1;j<=blinks;j=j+1){
Serial.println(j);
digitalWrite(pin,HIGH);
delay(ondelay);
digitalWrite(pin,LOW);
delay(offdelay);
}
}

You might also like