Introduction
Welcome to another Velxio tutorial! Today we’re building a Serial Echo test for the Raspberry Pi Pico (RP2040). This project is perfect for beginners who want to understand how serial communication works on microcontrollers. You’ll learn how to send and receive data over UART, add a visual indicator with an LED, and implement a simple heartbeat timer.

Circuit Walkthrough
The circuit is delightfully simple. We only need two components:
- Raspberry Pi Pico (the brain)
- Yellow LED (visual indicator for serial activity)
Wiring
- Connect the anode (A) of the yellow LED to the TX pin of the Pico. The TX pin is used for serial transmission, so every time the Pico sends data, the LED will blink.
- Connect the cathode (C) of the LED to GND (any ground pin on the Pico).
That’s it! The LED is wired in series with the TX line, so it lights up when the Pico transmits. This gives you a visual confirmation that serial data is flowing.

Code Walkthrough
Let’s dive into the code. Open the Velxio editor and you’ll see the following sketch:
// Raspberry Pi Pico — Serial Echo Test
// Echoes received characters and prints a heartbeat every 2 seconds
void setup() {
Serial.begin(115200);
delay(500);
Serial.println("=== Pico Serial Echo ===");
Serial.println("Type something and press Enter.");
Serial.println();
}
unsigned long lastHeartbeat = 0;
void loop() {
// Echo any incoming characters
while (Serial.available()) {
char c = Serial.read();
Serial.print("Echo: ");
Serial.println(c);
}
// Heartbeat every 2 seconds
if (millis() - lastHeartbeat >= 2000) {
lastHeartbeat = millis();
Serial.print("[Heartbeat] Uptime: ");
Serial.print(millis() / 1000);
Serial.println("s");
}
}
How It Works
setup(): Initializes serial communication at 115200 baud. After a short delay, it prints a welcome message.loop(): Two main tasks:- Echo: Checks if any data is available on the serial port. If yes, it reads one character and prints it back with an “Echo:” prefix.
- Heartbeat: Every 2000 milliseconds (2 seconds), it prints a heartbeat message showing the system uptime in seconds.
The lastHeartbeat variable keeps track of the last time the heartbeat was printed, using millis() for non-blocking timing.
Key Concepts
Serial Communication (UART)
UART (Universal Asynchronous Receiver/Transmitter) is a simple serial protocol. The Pico’s TX pin sends data, and the RX pin receives data. In this example, we only use TX for output, but the echo function also uses RX (via the Serial Monitor).
Non-blocking Timing with millis()
Instead of using delay(), which pauses the entire program, we use millis() to check elapsed time. This allows the echo loop to run continuously while still printing the heartbeat at regular intervals.
LED as a Visual Indicator
By connecting the LED to the TX pin, we get a real-time visual of serial activity. Every time the Pico sends a character, the LED blinks briefly.
Common Pitfalls & Debugging Tips
- Baud rate mismatch: Ensure the Serial Monitor is set to 115200 baud. If you see garbage characters, check the baud rate.
- LED not blinking: Verify the LED polarity (anode to TX, cathode to GND). Also check that the Pico is actually transmitting (e.g., type something in the Serial Monitor).
- No echo: Make sure you’re sending data to the Pico’s RX pin. In Velxio, the Serial Monitor handles this automatically.
- Heartbeat not printing: Check that
lastHeartbeatis declared asunsigned longand that the comparison logic is correct.

Suggested Extensions
Once you have the basic echo working, try these enhancements:
- Add an RX LED: Connect another LED to the RX pin to show when data is received.
- Command parsing: Instead of just echoing, interpret commands like “LED ON” or “LED OFF” to control an external LED.
- Multiple baud rates: Allow the user to change baud rate via a serial command.
- Log to console: Store received data in a buffer and print it on request.

Call to Action
Ready to try it yourself? Open the live example on Velxio and start experimenting: Pico Serial Echo on Velxio. You can modify the code, change the LED color, or add new components. Happy hacking!