MQ-9를 이용해 LPG, CH4(메테인), CO(일산화탄소)를 측정하는 예제
send me email if you have any questions.
MQ-9
이 모듈은 10~1000ppm의 CO-gas, 100~10000ppm의 가연성 가스(메탄,LPG 등)를 측정한다.
연결도
아두이노 | MQ-9 | |
5V | VCC | |
GND | GND | |
A0 | A0 |
라이브러리 설치
아두이노 -> 스케치 -> 라이브러리 포함하기 -> 라이브러리 관리…
mq9를 검색하여 MQUnifiedsensor 설치
예제소스(라이브러리에서 지원)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <MQUnifiedsensor.h>
#define Board ("Arduino UNO")
#define Pin (A0) //Analog input 4 of your arduino
#define Type ("MQ-9") //MQ9
#define Voltage_Resolution (5)
#define ADC_Bit_Resolution (10) // For arduino UNO/MEGA/NANO
#define RatioMQ9CleanAir (9.6) //RS / R0 = 60 ppm
MQUnifiedsensor MQ9(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin, Type);
void setup() {
// 가스 센서 시작
Serial.begin(9600); //Init serial port
// PPM 농도 및 상수 값을 계산하도록 산술 모형 설정
MQ9.setRegressionMethod(1); //_PPM = a*ratio^b
MQ9.init();
Serial.print("Calibrating please wait.");
float calcR0 = 0;
for(int i = 1; i<=10; i ++)
{
MQ9.update(); // Update data, the arduino will be read the voltage on the analog pin
calcR0 += MQ9.calibrate(RatioMQ9CleanAir);
Serial.print(".");
}
MQ9.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue founded, R0 is infite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Conection issue founded, R0 is zero (Analog pin with short circuit to ground) please check your wiring and supply"); while(1);}
Serial.println("** Lectures from MQ-9 ****");
Serial.println("| LPG | CH4 | CO |");
}
void loop() {
MQ9.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ9.setA(1000.5); MQ9.setB(-2.186); // Configurate the ecuation values to get LPG concentration
float LPG = MQ9.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
MQ9.setA(4269.6); MQ9.setB(-2.648); // Configurate the ecuation values to get LPG concentration
float CH4 = MQ9.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
MQ9.setA(599.65); MQ9.setB(-2.244); // Configurate the ecuation values to get LPG concentration
float CO = MQ9.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
Serial.print("| "); Serial.print(LPG);
Serial.print(" | "); Serial.print(CH4);
Serial.print(" | "); Serial.print(CO);
Serial.println(" |");
delay(1000); //Sampling frequency
}
측정 결과
측정 시작 후 라이터로 가스를 흘려보내다가 말았을때의 결과이다.
PREVIOUSArduino MLX90614 온도센서
NEXTLinux Vim editor