We will see how this works as we look more closely at our code in the next couple of pages. Sometimes you need to use text in your code, to pass along textual information, or to give context to other data. Why do we need strings? Computers normally only work with the value of numbers. Any letters, numbers or other alphanumeric characters (including spaces and punctuation marks) are represented by strings in our code. In order to send words to our serial monitor, we use something called a string.Ī string is a representation of text in a programming language. If we look at the first serial.print line, we see words and quotation marks around them.
Sending words to the serial monitor: Strings Here’s an example of a line of output this code will display in the serial monitor. The serial code in our loop includes the four lines below:Īll four of these lines of code together print the single line in the serial monitor which includes the words “sensor =”, the value of our sensor, a tab, the text “output = “ and the mapped value. Our sketch uses both of these functions in order to format the information on the computer screen. The Serial library has 2 functions for sending information to our computer: Serial.print() and Serial.println(). Now that we understand where to find our serial monitor, we can talk about our use of serial in the loop code. Here’s what the serial monitor window looks like when running this sketch: The Arduino and computer must use the same rate of communication: the value set in Serial.begin() By default, the baud rate of your serial monitor will be set to 9600, which matches the value we set in the serial.begin() function in our setup code, so you shouldn’t have to make any adjustments. As we said before, the baud rate is the rate of communication that the computer and Arduino use to talk to each other. and a drop down menu that controls the rate of communication, or baud rate, between our computer and the Arduino. When we open the serial monitor, we see a window that displays responses from the Arduino. To open the Serial Monitor, click the button at the top of the Arduino IDE. It is helpful for de-bugging and for learning what values a sensor or variable resistor produces. The serial monitor is a feature of the Arduino IDE that shows us information sent from the Arduino.