Class for MQxx sensors incluiding MQ2, MQ3,MQ4,MQ5,MQ6,MQ7,MQ8,MQ135
In principle, MQ-Series Sensors have internal sensor resistor Rs and an external load resistor RL forms a voltage divider. The sensor resistor varies depending on the type of gas it measures, and its density is measured in PPM. The data sheet measures PPM vs the ration or sensor resistance (Rs) over Zero resistance (R0).
Zero resistance (R0) calculated from the formula R0= Rs (in clear air) / Constant from data sheet
The relation between (Rs/R0) and PPM is exponential as shown in below MQ-135 data sheet chart hence the formula to calculate the PPM should be in the form of
Log10(PPM) = A + B * Log10(Rs/R0)
or
PPM = 10 ^ (A + B * Log10(Rs/R0))
Where A and B are constant depending on the sensor and gas type, accordingly, we should reference the charts for each sensor to extract the value of A and B from it.
To calculate Rs from normal voltage divider between two resistances.
Current in Sensor (V/R)S = Current output to ground (V/R)L
so
Vs / Rs = VL / RL
(Knowing that Rl = 1K ohm for all the sensors, Vl= Vout from the sensor reading so)
Rs = Vs * RL / Vout = Vs / Vout
Vs = Voltage over sensor = Vcc - Vout
In Arduino PWN pins read the voltage to 10 register bits means when the input voltage = max voltage (Vcc) then the reading will be 1023.
So for any reading to get the corresponding voltage, we should calculate it with the following formulation.
Vout = Vcc * Reading / 1023
and
Rs = Vs / Vout = (Vcc - Vout) / Vout
MQ-4 Datasheet
Calculation of the logscale
PPM = 10 ^ ( A + B * Log10( Rs/R0 ) )
According to Point1 (Log10(PPM)1,Log10(Rs/R0)1), Point2(Log10(PPM)2,Log10(Rs/R0)2)
Where:
B = (Log10(PPM)1 - Log10(PPM)2) / (Log10(Rs/R0)1 - Log10(Rs/R0)2)
A = Log(PPM)1 – B * Log10(Rs/R0)1
A and B is constants calculated depend on gas type according to above chart, hence the calculated constant show below:
|
|
PPM |
Rs/Ro |
LOG(PPM) |
LOG(Rs/Ro) |
A |
B |
|
LPG |
110 |
2.56 |
2.0414 |
0.4082 |
3.5410
|
-3.6735
|
|
10000 |
0.75 |
4.0000 |
(0.1249) |
|||
|
CH4 |
110 |
1.71 |
2.0414 |
0.2330 |
2.8026
|
-3.2669
|
|
10000 |
0.43 |
4.0000 |
(0.3665) |
|||
|
H2 |
110 |
3.77 |
2.0414 |
0.5763 |
5.6925
|
-6.3351
|
|
10000 |
1.85 |
4.0000 |
0.2672 |
|||
|
CO |
110 |
4.37 |
2.0414 |
0.6405 |
14.7252
|
-19.8035
|
|
10000 |
3.48 |
4.0000 |
0.5416 |
|||
|
Alcohol |
110 |
4 |
2.0414 |
0.6021 |
12.0550
|
-16.6322
|
|
10000 |
3.05 |
4.0000 |
0.4843 |
|||
|
Smoke |
110 |
3.77 |
2.0414 |
0.5763 |
7.7442 |
-9.8948 |
|
10000 |
2.39 |
4.0000 |
0.3784 |
Rs/R0 in clear air = 4.434
Accordingly, R0 = Calibrated Rs (initial value) / 4.434