一、元件介紹
感測:甲烷,丁烷,液化石油氣(LPG),煙
Arduino UNO | MQ-2 元件 |
A0 | A0 |
不接 | D0 |
GND | GND |
5V | VCC |
二、接線範例
三、程式範例
Arduino程式庫下載:https://github.com/labay11/MQ-2-sensor-library
本地下載:MQ-2程式庫
程式庫安裝後,有範例程式可以使用
#include <MQ2.h> //change this with the pin that you use int pin = A0; int lpg, co, smoke; MQ2 mq2(pin); void setup(){ Serial.begin(9600); mq2.begin(); } void loop(){ /*read the values from the sensor, it returns *an array which contains 3 values. * 1 = LPG in ppm * 2 = CO in ppm * 3 = SMOKE in ppm */ float* values= mq2.read(true); //set it false if you don't want to print the values in the Serial //lpg = values[0]; lpg = mq2.readLPG(); //co = values[1]; co = mq2.readCO(); //smoke = values[2]; smoke = mq2.readSmoke(); delay(1000); }