Serial.available()
Description
Get the number of bytes (characters) available for reading from the serial port. This is data that's already arrived and stored in the serial receive buffer (which holds 64 bytes).
Serial.available() inherits from the Stream utility class.
Syntax
Serial.available()
Parameter Values
- Serial: serial port object. See the list of available serial ports for each board on the Serial main page.
Return Values
- The number of bytes available to read.
Example Code
Example Code 1
The following code returns a character received through the serial port.
- Type "HELLO" on Serial Monitor and click Send button:
- The result on Serial Monitor:
Example Code 2
Arduino Mega example:
This code sends data received in one serial port of the Arduino Mega to another. This can be used, for example, to connect a serial device to the computer through the Arduino board.
※ NOTES AND WARNINGS:
Serial functions are not only used for the communication between an Arduino board and Serial Monitor of Arduino IDE but also used for the communication between:
- An Arduino board and other Arduino board
- An Arduino board and other sensors/devices
- An Arduino board and computer (any Serial software on computer)* An Arduino board and other Arduino board
- An Arduino board and other sensors/devices
- An Arduino board and computer (any Serial software on computer)
See Also
- Language : Arduino - Serial
- Language : Serial.availableForWrite()
- Language : Serial.begin()
- Language : Serial.end()
- Language : Serial.find()
- Language : Serial.findUntil()
- Language : Serial.flush()
- Language : Serial.getTimeout()
- Language : if(Serial)
- Language : Serial.parseFloat()
- Language : Serial.parseInt()
- Language : Serial.peek()
- Language : Serial.print()
- Language : Serial.println()
- Language : Serial.read()
- Language : Serial.readBytes()
- Language : Serial.readBytesUntil()
- Language : Serial.readString()
- Language : Serial.readStringUntil()
- Language : serialEvent()
- Language : Serial.setTimeout()
- Language : Serial.write()
※ ARDUINO BUY RECOMMENDATION
Arduino UNO R3 | |
Arduino Starter Kit |
Additionally, some links direct to products from our own brand, DIYables.