Introduction
Serial communication is one of the most fundamental skills in embedded electronics. Whether you’re debugging a sensor, talking to a GPS module, or sending data to a PC, the humble USART (Universal Synchronous/Asynchronous Receiver/Transmitter) is your go-to tool. In this tutorial, we’ll build a simple Serial Echo project using an Arduino Uno in the Velxio simulator. Every character you type in the Serial Monitor is echoed back with its ASCII value and a running count. It’s the “Hello, World!” of serial communication.

Circuit Walkthrough
This project is remarkably simple—it uses only the Arduino Uno board itself. No external components are needed because the serial communication happens over the USB-to-serial converter built into the Uno. In Velxio, the Serial Monitor is integrated into the editor toolbar, so you can interact with your code immediately.
Components
| Component | Quantity | Notes |
|---|---|---|
| Arduino Uno (wokwi-arduino-uno) | 1 | The brain of the operation |
That’s it! The Arduino Uno’s TX (pin 1) and RX (pin 0) are internally connected to the USB interface, which Velxio emulates perfectly. No wiring is required.

Code Walkthrough
Let’s dive into the code. Open the Velxio editor and you’ll see the following sketch:
// Serial Echo — USART Protocol Test
// Open the Serial Monitor to send and receive data.
// Everything you type is echoed back with extra info.
void setup() {
Serial.begin(9600);
Serial.println("=============================");
Serial.println(" Serial Echo Test (USART)");
Serial.println("=============================");
Serial.println("Type something and press Send.");
Serial.println();
// Print system info
Serial.print("CPU Clock: ");
Serial.print(F_CPU / 1000000);
Serial.println(" MHz");
Serial.print("Baud rate: 9600");
Serial.println();
Serial.println();
}
unsigned long charCount = 0;
void loop() {
if (Serial.available() > 0) {
char c = Serial.read();
charCount++;
Serial.print("[");
Serial.print(charCount);
Serial.print("] Received: '");
Serial.print(c);
Serial.print("' (ASCII ");
Serial.print((int)c);
Serial.println(")");
}
// Periodic heartbeat
static unsigned long lastBeat = 0;
if (millis() - lastBeat >= 5000) {
lastBeat = millis();
Serial.print("Uptime: ");
Serial.print(millis() / 1000);
Serial.print("s | Chars received: ");
Serial.println(charCount);
}
}

How It Works
-
Setup: We initialize serial communication at 9600 baud using
Serial.begin(9600). Then we print a banner and system info: the CPU clock speed (F_CPU / 1000000 gives MHz) and the baud rate. -
Global variable:
unsigned long charCount = 0;keeps track of how many characters we’ve received. -
Loop:
if (Serial.available() > 0)checks if data is waiting in the receive buffer.char c = Serial.read();reads one character.- We increment
charCountand print a formatted message:[count] Received: 'c' (ASCII 99). - Every 5 seconds, we print a heartbeat with uptime and total characters received.
Key Concepts for Students
- Baud Rate: The speed of serial communication. Both sides must agree on the same baud rate (here 9600).
- Serial.available(): Returns the number of bytes waiting to be read. Always check before reading to avoid getting -1.
- Serial.read(): Reads a single byte (character) from the buffer.
- ASCII: Each character has a numeric code. For example, ‘A’ is 65. The code casts
ctointto show this. - millis(): Returns milliseconds since the program started. Useful for non-blocking timing.
- static variables:
static unsigned long lastBeatretains its value between loop iterations, unlike local variables.
Common Pitfalls and Debugging Tips
- Serial Monitor not showing output? Make sure you’ve opened the Serial Monitor in Velxio (click the “Serial Monitor” button in the toolbar). Also check that the baud rate in the monitor matches 9600.
- Garbage characters? Baud rate mismatch is the most common cause. Double-check
Serial.begin(9600)and the monitor setting. - Nothing happens when you type? Ensure you’re pressing “Send” or Enter after typing. The code reads one character at a time.
- Heartbeat not printing? The
if (millis() - lastBeat >= 5000)condition uses>=to avoid missing the interval. If you see no heartbeat, check thatlastBeatis updated correctly.
Suggested Extensions
Once you’ve mastered the basic echo, try these enhancements:
- Echo whole lines: Instead of echoing each character, accumulate characters until newline, then echo the entire line.
- Command parser: Interpret special commands like “LED ON” to turn on an LED (add an LED to the circuit).
- Binary output: Print the received character in binary format.
- Multiple baud rates: Let the user change baud rate via a command.
- Log to virtual EEPROM: Store received data in the simulated EEPROM.
Conclusion
You’ve just built your first serial communication project! The Serial Echo is a simple but powerful demonstration of how microcontrollers talk to the outside world. With Velxio, you can experiment without any hardware—just open the simulator, write code, and test instantly.
Ready to try it yourself? Open the live example in Velxio and start typing: Serial Echo on Velxio. Happy coding!