# 繼電器

Grove Relay 模組為常開型繼電器，透過它可用低電壓 (3.3V \~ 5V) 進行高電壓的開關控制 (最高電壓支援至交流電 250V 或直流電 30V；最大電流為 5A)。且模組上配有 LED 燈，亮起時表示線路端點為連通狀態。欲取得更多關於此元件的資訊，請參考[官方 WiKi](http://wiki.seeed.cc/Grove-Relay/) 連結。接下來將示範利用繼電器開關 LED 的例子：

### 元件配置 <a href="#relay-yuan-jian-pei-zhi" id="relay-yuan-jian-pei-zhi"></a>

依照下圖連接各元件以進行後續範例：

![](/files/HngiyOKAjQ4U1zvVIxBD)

### 執行程式 <a href="#relay-zhi-hang-cheng-shi" id="relay-zhi-hang-cheng-shi"></a>

1. 在 Arduino IDE 中貼上下列程式碼：

   ```
   int val = 0; 
   int controlPin = 10; 
   int buttonPin = 6; 
    
   void pin_change(void) 
   { 
     val = !val; 
   } 
    
   void setup() { 
     Serial.begin(9600); 
     pinMode(controlPin, OUTPUT); 
     attachInterrupt(buttonPin, pin_change, RISING); 
   } 
    
   void loop() { 
     if (val) 
     { 
         digitalWrite(controlPin, HIGH); 
         Serial.println("High"); 
     } 
     else 
     { 
         digitalWrite(controlPin, LOW); 
         Serial.println("Low"); 
     } 
    
     delay(500); 
   }
   ```
2. 點選工具列上的 **Upload** 按鈕編譯並上傳程式至開發板。
3. 上傳完成後，即可藉由按壓 **USR** 按鈕控制繼電器的開關、進而影響 LED 的開關。

### 實際應用 <a href="#relay-shi-ji-ying-yong" id="relay-shi-ji-ying-yong"></a>

一般常見的繼電器應用為控制家用電器的開關 (交流電)，線路連接範例如下：

![](/files/Ee0JMKkcrnQz46e5shZo)

藉由將供電線 (或插座) 中的火線經由繼電器接出，開發者就可透過程式控制的方式操作該電源線的開關。


---

# 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/linkit-7697/linkit-7697-arduinoide/zhou-bian-yuan-jian-lian-jie-jiao-xue/ji-dian-qi.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.
