First steps with Arduino Uno · Lesson
9 min read
Talking to your computer: Serial
Print values to the Serial Monitor to see what your sketch is doing.
What You Will Learn
- Start serial at a baud rate
- Print text and numbers
- Use serial output to debug
Serial.begin(9600) opens the USB serial link at 9600 baud (bits per second). The Serial Monitor must use the same speed or you will see garbage.
Arduino C++
void setup() {
Serial.begin(9600);
Serial.println("Hello from Arduino!");
}
int count = 0;
void loop() {
Serial.print("count = ");
Serial.println(count);
count++;
delay(1000);
}- print() writes without a new line; println() ends the line.
- Serial.println(x, HEX) prints in hexadecimal; Serial.println(3.14159, 3) prints 3 decimals.
- Printing values is the fastest way to find bugs.
Traffic lightarduino-uno
Note: This traffic light prints each phase. Open the Serial tab while it runs.
Check Your Understanding
Test what you learned in this lesson