0% found this document useful (0 votes)
28 views10 pages

Lecture 12 Experiment-16

This document discusses serial UART communication between two Arduino boards. It explains that UART allows devices to communicate by transmitting data via a Tx pin and receiving data via an Rx pin. It provides code for an Arduino board configured as a master to transmit a string via Tx and for a slave board to receive the string via Rx. Finally, it shows how to connect the Tx and Rx pins between the boards and provides code to blink an LED by transmitting 1s and 0s from one board to control an LED on the other board.
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)
28 views10 pages

Lecture 12 Experiment-16

This document discusses serial UART communication between two Arduino boards. It explains that UART allows devices to communicate by transmitting data via a Tx pin and receiving data via an Rx pin. It provides code for an Arduino board configured as a master to transmit a string via Tx and for a slave board to receive the string via Rx. Finally, it shows how to connect the Tx and Rx pins between the boards and provides code to blink an LED by transmitting 1s and 0s from one board to control an LED on the other board.
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/ 10

ECE 2030

Arduino Based System


Design

Daw Khaing Su Wai


Experiment 16
Serial UART Communication between
Two Arduino Boards
Serial UART Communication
• UART (Universal Asynchronous Receiver-Transmitter) is the most used serial communication
protocol in which data format and communication speed is configurable.
• Arduino has three communication protocols named SPI, I2C and UART.
• UART protocol allows Arduino to communicate between different devices and sensors.
• Now will discuss how to use UART communication between two Arduino boards.
Serial UART Communication
• Serial UART is the serial communication protocol used by Arduino to communicate with
microcontrollers and PCs.
• Arduino has one UART port at D0 and D1.
• A serial bus with two terminals is used in UART communication, one for sending data named Tx
at pin D1 and another one for receiving data which is denoted as Rx at pin D0.
• So, all the devices that works over UART protocol must have two serial pins:
• Rx for Receiving data
• Tx for Transmitting data

https://linuxhint.com/serial-uart-communication-between-two-arduino/
Serial UART Communication
• While using these two pins for UART It’s important to note that UART pins are specific for a
device itself.
• To establish serial communication using UART between two Arduino boards then the Rx pin of
first board will be connected to the Tx pin of second board similarly Tx pin of first one with Rx
pin of second one.
• Connect two Arduino boards using Tx and Rx pins to establish a serial communication between
them one Arduino board which will transmit data will act as a Master and the second Arduino
board which will receive instructions will act as Slave.
• Setup Arduino boards in Master and Slave configuration.
• To start communication between two Arduino boards, one will be configured as Sender and
other Arduino board as the receiver.
• So, write two programs, one for sender and second for receiver.
Serial UART Communication
Connect Master Arduino
• Using a USB B cable connects the Arduino board which is acting as Master to the PC.

//Sender Arduino Board Code (Master)


char mystring[15] = "LinuxHint.com "; //String data which is
to be sent
void setup() {
Serial.begin(9600); // Begin the Serial at 9600 Baud
rate
}
void loop() {
Serial.write(mystring,15); //Write the serial data
delay(1000);
}

https://linuxhint.com/serial-uart-communication-between-two-arduino/
Serial UART Communication
Connect Slave Arduino
• Using a USB B cable connects the Arduino board which is acting as Master to the PC.

//Receiver Arduino Board Code


char mystring[20]; //Initialized variable to store receive
void setup() {
Serial.begin(9600); // Begin the Serial at 9600 Baud
}
void loop() {
Serial.readBytes(mystring,15); //Read the serial data
Serial.println(mystring); //Print data on Serial Monitor
Serial.println(" RECEIVER");
delay(1000);
}

https://linuxhint.com/serial-uart-communication-between-two-arduino/
Serial UART Communication
Connect Both Arduino Using TX and Rx Pins

https://linuxhint.com/serial-uart-communication-between-two-arduino/
Blink LED Using Two Arduino Boards through UART Communication

//Transmitter (Tx) Arduino Board Code

void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.print(1);
delay(2000);
Serial.print(0);
delay(2000);
}

https://howtomechatronics.com/tutorials/arduino/ultrasonic-sensor-hc-sr04/
Blink LED Using Two Arduino Boards through UART Communication
//Receiver (Rx) Arduino Board Code

char serialinput = ' ';


byte LED = 2;

void setup()
{
pinMode(LED, OUTPUT);
Serial.begin(9600);
}
void loop()
{
if(Serial.available())
{
char serialinput = Serial.read();
if (serialinput =='0') { digitalWrite(LED, LOW); }
if (serialinput =='1') { digitalWrite(LED, HIGH); }
Serial.println(serialinput);
}
}
https://howtomechatronics.com/tutorials/arduino/ultrasonic-sensor-hc-sr04/
Blink LED Using Two Arduino Boards through UART Communication

https://howtomechatronics.com/tutorials/arduino/ultrasonic-sensor-hc-sr04/

You might also like