What is Serial.begin(9600)?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
- [Instructor] Are you wondering what serial begin with that 9,600 in the parentheses does? You've probably seen it in almost all 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 9,600? I mean what's 9,600 even mean? In this lesson, you will learn exactly what serial begin does, when you need to use it and what the heck the 9,600 means. Stay tuned. (upbeat music) Subscribe to our YouTube channel to get more videos like this. So what does serial begin 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 that you will establish is between your Arduino in your computer via a USB cable, or should I say 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. When do you actually need to use serial begin? So 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 if you want to like print some text out. The function that's used to display text on your computer screen from your Arduino board is the serial print function. The text that gets printed out shows up on the serial monitor window, which you can open up in the Arduino IDE menu bar under tools, serial monitor or with the shortcut key control shift M on PC or command shift MAC OS. Now there's other times you'll use serial begin. For example, you may 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. So where does serial begin go in an Arduino sketch? 99% of the time, you'll be putting the serial begin function inside the setup function inside your Arduino sketch. So as you may know, the setup function only runs once and you only need to establish serial communication one time and it will last the length of your sketch which is why it makes sense to put the function inside of setup. So what's with the number 9,600? That number is called the baud rate. And it's basically the rate at which your two devices will be communicating over serial. Probably the most 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're using the Arduino IDE serial monitor window to read 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 two hoots? Woo, woo. Is anyone at the Fort? And the appropriate response back was like two hoots. But if you both didn't agree on that protocol beforehand and your friend's like call, call, instead of hooting then you're like, "What's he trying to say? Don't he like my shoes or something like that?" It's the same thing with the baud rate. Remember, these have to match. All right. So let's do a review. Serial begin is used to establish serial communication. Serial communication is one way to allow devices to talk to each other. Most often, you'll be using serial begin when you want to print something out to your computer screen from your Arduino. This would also require the serial print function. The serial begin function generally goes inside a void setup. Well, hey, I hope you found this really helpful. Make sure to check out Programming Electronics Academy for tons of other information about serial communication. This is just the tip of the iceberg. Have a great one. Bye. (upbeat music)
Info
Channel: Programming Electronics Academy
Views: 6,088
Rating: 4.9133573 out of 5
Keywords: Arduino, Arduino(Brand), Arduino Tutorial, Arduino Lesson, Open Source Hardware Group, Learning Arduino, Microcontrollers, Electronics, Arduino IDE, Arduino Sketch, Computer programming, C++, Programming Electronics Academy
Id: 8GX5brSZ_1E
Channel Id: undefined
Length: 4min 24sec (264 seconds)
Published: Sat Apr 17 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.