2

In recent practice, I found out some new things.

Serial.begin(9600);

What is mean of this line of code?

Why here, we always write 9600?

And can we write manually number means instead of 9600 let's say 10000?

1
2

Serial.begin(9600);

What is mean of this line of code?

Serial.begin(9600) doesn't actually print anything.

If you want to print "Hello world!" to the serial monitor then you have to use this line of code. Rather it initializes the serial connection at 9600 bits per second.

It is used for kind of handshaking means both sides of the serial connection (i.e. the Arduino and your computer) need to be set to use the same speed serial connection in order to get any sort of intelligible data. If there's a mismatch between what the two systems think the speed is then the data will be garbled.

Why here, we always write 9600?

And 9600 bits per second is the default for the Arduino, and is perfectly adequate for the majority of users, but you could change it to other speeds: Serial.begin(57600) would set the Ardunio to transmit at 57600 bits per second. You'd need to set whatever software you're using on your computer (like the Ardunio IDE's serial monitor) to the same speed in order to see the data being sent.

And can we write manually number means instead of 9600 let's say 10000? No, we can't write. There is a specific baud rate available: 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, or 115200.

1
Serial.begin(9600);

This line starts Serial communication with a baud rate of 9600. Serial communication is used to transmit data between your application and external systems (including your PC, other Arduinos, sensors, and other ICs).

Most of the time this is included to allow the application to output information via the Serial Monitor when connected to you PC.

Documentation for this is here: https://www.arduino.cc/en/reference/serial

From the documentation: "For communicating with the computer, use one of these rates: 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, or 115200." - source

1
  • 2
    It's worth noting that on boards with a "direct" USB connection (such as the Leonardo, Micro, Teensy, Lenny, Fubarino, etc) the baud rate is actually meaningless. – Majenko Mar 22 '17 at 10:08

Not the answer you're looking for? Browse other questions tagged or ask your own question.