Serial Communication Practical
Serial Communication Practical
board (Receive)
The serial monitor can be used to send data from computer to Arduino board.
Try the following sketch.
void setup() {
Serial.begin(9600);
} Type your text here
void loop() {
if (Serial.available()){
char ch=Serial.read(); //read as a char data type
Serial.print(ch); //write it back to serial monitor
delay(1000);
}
}
To send data, type the required data in the text box in the serial monitor and press the send
button.
Note that
o Data is read as char data.
o Data is read one character at a time.
o Delay function is not essential.
o Rx LED on the Uno board will be turn on during the data transfer.
Practical 1 – Controlling built-in LED via
Serial Monitor
void setup() {
Serial.begin(9600);
pinMode(13,OUTPUT);
}
void loop() {
if (Serial.available()>0){
char c=Serial.read();
Serial.println(c);
if (c=='H') digitalWrite(13,HIGH);
else if (c=='L') digitalWrite(13,LOW);
}
Practical 2 - Connecting two UNO boars through
serial Communication
void loop() {
if (Serial.available()>0){
char c=Serial.read();
Serial.println(c);
if (c=='H') digitalWrite(13,HIGH);
else if (c=='L') digitalWrite(13,LOW);
else if (c=='R') digitalWrite(8,HIGH);
else if (c=='r') digitalWrite(8,LOW);
void loop() {
Serial.write('H'); delay(1000);
Serial.write('R'); delay(1000);
Serial.write('G'); delay(1000);
Serial.write('L'); delay(1000);
Serial.write('r'); delay(1000);
Serial.write('\n'); delay(1000);