Table of Contents
Example Description
Discover the fascinating world of Arduino Serial Communication and how it enables data exchange between the Arduino board and the user.
introduction

If you are here willingly, it means you already possess knowledge about programming and project-making. In programming, data from users is often needed, and valuable information needs to be displayed for users. Similarly, when coding for Arduino and creating projects, dealing with useful information is common. This information is referred to as serial data, and the process of sending or receiving data through the Serial monitor in Arduino is known as serial communication.

In this example, we will learn how to read Serial input for Arduino using the communication extension in Pictoblox.

Extension

  1. Go to the extensions section and add the communication extension.
  2. Change the mode from “stage” to “upload.”

Code

  1. Add the “when Arduino starts up” block from the Arduino palette
  2. From the communication palette, enable Serial communication using the “Set Serial() baud rate()” block. Set the baud rate to 9600 from the drop-down menu.
  3. From controls add forever block.
  4. Create a variable of type “string” and name it “input.”
  5. Add the “set input to ()” block from “my variables” into the forever block.
  6. Use the “Read byte as string from serial ()” block to read the collection of data (as a single word or sentence) from the Serial monitor.
  7. Set “input” to the value read from the Serial monitor using the “Read byte as string from serial ()” block.
  8. To display the user input on the screen, use the “write() on serial()” block and input the value of “input” as the output.

Script

Output

in the serial terminal, change the baud rate to 9600. enter the input in the place marked yellow. to fed this input hit the button marked in blue.

 

here you will notice that there are a lot of empty lines (space marked in red ) between the outputs you are entering. in the next example we will learn how to avoid such a problem.