> For the complete documentation index, see [llms.txt](https://cavedu.gitbook.io/cavedu/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cavedu.gitbook.io/cavedu/rk005/module_ui/servo.md).

# SG90伺服馬達模組

## SG90伺服馬達模組

專案說明

使用「Raspberry Pi Pico W」連接「SG90伺服馬達模組」, 控制SG90伺服馬達模組的角度。此 SG90伺服馬達模組包含於「洞洞五教學材料包」內。

### SG90伺服馬達模組電路圖

·        Raspberry Pi Pico W

·        Raspberry Pi Pico W 擴充板

·        SG90伺服馬達模組

| SG90伺服馬達模組是PWM訊號輸入，  可以接「D0 \~ D28」的Raspberry Pi Pico擴充板訊號端上。  本範例連接到「D7」。 |
| -------------------------------------------------------------------------- |

<figure><img src="/files/4fOzQjGD0q0JCrhXz2yc" alt=""><figcaption></figcaption></figure>

### BlocklyDuino 程式 (Servo)

需定義 Raspberry Pi Pico W 控制伺服馬達脈衝寬度的範圍大小約為700\~2500之間，可以控制伺服馬達的角度約0\~180度。

<figure><img src="/files/JIZGH2gMRrEw7aleA5ps" alt=""><figcaption></figcaption></figure>

### &#x20;Arduino 程式(Servo.ino)如下

```
#include <Servo.h>
 
Servo __myservo7;
 
void setup()
{
  __myservo7.attach(7);
  __myservo7.attach(7,700,2500);
}
 
void loop()
{
  __myservo7.write((map(0,0,180,700,2500)));
  delay(1000);
  __myservo7.write((map(90,0,180,700,2500)));
  delay(1000);
  __myservo7.write((map(180,0,180,700,2500)));
  delay(1000);
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://cavedu.gitbook.io/cavedu/rk005/module_ui/servo.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
