# 氣體感測器Gas Sensor(MQ7)模組

## 氣體感測器Gas Sensor(MQ7)模組

**專案說明**

使用「Raspberry Pi Pico W」連接「氣體模組(MQ7)」, 讀取氣體模組(MQ7)的數值變化。此**氣體模組(MQ7)**&#x5305;含於「洞洞五教學材料包」內。

**感測器調整說明**

精密電阻旋鈕可以調整氣體濃度測量範圍，如下圖所示。

![](https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LaZQFBYOS3O0ksiEmR1%2Fuploads%2FCeXMP7LbiOl5egKNEGrU%2F0.png?alt=media)

### **氣體模組(MQ7)電路圖**

* Raspberry Pi Pico W
* Raspberry Pi Pico W 擴充板
* 氣體模組(MQ7)

**氣體模組(MQ7)**&#x662F;**類比訊號**輸入， 可以接「A0\~ A2」的Raspberry Pi Pico擴充板訊號端上。 本範例連接到「A0」

![](https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LaZQFBYOS3O0ksiEmR1%2Fuploads%2Fx2geAicRaPh02RXO36Dh%2F1.png?alt=media)

### **BlocklyDuino 程式 (GAS)**

偵測氣體的濃度變化，若**氣體濃度大於500，則顯示「危險!」；反之顯示「安全!」**。

![](https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LaZQFBYOS3O0ksiEmR1%2Fuploads%2FAeQcg49SVg02edPQ2F6X%2F2.png?alt=media)

### **Arduino 程式(GAS.ino)如下**

```
void setup()
{
Serial.begin(9600);
}
void loop()
{
int GAS = analogRead(A0);
if (GAS > 500) {
Serial.println("危險!");
} else {
Serial.println("安全!");
}
Serial.println((String("數值 :")+String(GAS)));
delay(100);
}
```

### **程式執行結果:**

偵測氣體的濃度變化，若**氣體濃度大於500，則顯示「危險!」；反之顯示「安全!」**。

以下是**安全範例**

| <img src="https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LaZQFBYOS3O0ksiEmR1%2Fuploads%2FLcDMWPYQSqh729VYLQxc%2F3.png?alt=media" alt="" data-size="original"> | <img src="https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LaZQFBYOS3O0ksiEmR1%2Fuploads%2FEjywJzLA748EQSbEkB5b%2F4.png?alt=media" alt="一張含有 文字, 螢幕擷取畫面, 陳列, 軟體 的圖片

自動產生的描述" data-size="original"> |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |

以下**危險範例**

| <img src="https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LaZQFBYOS3O0ksiEmR1%2Fuploads%2FPYDb3tfuFL7CkAC4nB1L%2F5.png?alt=media" alt="" data-size="original"> | <img src="https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LaZQFBYOS3O0ksiEmR1%2Fuploads%2FJbOYJfI6kWORnGVuyMlX%2F6.png?alt=media" alt="" data-size="original"> |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
