-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmq9_tester.ino
61 lines (49 loc) · 1.47 KB
/
mq9_tester.ino
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
61
void setup() {
Serial.begin(9600);
}
void loop() {
float sensor_volt;
float RS_air; // Get the value of RS via in a clear air
float R0; // Get the value of R0 via in LPG
float sensorValue;
/*--- Get a average data by testing 100 times ---*/
for (int x = 0 ; x < 100 ; x++)
{
sensorValue = sensorValue + analogRead(A0);
}
sensorValue = sensorValue / 100.0;
/*-----------------------------------------------*/
sensor_volt = sensorValue / 1024 * 5.0;
RS_air = (5.0 - sensor_volt) / sensor_volt; // omit *RL
R0 = RS_air / 9.9; // The ratio of RS/R0 is 9.9 in LPG gas
Serial.print("sensor_volt = ");
Serial.print(sensor_volt);
Serial.println("V");
Serial.print("R0 = ");
Serial.println(R0);
delay(1000);
} void setup() {
Serial.begin(9600);
}
void loop() {
float sensor_volt;
float RS_air; // Get the value of RS via in a clear air
float R0; // Get the value of R0 via in LPG
float sensorValue;
/*--- Get a average data by testing 100 times ---*/
for (int x = 0 ; x < 100 ; x++)
{
sensorValue = sensorValue + analogRead(A0);
}
sensorValue = sensorValue / 100.0;
/*-----------------------------------------------*/
sensor_volt = sensorValue / 1024 * 5.0;
RS_air = (5.0 - sensor_volt) / sensor_volt; // omit *RL
R0 = RS_air / 9.9; // The ratio of RS/R0 is 9.9 in LPG gas
Serial.print("sensor_volt = ");
Serial.print(sensor_volt);
Serial.println("V");
Serial.print("R0 = ");
Serial.println(R0);
delay(1000);
}