মূল বিষয়বস্তুতে যান
Learn/First steps with Arduino Uno/Talking to your computer: Serial
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
Open in Lab
UNOATmega328P: The 8-bit AVR microcontroller that runs your sketch (16 MHz, 32 KB flash, 2 KB RAM).ATmega328PUSB-B: USB connection for uploading sketches and for the Serial Monitor. Also powers the board (5 V).DC jack: Barrel jack for 7–12 V from a battery pack or adapter (centre positive).ATmega16U2: Converts USB to serial for uploads and Serial.print().RESET: Restarts your sketch from the beginning (setup() runs again).L (D13): Built-in LED connected to pin 13 (LED_BUILTIN).ON: Power indicator.5 V regulator: Turns 7–12 V from VIN/jack into a steady 5 V.16 MHz: Clock source: the microcontroller runs 16 million cycles per second.ICSP: In-circuit programming header (SPI). Used to burn a bootloader; not needed for normal uploads.220 Ω220 Ω220 Ω+++
Note: This traffic light prints each phase. Open the Serial tab while it runs.

Check Your Understanding

Test what you learned in this lesson

1Your sketch uses Serial.begin(115200) but the monitor is set to 9600. What do you see?