Last active
May 18, 2018 05:56
模組介紹 : faya瓦斯感應模組
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 2018/5/18 | |
// Faya-Nugget 範例程式 (GasSensor_1.ino) | |
// 單元: 模組介紹-faya瓦斯感應模組 | |
// 網址: https://fayalab.blogspot.com/2018/05/GasSensor.html | |
// 目標 (1) 當偵測到瓦斯時,蜂鳴器發出告警聲 | |
// 接線: Arduino ==> faya模組 | |
// A0 ==> Vout (瓦斯感應器) | |
// D13 ==> BZ (蜂鳴器模組) | |
int buzzerPin = 13; // 定義蜂鳴器腳位 | |
int gasValue = 0; // 瓦斯變數 | |
void setup() | |
{ | |
Serial.begin(9600); // 初始化串列傳輸,鮑率為9600bps。 | |
pinMode(buzzerPin, OUTPUT); | |
} | |
void loop() | |
{ | |
gasValue = analogRead(A0); | |
Serial.print("sensorValue = "); | |
Serial.println(gasValue); | |
delay(200); | |
if(gasValue>=800) //當偵測值超過800時 | |
{ | |
tone(buzzerPin,850,200); //蜂鳴器發出850Hz的響頻 | |
delay(120); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment