> For the complete documentation index, see [llms.txt](https://ubtechedu.gitbook.io/chinese/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ubtechedu.gitbook.io/chinese/arduino-language/functions/communication/read.md).

# serial.read()

读取传入的串口的数据

### 返回

| 参数名    | 描述                                |
| ------ | --------------------------------- |
| number | 传入的串口数据的第一个字节（或-1，如果没有可用的数据）- int |

### 例子 <a href="#li-zi" id="li-zi"></a>

```c
int incomingByte = 0;   // 传入的串行数据
 
void setup() {
  Serial.begin(9600);     // 打开串口，设置数据传输速率9600
}
 
void loop() {
 
  // 当你接收数据时发送数据
  if (Serial.available() > 0) {
    // 读取传入的数据:
    incomingByte = Serial.read();
 
    //打印你得到的：
    Serial.print("I received: ");
    Serial.println(incomingByte, DEC);
  }
}
```
