# 舵機

![](https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LaZQFBYOS3O0ksiEmR1%2F-Lx00XGnqAn7JxlS80YM%2F-Lx03HDEYQYVpc6bF_GN%2F01.png?alt=media\&token=142c357a-7586-424b-84a0-188cf182353f)

## 專案說明

使用「科易KEYES Arduino UNO R3 開發板」連接「舵機」, 控制舵機順時針轉和逆時針轉。

此**舵機**包含於「[洞洞兩教學材料包 Education Kit 002](https://www.robotkingdom.com.tw/product/rk-education-kit-002/)」內。

## KEYES Arduino UNO R3電路圖

* [KEYES Arduino UNO R3](https://www.robotkingdom.com.tw/product/keyes-uno-r3/)&#x20;
* 通用型彩色Sensor shield v5.0感測器擴充板
* 舵機

**舵機**是**數位訊號**輸出，脈衝寬度調變(Pulse Width Modulation)訊號輸出， 可以接「D3、D5、D6、D9、D10」的KEYES Arduino UNO R3訊號端上。 本範例連接到「**D3**」

![](https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LaZQFBYOS3O0ksiEmR1%2F-Lx00XGnqAn7JxlS80YM%2F-Lx03cV3AoD9e0e_VQ2n%2F02.png?alt=media\&token=860356d7-d868-4f73-a624-4bcf3ad89056)

## Arduino 程式

由於舵機是函式庫型模組，在Arduino上有內建的函式庫即可使用。

控制舵機順時針轉和逆時針轉。

產生出的 Arduino 程式如下

```c
#include <Servo.h>

Servo myservo;  

int pos = 0;    

void setup() {
  myservo.attach(3); 
}

void loop() {
  for (pos = 0; pos <= 180; pos += 1) { 
    myservo.write(pos);             
    delay(15);                       
  }
  for (pos = 180; pos >= 0; pos -= 1) { 
    myservo.write(pos);              
    delay(15);                      
  }
}

```


---

# 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://cavedu.gitbook.io/cavedu/rk002/module/002_servo_motor.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.
