انتقل للمحتوى
Robo EgyptRobo Egypt
☰ Course contents
Robo Maker: home
0. Lab tour1
1. The start: the Arduino6
2. Wiring and the traffic light4
3. Inputs: the button4
4. Sound and movement5
5. Sensors and numbers5
6. Distance, the screen and colours5
7. Motors and the car4
8. The project: the city's smart gate3
9. From blocks to C++ code5
10. Sensors and screens in code5
11. Smart systems5
12. Bluetooth: control from the phone1

The Arduino writes to you: Serial

Section 9: From blocks to C++ codeLesson 9.3 · ⏱ 6 min

Serial.println makes the Arduino write a line in the Serial Monitor under the code. Engineers use it to know what is happening inside the program.

⚙️ Write your name
void setup() {
  Serial.begin(9600);
  Serial.println("Youssef");
}

void loop() {
}
🖥️ The Serial in Robo Maker:
Youssef
The name in the Serial screen
The name in the Serial screen

📌 Another example: two lines

The Arduino writes two lines: the greeting, then the question.

⚙️ Two lines
void setup() {
  Serial.begin(9600);
  Serial.println("Hello!");
  Serial.println("How are you?");
}

void loop() {
}
🖥️ Serial Monitor
Hello!
How are you?
✍️ Practise
Write your name in English.
✍️ Practise here in the lessonor open the lab in a new page ↗

🎯 Challenge yourself

Easy

Write your name and your city on two lines.

👀 Show the solution
⚙️ Solution
void setup() {
  Serial.begin(9600);
  Serial.println("Mona");
  Serial.println("Cairo");
}

void loop() {
}
🖥️ Serial Monitor
Mona
Cairo

Result: two lines: the name and the city.

Medium

print without ln: write “Robo” and “Egypt” on the same line.

👀 Show the solution
⚙️ Solution
void setup() {
  Serial.begin(9600);
  Serial.print("Robo ");
  Serial.println("Egypt");
}

void loop() {
}
🖥️ Serial Monitor
Robo Egypt

Result: Robo Egypt on one line.

Hard

Write “Hi” every second, inside loop.

👀 Show the solution
⚙️ Solution
void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.println("Hi");
  delay(1000);
}
🖥️ Serial Monitor
Hi
Hi
Hi
Hi

Result: it repeats every second.

Finished the lesson? Mark it so your progress counts.