# 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="https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LaZQFBYOS3O0ksiEmR1%2Fuploads%2FkwpkImatdlF47LDJYcB3%2Fimage.png?alt=media&#x26;token=0e6c3a14-4767-4fbc-8c39-ca8f30b88990" alt=""><figcaption></figcaption></figure>

### BlocklyDuino 程式 (Servo)

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

<figure><img src="https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LaZQFBYOS3O0ksiEmR1%2Fuploads%2FqiSXg0VV98txJpLZczmR%2Fimage.png?alt=media&#x26;token=60f0a35a-b49b-4ca9-9178-7859fbf741f8" 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: 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/rk005/module_ui/servo.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.
