What you will learn
  • Distinguish an electrical interface from a message protocol.
  • Send and acknowledge simple USB serial commands.
  • Compare UART, I²C and SPI connections.
  • Explain what extra hardware Uno R3 needs for wireless communication.
  • Design explicit behavior for malformed or missing messages.

Before you begin

Understand digital outputs and the I²C display example. The runnable example needs only an Uno R3 and USB cable.

Communication needs shared rules

Two devices can be connected by a wire and still misunderstand each other. They need compatible electrical levels, timing and a shared interpretation of messages. A protocol is a set of rules for that exchange.

A useful analogy is a letter: the transport delivers marks, while language and formatting determine their meaning. In electronics, the details are less forgiving. A 5 V output connected to an intolerant 3.3 V input can damage hardware before message formatting matters.

The Uno R3 has USB communication through a USB-to-serial interface. Serial lets a sketch exchange bytes with your computer. A byte can represent a character or part of a binary value; our first protocol deliberately uses a few readable characters.

I²C and SPI are commonly used between nearby chips or boards. Bluetooth and Wi-Fi are wireless technologies, usually supported through additional radios and software. The standard Uno R3 has neither built in; a board with a similar name may have different capabilities.

A one-character command protocol

Our protocol accepts 1 to turn the onboard LED on and 0 to turn it off. Each valid command receives an acknowledgment. Spaces, carriage returns and newlines are ignored so Serial Monitor line-ending settings do not accidentally create errors. Other characters produce ERR.

The distinction between the number 1 and the character '1' matters. The character is an encoded byte sent by a text interface. Arduino C/C++ uses single quotes for a character and double quotes for a string of characters.

Only USB connects to the board. Do not wire pins 0 and 1 to another device during this exercise, because they participate in the Uno’s serial connection and can interfere with uploading.

PartPurpose
Arduino Uno R3Executes the command parser
USB data cablePower and serial transport
Arduino IDE Serial MonitorSends characters and displays acknowledgments
Onboard L LEDVisible output; no external circuit
cpp
void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);
  Serial.begin(9600);
}

void loop() {
  if (Serial.available() == 0) return;
  char command = Serial.read();
  if (command == '1' || command == '0') {
    digitalWrite(LED_BUILTIN, command == '1' ? HIGH : LOW);
    Serial.println(command == '1' ? "OK ON" : "OK OFF");
  } else if (command != '\n' && command != '\r' && command != ' ') {
    Serial.println("ERR");
  }
}

available() checks whether a byte is waiting, preventing the program from treating missing input as a command. read() consumes one byte. The parser recognizes an explicit allowlist and acknowledges the resulting output state. return ends only this loop invocation; Arduino calls loop again.

Expected result: At 9600 baud, sending 1 returns OK ON and lights L. Sending 0 returns OK OFF. Sending x returns ERR without changing the previous LED state.

Compare the wired interfaces

UART serial uses transmit and receive signals and agreed timing, commonly described by a baud rate. Direct board-to-board UART also needs compatible voltage levels and ground. Connect one device’s transmitter to the other’s receiver; connecting two outputs together is not the intended arrangement.

I²C uses SDA for data and SCL for clock, with pull-up resistors and addressed devices. Several devices can share the bus if addresses and electrical loading are compatible. A breakout that pulls the lines up to 5 V can be unsafe for a 3.3 V controller even if the sensor chip itself uses 3.3 V.

SPI commonly uses a clock, controller-to-peripheral data, peripheral-to-controller data and a chip-select connection for each peripheral. It often supports faster transfers than typical beginner I²C setups, but exact performance depends on the devices, wiring and configuration.

On Uno R3, hardware SPI uses D11, D12 and D13, with D10 commonly used for chip select; the ICSP header also exposes SPI. The exact signals and library roles should be checked in the Uno pinout. Prefer labelled signal names over guessing from connector shape.

What wireless adds

Bluetooth can connect nearby devices using supported profiles or services. Wi-Fi connects devices to a local network and can provide access to Internet services through that network. Neither automatically defines what an application command means.

