0% found this document useful (0 votes)
48 views7 pages

Serial Monitor: Lab 2 Didam Ahmed

This document discusses using the serial monitor in Arduino. It explains that the serial monitor allows communication between the Arduino and computer by displaying data from the Arduino and allowing data to be sent from the computer keyboard. The serial monitor must be activated by adding Serial.begin(9600) to the setup function. Text and data can be sent to the serial monitor using Serial.print, Serial.println, Serial.parseInt and other Serial functions. An example is provided that takes a number of blinks from the serial monitor and blinks an LED that number of times.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views7 pages

Serial Monitor: Lab 2 Didam Ahmed

This document discusses using the serial monitor in Arduino. It explains that the serial monitor allows communication between the Arduino and computer by displaying data from the Arduino and allowing data to be sent from the computer keyboard. The serial monitor must be activated by adding Serial.begin(9600) to the setup function. Text and data can be sent to the serial monitor using Serial.print, Serial.println, Serial.parseInt and other Serial functions. An example is provided that takes a number of blinks from the serial monitor and blinks an LED that number of times.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 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