Arduino Serial Communication Basics with Serial Port
Arduino Serial Communication Basics with Serial Port
Serial communication is one of the most practical tools in an engineer’s toolkit. It lets you send data from Arduino to your computer and vice versa over a USB cable, which is essential for debugging and interactive control. This guide walks through every Serial command you’ll use regularly.
Setting Baudrate: The Communication Speed
Before two devices can talk, they must agree on a speed. This is called the Baudrate and is set once at the start of your program. The Arduino board and your computer’s Serial Monitor must use the same value, or the output will be unreadable.
Common Baudrate values:
| Baudrate | Typical use |
|---|---|
| 9600 | Default for most beginner projects |
| 57600 | Moderate-speed data transfer |
| 115200 | Higher-speed communication |
Arduino supports 110, 300, 1200, 2400, 4800, 14400, 38400, 230400, 460800, and 921600 as well.

Core Serial Commands on Arduino
Serial.begin(speed)
Opens the serial port and sets the communication speed. Place this once inside setup() at the beginning of your program.
void setup() {
Serial.begin(9600); // Set Baudrate to 9600
}
Serial.print() and Serial.println()
Send data to the Serial Monitor. The println variant appends a newline character, making each output appear on its own line.
Serial.print("Welcome to ");
Serial.println("My Arduino");
Serial.available() and Serial.read()
Check whether incoming data is waiting in the buffer. If available() returns greater than zero, use read() to grab one byte. These two commands work together in most input-handling sketches.
if (Serial.available() > 0) {
char key = Serial.read();
}
Serial.flush()
Waits until all outgoing data in the transmit buffer has been sent. Useful when you need to ensure a complete message is delivered before your program continues.
Example 1: Arduino Sends Data to the Computer
This sketch repeatedly sends “My Arduino” to the Serial Monitor every second.
void setup() {
Serial.begin(9600); // Set Baudrate to 9600
Serial.print("Welcome to ");
Serial.println("My Arduino");
}
void loop() {
Serial.println("My Arduino");
delay(1000); // Wait 1 second
}
How to view the output: Open Arduino IDE → Tools → Serial Monitor and make sure the Baudrate dropdown is set to 9600.

Example 2: Computer Sends Commands to Control LEDs
Connect 4 LEDs with 220–330Ω resistors to pins 2, 3, 4, and 5. Then type the numbers 0–4 in the Serial Monitor to select which LED turns on.
const int led1 = 2;
const int led2 = 3;
const int led3 = 4;
const int led4 = 5;
char key = '0';
void setup() {
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
// Turn all LEDs off initially
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
Serial.begin(9600);
Serial.print("Welcome to ");
Serial.println("My Arduino");
}
void loop() {
// Receive command from computer
if (Serial.available() > 0) {
key = Serial.read();
Serial.print("key : ");
Serial.println(key);
}
// Turn on the selected LED based on the command
if (key == '0') {
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
}
if (key == '1') {
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
}
if (key == '2') {
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
}
if (key == '3') {
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
}
if (key == '4') {
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, HIGH);
}
}
Testing steps:
- Upload the sketch to your Arduino board
- Open the Serial Monitor (set Baudrate to 9600)
- Type the numbers 1–4 and press Send to light up each LED in sequence
- Type 0 to turn all LEDs off

Quick Reference: Serial Commands
| Command | Purpose |
|---|---|
| Serial.begin(speed) | Open serial port, set Baudrate |
| Serial.available() | Check if incoming data is waiting |
| Serial.read() | Read 1 byte from the receive buffer |
| Serial.print(data) | Send data on the same line |
| Serial.println(data) | Send data then move to a new line |
| Serial.flush() | Wait for transmit buffer to empty |
Reference Videos
อยากทำโปรเจคแบบนี้?
รับทำโปรเจค Arduino / IoT จบงานไว ส่งงานครบ พร้อมสอน
If you need Arduino project service or urgent IoT development, see full service details on the home page
จ้างทำโปรเจคเลย