Introduction
Welcome to the Serial LED Control project! In this tutorial, you’ll learn how to control an LED connected to an Arduino Uno by sending simple commands over the Serial Monitor. This is a classic beginner project that combines two fundamental concepts: USART (Universal Synchronous/Asynchronous Receiver-Transmitter) communication and GPIO (General Purpose Input/Output) output. By the end, you’ll be able to turn an LED on and off by typing “1” or “0” in the Serial Monitor, and even query the LED’s status with ”?”.
We’ll be using Velxio, an in-browser circuit and microcontroller simulator with SPICE-accurate analog support. No hardware needed—just your browser! Let’s dive in.
Circuit Walkthrough

The circuit is incredibly simple. You only need two components:
- Arduino Uno (the brain)
- Green LED (the output device)
Wiring Details
- LED Anode (long leg, pin A) connects to Arduino pin 13 via a green wire (
#00cc00). - LED Cathode (short leg, pin C) connects to Arduino GND via a black wire (
#000000).
That’s it! No resistor is needed because the Arduino Uno’s pin 13 already has a built-in current-limiting resistor on the board. In a real circuit, you’d add a 220Ω resistor in series with the LED, but for simulation, this works perfectly.
How to Build in Velxio
- Open the Serial LED Control example in Velxio.
- You’ll see the Arduino Uno and LED already placed on the canvas. If you want to build from scratch, use the component picker (shown below) to add an Arduino Uno and an LED.

- Click on the Arduino Uno to select it, then click on pin 13. Drag a wire to the LED’s anode (pin A).
- Similarly, wire the LED’s cathode (pin C) to any GND pin on the Arduino.
- Use the canvas toolbar to zoom and pan for a better view.

Code Walkthrough

Now let’s examine the code that makes this work. Open the code editor in Velxio (you’ll see the Monaco editor with syntax highlighting).
// Serial LED Control
// Send "1" to turn LED ON, "0" to turn LED OFF.
// Demonstrates Serial input controlling hardware.
const int LED_PIN = 13;
void setup() {
Serial.begin(9600);
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW);
Serial.println("=========================");
Serial.println(" Serial LED Controller");
Serial.println("=========================");
Serial.println("Send '1' = LED ON");
Serial.println("Send '0' = LED OFF");
Serial.println("Send '?' = Status");
Serial.println();
}
bool ledState = false;
void loop() {
if (Serial.available() > 0) {
char cmd = Serial.read();
switch (cmd) {
case '1':
digitalWrite(LED_PIN, HIGH);
ledState = true;
Serial.println("[OK] LED is ON");
break;
case '0':
digitalWrite(LED_PIN, LOW);
ledState = false;
Serial.println("[OK] LED is OFF");
break;
case '?':
Serial.print("[STATUS] LED is ");
Serial.println(ledState ? "ON" : "OFF");
Serial.print("[STATUS] Uptime: ");
Serial.print(millis() / 1000);
Serial.println("s");
break;
default:
if (cmd >= 32) { // ignore control chars
Serial.print("[ERR] Unknown command: '");
Serial.print(cmd);
Serial.println("' (use 1, 0, or ?)");
}
break;
}
}
}
How It Works
const int LED_PIN = 13;– We define the LED pin as 13 (the built-in LED pin on Arduino Uno).setup()– Initializes Serial communication at 9600 baud, sets the LED pin as an output, and prints a welcome message.loop()– Checks if data is available on the Serial port. If yes, it reads one character and processes it with aswitchstatement.'1': Turns the LED on (digitalWrite(LED_PIN, HIGH)) and updatesledState.'0': Turns the LED off (digitalWrite(LED_PIN, LOW)).'?': Prints the current LED state and the system uptime in seconds.- Any other printable character prints an error message.
Running the Simulation
- Click the Run button in the editor toolbar.

- Open the Serial Monitor (usually a button in the toolbar or a separate panel).
- Type
1and press Enter – the green LED should light up. - Type
0– the LED turns off. - Type
?– you’ll see the status and uptime.
Key Concepts for Students
This project teaches several important concepts:
- Serial Communication: The Arduino communicates with your computer via USART.
Serial.begin(9600)sets the baud rate (bits per second). - GPIO Output:
pinMode()anddigitalWrite()control digital pins. - State Variables:
ledStatekeeps track of the LED’s current state, allowing the status command to work. - Input Parsing: Reading characters from Serial and using
switchto handle commands. - Error Handling: The
defaultcase catches invalid input and provides feedback.
Common Pitfalls and Debugging Tips
- Serial Monitor not showing output? Make sure the baud rate matches (9600). Also, ensure you’ve clicked the Serial Monitor’s connect button.
- LED not responding? Check that the LED is wired correctly: anode to pin 13, cathode to GND. In Velxio, wires are color-coded; verify the connections.
- Commands not working? The code ignores non-printable characters (ASCII < 32). If you send newlines, they are ignored. Use the Serial Monitor’s “No line ending” option or send only the character.
- Multiple characters? The code reads one character at a time. If you send “10”, it will process ‘1’ then ‘0’ in separate loop iterations.
Suggested Extensions
Once you’ve mastered this project, try these enhancements:
- Add a second LED on pin 12 and control it with commands like ‘2’ and ‘3’.
- Use PWM to control brightness: send a number from 0 to 255 to set LED brightness via
analogWrite(). - Add a button as input: read a digital pin and toggle the LED when pressed.
- Implement a command parser that accepts strings like “ON” or “OFF” instead of single characters.
- Log data to the Serial Monitor: print sensor readings or timestamps.
Conclusion
You’ve just built a simple yet powerful Serial LED controller! This project is the foundation for countless IoT and automation projects where you control hardware via text commands. Velxio makes it easy to experiment without any physical components.
Ready to try it yourself? Open the Serial LED Control example in Velxio, run the simulation, and start sending commands. Happy tinkering!