Serial Communication with Arduino
This article contains everything you need to know to implement serial communication on your next arduino project. Just as usual, I have included example sketches (code) and wiring diagram.
In this lesson I will go into opening and closing serial communications, setting up your baud rate, and sending and receiving basic texts and numbers
Serial communication is used to communicate with electronic devices in this case, an arduino uno. Serial communication can be used for getting valuable data from the arduino such as sensor data or it can be used to send commands to the arduino. It also helps debug faster since you have more data.
This is very self explanatory since all we have to do is to plug in the arduino to the computer with the 2.0 cable.
In this piece of code, I have begun the serial communication with begin() function and passed in the desired baud rate as my parameter. Then, it checks for incoming data with available() function, if incoming data available then, I used the readString() to read the complete string instead of I character that you get with the read() function. Later on, it checks if the incoming data said quit and if it did then It stops the serial communication and if it didn't then it prints the incoming data using the println() function which prints on a new line instead of on the same line which you can achieve using the print() function instead of println().
NOTE: Configure the serial monitor with no line ending. This way it can detect the quit message properly.