An extra radio module brings voltage requirements, firmware, pairing or network setup, and another possible failure point. A beginner should first prove the message protocol over USB. The same command meaning can later move over another transport, with appropriate framing and authentication.

An API is an interface through which software requests behavior from another component. A cloud AI API might return a suggested action to a Python program, but that program still needs to validate the result before sending a bounded hardware command. Raw model text should not become unrestricted actuator instructions.

Network credentials and secret keys belong outside public sketches and screenshots. For a classroom prototype, use a local connection and minimal permissions before introducing remote control.

Design for incomplete conversations

The LED example keeps its last state if communication stops, which is acceptable for this harmless demonstration. A moving robot needs a different rule: commands should expire and the controller should stop if updates cease. Decide that behavior as part of the protocol, not as an afterthought.

For longer messages, define a terminator, a maximum length, allowed fields and a timeout. A parser should reject invalid values rather than trying to guess the sender’s intent. Include sequence or timestamp information when freshness matters.

Test valid commands, invalid characters, extra line endings, a disconnected cable and a reset. Opening a serial connection can reset an Uno, so startup should always be safe. An acknowledgment confirms what the receiver accepted; it does not prove a motor actually moved or an LED was visibly illuminated.

Important terms

Protocol
Rules for exchanging and interpreting information.
Byte
A unit of eight bits.
UART
Hardware for asynchronous serial communication.
Baud rate
A signaling rate used when configuring serial communication.
Acknowledgment
A response confirming that a request was accepted or handled.
API
A defined interface for software to request operations or data.

Mini project: Test a tiny hardware command language

  1. Upload with only USB connected and open Serial Monitor at 9600.
  2. Send 1, 0 and x, recording each expected and actual response.
  3. Repeat with different line-ending settings.
  4. Reset the board and confirm the LED starts off.
  5. Write a sentence explaining what the acknowledgment proves and what it cannot prove.

Common mistakes and debugging

  • Confusing text '1' with numeric byte value 1: specify the encoding and parser.
  • Ignoring voltage compatibility on a direct serial link: validate levels and ground first.
  • Assuming Uno R3 includes wireless radios: check the exact board or add a documented module.
  • Letting the last motor command last forever: moving systems need an independent command timeout.

Independent challenge

Extend the protocol with ? to report the current LED state without changing it. Keep unsupported characters invalid and document the complete command set.

Check your understanding: 10 questions

  1. What does Serial.available() tell the program?

  2. Why ignore carriage return and newline here?

  3. Can two I²C devices always share a bus?

  4. Does Uno R3 have built-in Wi-Fi?

  5. What should happen to a robot when command updates stop?

  6. In your own words, what does “Protocol” mean?

  7. In your own words, what does “Byte” mean?

  8. In your own words, what does “UART” mean?

  9. In your own words, what does “Baud rate” mean?

  10. In your own words, what does “Acknowledgment” mean?

Quiz answers

Reveal all 10 answers after your attempt
  1. How many incoming bytes are currently waiting to be read.
  2. Text tools may append them; they are not output commands.
  3. No. Addresses, voltage levels, pull-ups and electrical loading must be compatible.
  4. No.
  5. Its controller should expire the command and enter a defined safe stop state.
  6. Rules for exchanging and interpreting information.
  7. A unit of eight bits.
  8. Hardware for asynchronous serial communication.
  9. A signaling rate used when configuring serial communication.
  10. A response confirming that a request was accepted or handled.

Summary

A reliable connection combines compatible electrical signaling with explicit message rules and failure behavior. USB serial is an accessible place to learn those rules before adding radios or AI.

Continue learning

ARD09 combines sensing, decisions, a motor driver and safe startup in a complete small rover.

Choose a connected learning path

Sources and further reading

Prepared 2026-09-18. Editorial draft; primary documentation consulted. Hardware build not bench-tested; code has not been executed on the reference board.

GO DEEPER

Extra reading & source documents

Optional reading alongside the lessons. These sources do not add to your course lesson count.

Explore the AI model guides →