Serial Communication
Introduction to Communication:-
Communication refers to the process of exchanging ideas, thoughts, and experiences between two or more persons. In IOT it refers to the process of exchange of data between two devices.
1. Parallel Communication:-
Parallel Communication is Communication in which Data is transmitted simultaneously across multiple data lines.
2. Serial Communication:-
Serial Communication is a Communication in which Data is transmitted one bit at a time across a single line.
What is the Baud Rate?
Baud rate is the rate of data at which it is transmitted over a communication channel. It is measured in bits per second.
Function of Serial Communication with Arduino.
1. Serial.begin(9600):- It tells the Arduino to get ready to exchange messages with the serial monitor at the baud rate of 9600 bits per second.
2.Serial.available( ):- This function Sends the data received to one serial port to another.
3.Serial.read( ):- This function reads the data received at the serial port.
4.Serial.print ( ):- This function prints the message on the Serial monitor.
5.Serial.println( ):- This function prints the message on the Serial monitor and goes to new line.
6.Serial.readString( ):- It is used to read the String.
Task 1: To display a message on Serial monitor.
Code:-
void setup()
{
Serial.begin(9600);
Serial.println("We are learning Serial Communication");
}
void loop()
{
}
Output:-
Code:-
int sw=8;
void setup()
{
Serial.begin(9600);
}
void loop()
{
if (digitalRead(sw)==LOW)
{
Serial.println("We are learning Serial Communication");
delay(1000);
}
}
Output:-
Task 3: To print the received serial message on a Serial monitor .
Code:-
int sw=8;
void setup()
{
Serial.begin(9600);
}
void loop()
{
if (Serial.available()>0)
{
String ch =Serial.readString();
Serial.println(ch);
}
}
Output:-
0 Comments