Ramana R
/
MQ9
This is a library for the MQ9 gas sensor module.
Diff: MQ9.cpp
- Revision:
- 0:7712450a546d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MQ9.cpp Tue May 01 20:26:00 2018 +0000 @@ -0,0 +1,35 @@ +#include "MQ9.h" + +MQ9::MQ9 (PinName const &p) : _pin(p) +{ + _LPG_ppm = 0.0; + _CO_ppm = 0.0; + _Methane_ppm = 0.0; +} + +int MQ9::read() +{ + float sensorDat = _pin.read(); + float sensorVolt = sensorDat * 3.3 / 4095; + + _LPG_ppm = 26.572*exp(1.2894*sensorVolt); + _CO_ppm = 10.938*exp(1.7742*sensorVolt); + _Methane_ppm = 3.027*exp(1.0698*sensorVolt); + + return MQ9_STATUS_PASS; +} + +float MQ9::getLPG_ppm() +{ + return _LPG_ppm; +} + +float MQ9::getCO_ppm() +{ + return _CO_ppm; +} + +float MQ9::getMethane_ppm() +{ + return _Methane_ppm; +} \ No newline at end of file