Take the 2-minute tour ×
Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It's 100% free, no registration required.

I know that this is to print something:

Serial.begin(9600);

But I want to know what it really means?

share|improve this question
1  
The documentation has a good description of it. arduino.cc/en/Serial/begin –  sachleen May 17 at 21:08
add comment

1 Answer 1

up vote 6 down vote accepted

Serial.begin(9600) doesn't actually print anything. For that you'd want to use Serial.print("Hello world!") to print the text "Hello world!" to the serial console. Rather it initializes the serial connection at 9600 bits per second.

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.

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.

share|improve this answer
1  
Baud and BPS are two different things... can't find the link I was looking for now. –  Annonomus Penguin May 17 at 21:34
    
what if I put "Serial.begin(0);" or "Serial.begin(4000);". I mean I want to know what is the difference between the numbers? –  shajib0o May 18 at 18:55
1  
Serial.begin is used to set the speed of communication, in bits per second. One byte is equal to 8 bits, but serial connections send a start and stop bit to identify the start and end to a particular byte to the receiving system. Thus, 10 bits are needed to send one character. Using Serial.begin(0) tells the Arduino that it should communicate with serial at 0 bits per second. As you might expect, this means that the Arduino will never send any data at all. Serial.begin(4000) will cause the Arduino to send data at 4000 bits per second. This is non-standard, but otherwise fine. –  heypete May 19 at 20:19
    
In short: changing the number changes the speed. Making the number smaller (e.g. Serial.begin(300)) has the Arduino send data more slowly. Increasing it, say to 57600 will send data faster. Both the sending system and the receiving system need to agree on what speed to use: your computer's serial program, like the Arduino Serial Monitor window, will let you set the speed at which your computer will receive data but you can only select from the common speeds: 300, 1200, 2400, 4800, 9600, 19200, 38400, 57600 and 11520 bit/sec. You can't enter other speeds, like 4000. 9600 is usually good. –  heypete May 19 at 20:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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