hi welcome to an Arduino step-by-step course by Robojax this is for absolute
beginners
hi this is an introduction to serial monitor so what is the serial monitor serial monitor is a
tool or a pop-up window embedded in ide integrated development environment the program for Arduino
this is a serial monitor it's used for debugging to find out the problem with a certain
section of your code it is used to print information from the code for example you're
reading some data or a value or something you want to make sure that data exists
or does not exist or it is equivalent to some value you print it and read it and also it can
read the user input from the serial monitor here at the top the user can input the information
and it's used to read the serial port information of Arduino or from a pc so it can read data from
the serial ports for example from usb or other means of serial you can read the data using serial
monitor let's start with the actual code when you click on file new you will get this screen this
is totally blank screen and it does not have any code running when you can open serial monitor in
three ways the first way let's start by clicking on tools and serial monitor as soon as I clicked
as you can see there is a warning it says board at com13 is not available and also the
same information is here it means my Arduino is not connected so the first condition is that if
you want to make the communication possible you have to select a certain port and then
connect it this 13 that you see here is the last used port when I was using prior to this lesson
when I was using Arduino I have used port 13 and Arduino has remembered that and it goes to
that port and you can check the port by clicking at the tool port as you can see it has only com3
country is used within my computer in windows for other purposes so that cannot be used for
this application that I’m running now you run this nothing will happen now I’m connecting my Arduino
and let's click on tools and port now you can see we have one more port
and that is the Arduino board that I have
so now let's open it click on tool serial monitor so this is one way to open the serial monitor this
doesn't do at the moment anything let me close it and open it in a second way the second way
would be a shortcut ctrl shift m now if I on my computer if I press ctrl shift and m it opens
and the third way would be to click on this icon this is a serial monitor icon you click and opens
so perhaps if you're using mouse this will be your best option if you're a person of keyboard
control shift m is the monitor or serial monitor to initialize the serial monitor inside the setup
at this portion as you can see here we have one function here it's called setup and we
have another one it's called loop the function is identified by this opening and closing parentheses
and this is opening and closing portion of the function all the content that is inside the setup
or within these two curly parentheses so we will have inside the setup we have to type serial
dot begin and opening and closing and in here we type the speed of communication board per second
here I’m typing 9600 and this board must match the serial monitor value open the serial monitor
side by side on windows click on this bar hold it and go to the left of the screen and it goes
occupies half of the screen and now click on this the serial monitor opens wherever it was the last
location now I’m holding again from the top bar go to the right and it shows you where it goes
now the spring has been splatted if you want to adjust it if you grab from the middle both of
these will be adjusted to the left or right I think this this is enough for me on this side
after setting the baud rate in here when you open your serial monitor the serial monitor
at this point the right lower corner you will be able to set the baud rate that matches this
if you set it in a different value you will not be able to see the text which I’m going to show
you next and here let's print this text if you want to print something on the screen you type
serial dot print and serial is a class name and then dot this is a method or function
part of this class print is part of this class
and whatever you want to type you will type it inside the opening and closing parentheses here
and because I’m typing a text for the text you must put double quotation at the beginning and end
once you type it you will not see it here until you upload it to the Arduino board Arduino board
is now connected and I’m uploading it when I click this the code is now uploaded to Arduino
once that is completed it will be printed here and see on serial monitor
and here if I change the baud rate to the right lower corner 19200
you will see the same text is displayed like this it's not readable if I select a different battery
38 400 you will see different characters depending on the baud rate the data that comes will be
treated differently see when I upload the code the serial monitor is greyed out it's disabled
once the code runs you will see that Robojax and then welcome they are shown in one line
the reason for that is when you type print it will print this and another print will come
immediately after that so you have multiple ways to fix it one way would be to just put space here
you can delete this space and add the space before the welcome world
and there is also a third way we will be when we print this we can say print the text and
also print a new line for us which means go to the new line and this is happening like ln and we type
ln to do that ln that is newline and is on this side but that refers to new line
you see the Robojax have been printed and new line have been inserted and then will come
appears in the other line the same way if you want something after will come to appear in
another line add here new line if I add ln here you will not see any difference because
this ln creates a new line after the will come the whatever comes after this will be affected
and as you can see this ln that is in the welcome line is affecting this line
and this doesn't have anything and doesn't matter if I put here ln it will affect
the upcoming new text after this line there are other ways also to add the new line and here as
you can see to Arduino class having printed a name appears at the end there is another way to break
this in a new line you can just add here backslash in this backslash is a key on the keyboard
and here is a backslash location on the keyboard and the us English the location is here in your
region it might be somewhere else either was pressing shift or without shift somewhere this
is escape character and it is used extensively in programming and here it tells the program that
do not print this in this is something special so this is telling that the character that is
coming next is a special character and this backslash n means new line it means create
a new line if I upload this even though there is no ln if I upload this after this the word class
you will immediately see a new line so this name will go down
as you can see after the class name went down to the next line and you can do backslash in
anywhere in the text and break those text for example if I want name to be here and
telephone should be low and address should be lower I can do the same thing backslash in
backslash in
bring the code now once the code is uploaded you will see that
after the class we have a new line and n and each will appear in a new line
and this time I’ve changed it I’ve put here backslash t backslash t
this t means tab the address after this I put last name and here I put backslash n that backslash n
after the address creates a new line and then last name is printed after that this backslash t means
tab like in any word processing program like Microsoft word or google sheet if you press the
tab on the keyboard it creates a certain space so that's one tab space and then we have another tab
so this is for tabular data sometimes you want to display some information in a column you can use
backslash t so pay attention to this backslash t in front of p nothing happened because p is
not a special character with backslash so this backslash was not able to escape p and execute
whatever p was doing because p was not in the left to do anything now backslash is also not printed
and here if I want to print backslash I have to put another backslash in front of it
so this is escaping and it says ignore the job of this and it is now printing one of them this is
how you can print a backslash and if you want to print two backslashes you have to put four
this is how it prints also two backslashes now let's see how we can read user's input
and here this is the code that accepts the user input and here is an example that we read user
data the serial monitor is here and the code for the explanation for simplex and
here simple explanation would be that we check if serial. Available
this checks if the data is entered by the user because it doesn't print you can see anything here
if it is available and it is greater than zero then we print this so we use cellular plant ln
as before inside this we just put serial dot read so we type this inside this practice if I put some
space you will see it properly so this was opening and this is a closing we just put here serial.read
and this is serial.print so serial.read it gets the data that we enter here or the information
so this grabs it we can do something with it but in this case we just put this
inside this print so it can print this for us
for example if I type a 97 if I type b pay attention here and see 99 and if I print 0
48 1 2 49 50. then why it doesn't print a or b and c the reason for that is this is not
the a or b value this is ascii value for that because valuing each numbers each
characters we have associated number related to it which is called ascii
or ask ascii stands for American standard code for information interchange ASCII and it has a table
defined by an organization in the us and these are the values for different characters
these are printable values and as you can see here for space we have 32 explain
explanation mark these are all characters that are in the us keyboard us English keyboard and as you
can see here when I typed a it printed 97 for b 98 for c 99 these are the value decimal value
and also here when I typed 0 it typed 48 printed 48 for me and for 1 49 and for 250
because these are ascii characters that is being printed so pay attention that serial monitor
prince ascii character if you just print it directly
here I’ve changed the code I’ve just added this in front of the serial read this is called
casting casting mean changing a type of data into other data type and inside
open and closing practice we just type car c-h-a-r or sometimes people read it as char
and this is converting this from the decimal value or a number into a character now if I type
a it will be a b c all these readable characters that we have on the keyboard and will be printed
and here are some of the built-in examples of serial monitor if you
click on file examples and then go to number four communications let's first print this ascii table
this is a program that prints ascii table and let me upload it
this program prints all the values of American English keyboard from exclamation mark it goes
from 33 decimal and as you can see the number is increasing and it goes to 126.
beside this we have hexadecimal value and octal
and binary values which I am going to explain in the upcoming lecture
let's open another example if you click on file examples communication serial event
let's upload it in this example you have to enable from the lower right corner the new line
once you enable it when you enter the value
it collects it and prints it for example you can enter two three or more digits and it will
be printed this new line this new line will send also a new line character with your entered value
this new line will send also a new line character with your entered value
if I print 1000 you see they are all printed together
if this code is not arranged this way you will see that if I type seven nine eight it will be printed
in separate values if you remember from the first example that I gave for the reading if you print
eight this just prints ascii character but let's print hy as you can see as prince2 line the
reason for that is that it reads each character separately y is 121 as you can see if I type
t y together and press enter at prince 116 and 121 but in this example it will be printed all
together if I print t y it will be printed as t y without making the character it prints
actual value if I type h7 it will be l7 this was introduction to serial monitor it can do much more
than what I’ve explained and as the course progresses within the topics I’ll explain more
feature of this thank you for watching please make sure to subscribe by clicking on the subscribe
button in here thank you thank you for watching tutorial from Robojax if you learned something
and found this useful please thumb up as this will help my video in the search algorithm of YouTube
if you have comment or question please post it at the comment section below
I try to answer and reply and don't forget subscribe to get updates on my upcoming videos you