Arduino UART

Introduction

UART (Universal Asynchronous Receiver-Transmitter) is an essential serial communication protocol in the world of electronics and microcontrollers. It enables simple, efficient communication between an Arduino and other peripherals such as sensors, GPS modules, Bluetooth modules, computers and so on.

This communication takes place via the Arduino’s digital pins, using asynchronous serial data transmission.

How it works

A UART (Universal Asynchronous Receiver Transmitter) link is a universal asynchronous transceiver. The UART link is exclusive, meaning that a master can only talk to one slave per link, as shown below:

The uart link is asynchronous, which means that transmission does not require a clock, but adds a parity bit to the data before transmission.

It’s an exclusive link, meaning that a single wire carries all the data bits.

The UART link is a full-duplex link, meaning that you can listen while transmitting bits. The UART link has a low data rate, from 100 bps to 200 kbps.

The UART converts the microcontroller’s parallel data into serial data, transmits it bit by bit, then converts the serial data back into parallel data on the receiver side. UART communication is asynchronous, which means it does not require a shared clock signal between the transmitting and receiving devices.

The UART communication lines are :

  • TX (Transmit): Sends data.
  • RX (Receive): Receives data.

These two lines enable bidirectional data exchange.

UART pin on the Arduino board

On Arduino boards, the UART is used during program transmission. This is why we advise you to disconnect the component connected to the UART if you wish to upload a new program. Otherwise you’ll get an error on the Arduino IDE.

Pin configuration

  • Arduino Uno/Nano: TX (pin 1), RX (pin 0)
  • Arduino Mega: Several hardware serial ports, including Serial1, Serial2, and Serial3.

Here’s where the pins are located on the Arduino UNO board:

Writing to the UART

Writing to the UART is very simple with Arduino, as the bus can be read using the Arduino IDE serial monitor. Here’s a program to write to the UART on your Arduino board:

void setup() {
  Serial.begin(9600); // Initialize serial communication at 9600 bauds
}

void loop() {
  Serial.println(“Hello, UART!”); // Send text to serial port
  delay(1000); // Wait one second
}

To see the “Hello UART”, simply connect your Arduino to your computer and open the serial monitor in Arduino IDE at 9600 bd/s.

Reading the UART

You can also use the Arduino IDE serial monitor to read from the UART. Simply send some text or value through the serial monitor, and the Arduino board will reply what it has read on the serial monitor with the following program:

void setup() {
  Serial.begin(9600); // Initialize serial communication at 9600 bauds
}

void loop() {
  if (Serial.available() > 0) { // Checks if data is available
    int incomingByte = Serial.read(); // Reads data
    Serial.print("I have received: ”);
    Serial.println(incomingByte, DEC); // Display received data
  }
}

Conclusion

If you’d like to know more about communication buses on Arduino, we’ve made some sews on SPI and I2C.