# \[아두이노] 초음파 센서 코드

### 코드

```
@아두이노 초음파 트리거{Trig 핀 번호} 에코{Echo 핀 번호} 읽어오기
```

***

### 설명

<mark style="color:purple;">`초음파 읽어오기`</mark>는 아두이노와 연결된 초음파 센서와의 거리 데이터를 읽어오는 코드예요.

***

### 주의사항

* Trig는 디지털 출력으로, Echo는 입력으로 핀 모드 설정을 먼저 해야 해요.
* Trig와 Echo 핀은 모두 디지털 핀(2\~13번 핀)에 연결되어야 해요.
* 초음파 센서와의 거리는 cm 단위로 반환하나, 오차가 있을 수 있어요.

***

### 파이썬 대응 코드

아두이노 코드는 파이썬에 대응되는 코드가 없어 제공되지 않아요.

***

### 예시

{% code title="예시 코드" %}

```
@아두이노 9번 핀 디지털 출력 설정
@아두이노 8번 핀 입력 설정
(@아두이노 초음파 트리거(9) 에코(8) 읽어오기) 보여주기
```

{% endcode %}

{% code title="예시 코드의 결과" %}

```
12
```

{% endcode %}

***

### 검색 키워드

초음파 피아노, 거리 측정


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://codebook.horang.it/arduino/030.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
