How to Get a String or Number into the Arduino from the Serial Port

Arduino boards such as the Arduino Uno have a serial port that is linked to the USB port on the board. When data is sent out of the serial port in an Arduino sketch using a function such as Serial.print(), then the data goes out of the Atmel AVR microcontrollers (which is the main Arduino microcontroller) serial port to the small Atmel microcontroller on the board that handles the USB communications. This small microcontroller then sends the serial data out of the USB port.

The data that is sent out of the Arduino USB port can be displayed in the Serial Monitor window of the Arduino IDE as shown in the image below.

Opening the Arduino Serial Monitor window.

Opening the Arduino Serial Monitor window.

Data can also be sent from the Arduino IDE Serial Monitor window into the Arduino. Part 19 of the Arduino programming course shows how to send a character, string and number from the Arduino Serial Monitor window to the Arduino board.

A single character is easy enough to receive and process in an Arduino sketch. A string requires a bit more work because it must be assembled from the characters received via the serial port. A number is captured as a string and then must be converted from a series of characters into an actual number.

Go to the tutorial (part 19 of the Arduino programming course) to learn how to handle Arduino serial input →