You are on page 1of 10

INTRODUCTION TO UART

AND RADIO FREQUENCY COMMUNICATION

WHAT IS UART?
Stands for Universal Asynchronous Receiver Transmitter.
One of the serial communication available in Arduino, computer, .
A protocol which do not have external clock line like SCK in SPI
protocol or SCL in I2C protocol, hence the name asynchronous.

Basically consists of 2 lines; Receiver and Transmitter


When one Transmits, the other would Receive and vice versa.
Requires exclusive connection for each device.

HOW THE DATA IS BEING TRANSMITTED?

THERES NO CLOCK LINE, SO HOW DOES


IT SYNCHRONISE THE DATA
TRANSMISSION?
UART requires us to specify the rate of the data flow or
transmission before any data transmission occur for BOTH
devices. The rate of transmission is called baud rate. Both
devices must communicate at the same speed or well get
rubbish or garbled data at the other end. Baud rate is measured
in bits per second.

Usually only goes up to 230400 bps. Typical baud rates used in


Arduino are 9600, 19200, 38400, 57600, 115200 etc.

MORE ABOUT BAUD RATE


Higher baud rate means faster data transfer, but might have
some packet loss. On RF or remote communication, higher
baud rate could cause shorter area of effect, or closer
communication distance. Slower baud rate should be able to
make longer or further communication distance.

Some slow devices might not going to be able to catch up


with faster devices. For example, GPS modules default baud
rate is 38400 bps. Arduino are unable to capture all the data
without reducing the GPS baud rate first.

TYPICAL CONNECTION

Device 1 can be an Arduino while Device 2 can be RF, Bluetooth, GPS or others.

PINS THAT CAN BE USED FOR UART ON


ARDUINO
All Arduino boards have at least one serial port. The hardware UART pins
on Arduino UNO and most Arduino boards are on digital pin 0 (RX) and 1
(TX). Both are labelled on the board. Arduino Mega has three additional
serial ports: Serial1 on pins 19 (RX) and 18 (TX), Serial2 on pins 17 (RX)
and 16 (TX), Serial3 on pins 15 (RX) and 14 (TX).

Pin 0 and 1 are used by the computer when uploading program and
when Serial Monitor is used. When hardware UART pins are used for
communication, it cannot be used for typical digital input output
operation.

BASIC SERIAL COMMUNICATION USING


HARDWARE RX AND TX PINS.
void setup() {
Serial.begin(9600); // Initiate pin 0 and 1 to communicate at 9600 bps
}

void loop() {
Serial.println(Hello, Roboteam!); // Prints a message in Serial Monitor
}

The program above makes the Arduino to transmit the message via RX pin,
so we can also read the message if we tap into the pin.

HOW DO WE CONNECT TO THE OTHER


SENSORS IF THE HARDWARE PINS ARE ALREADY
BEING USED BY THE SERIAL MONITOR?
Luckily, Mikal Hart wrote a library called NewSoftSerial which
was later being adopted in Arduino IDE 1.0 and later and
renamed as SoftwareSerial.

The library is automatically installed for you along with the


Arduino IDE 1.0 and later.

USING SOFTWARESERIAL LIBRARY


// The following is the basic loopback test. Can be used as chat service.
#include <SoftwareSerial.h>
SoftwareSerial rf(2, 3); // Initialize pin 2 as RX and 3 as TX
void setup() {
Serial.begin(9600); // Initiate pin 0 and 1 to communicate at 9600 bps
rf.begin(9600); // Initiate pin 2 and 3 to communicate at 9600 bps
}
void loop() {
if(Serial.available()) { // If theres a message typed in Serial Monitor
rf.write(Serial.read()); // Send the message via RF module
}
if(rf.available()) { // If theres a message received via RF module
Serial.write(rf.read()); // Print the message in the Serial Monitor
}
}

You might also like