What is Serial.begin(9600)?

Are you wondering what Serial.begin(9600) does?

You’ve probably seen it in most of the Arduino programs you’ve looked at – but what’s it there for?! Do you even need to use Serial.begin()?

What if you change the number 9600? I mean, what’s 9600 even mean?!

In this lesson you will learn exactly what Serial.begin does, when you NEED to use it, and what the heck the 9600 means.

What does Serial.begin(9600) do?

Let’s get straight to this…

Serial.begin() establishes serial communication between your Arduino board and another device. The most common use of serial communication you will establish is between your Arduino and your computer via a USB cable – or should I say a Universal Serial Bus cable.

When you have established serial communication between two devices, it allows the two devices to communicate using a serial protocol.

So let’s answer a couple practical questions…

Programming Electronics Academy members, check out the Arduino Course for Absolute Beginners to practice using the Serial Library in your code.

Not a member yet?  Sign up here.

When do I need to use Serial.begin()?

The most common reason to use serial.begin() is when you want to output some information from your Arduino to your computer screen.

That is, you want to print some text out.

The function used to display text on your computer screen from your Arduino board is the serial.print() function.

void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.print("Look Ma, I’m in the phone book!");
}

The text that gets printed out shows up on the Serial Monitor window – which can be opened from the menu bar under Tools > Serial Monitor. Or with the shortcut key CTRL + SHIFT + M (on PC) or Command + Shift + M (MacOs).

There are other times you’ll use serial.begin(), for example, maybe you have an application running on your computer that will be expecting data from your Arduino over a serial port. In these cases, you’ll also need Serial.begin().

Where does Serial.begin() go in the Arduino sketch?

99% of the time, you’ll be putting the Serial.begin() function inside of the setup() function. As you may know, setup() only runs once, and since you’ll only need to establish the Serial Communication one time – it makes sense to have it there.

Programming Electronics Academy members, check out the Arduino Course for Absolute Beginners to jump start your Arduino programming skills.

Not a member yet?  Sign up here.

What’s with the number 9600?

That number is called the baud rate. Probably the most important practical thing you need to know, is that for serial communication to work the baud rate in Serial.begin() and the baud rate set on the receiving device need to match.

If you are using the Arduino IDE Serial Monitor window to read the information from your Arduino, then you can use the baud rate drop down to set the baud rate.

Remember! If these two values don’t match – then anything you try to send over serial will not work right.

It’s like, as a kid, did you and a friend ever come up with a long distance communication protocol?

Like, 2 hoots meant, “Is anyone at the fort?”, and the appropriate response was two hoots back?

But if you both didn’t agree on that protocol beforehand, and your friend was cawing, instead of hooting, then you were like, what is he trying to say? Same thing with the baud rate – remember these have to match!

So let’s do a review here:

  • Serial.begin() is used to establish serial communication
  • Serial communication is one way to allow to devices to talk to each other
  • Most often, you’ll need to use Serial.begin() when you want to print something to your computer screen from your Arduino. This would also require the Serial.print() function.

Well hey, I hope you found this helpful! If you’re curious about other features of the serial communication, make sure to check our membership program! This is just the tip of the iceberg!

Have a great one!

AppLab Bricks open in background with actual brick

Arduino AppLab Bricks → Marketing Garbage or New Powerful Interface?

Arduino Ventuno single board computer - top side

New Ventuno Q Dual Brain Single Board Computer

AppLab Pip Install

How to Add Python Packages in Arduino AppLab (No pip install needed)

Arduino Power Section Schematic

Kit-on-a-Shield Schematic Review

Just how random is the ESP32 random number generator?

Just how random is the ESP32 random number generator?

7 Comments

  1. chikhaoui on June 23, 2021 at 4:11 pm

    thank you. it’s helpfull

  2. Mugenzi on July 27, 2021 at 9:39 pm

    Well explained

  3. Dominic UDOUSORO on August 13, 2022 at 1:20 pm

    Best explanation for a beginner

  4. Maani on January 26, 2024 at 1:54 pm

    thnku

Leave a Comment