📡 Lesson 5: Serial Communication
⏱️ Estimated time: 20 minutes | Difficulty: Beginner
Talking Back
Serial communication allows the Arduino to send messages to your computer. It's the most powerful tool for debugging your projects and seeing what's happening inside the microchip.
What is Serial?
Serial communication lets Arduino send and receive data to/from your computer through the USB cable. Open the Serial Monitor in Arduino IDE (Tools → Serial Monitor or Ctrl+Shift+M).
Sending Data (Arduino → Computer)
void setup() {
Serial.begin(9600); // Start serial at 9600 baud
}
void loop() {
Serial.println("Hello from Arduino!");
Serial.print("Temperature: ");
Serial.println(25.5);
delay(1000);
}
Receiving Data (Computer → Arduino)
int ledPin = 13;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
Serial.println("Send '1' for ON, '0' for OFF");
}
void loop() {
if (Serial.available() > 0) {
char input = Serial.read();
if (input == '1') {
digitalWrite(ledPin, HIGH);
Serial.println("LED is ON");
} else if (input == '0') {
digitalWrite(ledPin, LOW);
Serial.println("LED is OFF");
}
}
}
Serial Plotter
Use Tools → Serial Plotter to visualize data as a graph in real-time!
void loop() {
int sensorValue = analogRead(A0);
Serial.println(sensorValue); // Shows as graph!
delay(50);
}
✅ Quick Quiz
❓ What does Serial.begin(9600) do?
❓ Difference between print() and println()?
❓ What checks if data is available to read?