0% found this document useful (0 votes)
45 views4 pages

Serial Communication Practical

The document discusses sending data from a computer to an Arduino board through the serial monitor. It provides an example sketch that reads data sent as individual characters from the serial monitor and prints or writes it back. It also provides examples of controlling an onboard LED and connecting two Uno boards through serial communication.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views4 pages

Serial Communication Practical

The document discusses sending data from a computer to an Arduino board through the serial monitor. It provides an example sketch that reads data sent as individual characters from the serial monitor and prints or writes it back. It also provides examples of controlling an onboard LED and connecting two Uno boards through serial communication.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Sending data from computer to Arduino

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

Code for board 1


void setup() {
Serial.begin(9600);
pinMode(13,OUTPUT); pinMode(8,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);
else if (c=='R') digitalWrite(8,HIGH);
else if (c=='r') digitalWrite(8,LOW);

Code for board 2


void setup() {
Serial.begin(9600);
}

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);

Practical 3 – Bluetooth Module

You might also like