This is a library for the MQ9 gas sensor module.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MQ9.cpp Source File

MQ9.cpp

00001 #include "MQ9.h"
00002 
00003 MQ9::MQ9 (PinName const &p) : _pin(p)
00004 {
00005     _LPG_ppm = 0.0;
00006     _CO_ppm = 0.0;
00007     _Methane_ppm = 0.0;
00008 }
00009 
00010 int MQ9::read()
00011 {
00012     float sensorDat = _pin.read();
00013     float sensorVolt = sensorDat * 3.3 / 4095;
00014     
00015     _LPG_ppm = 26.572*exp(1.2894*sensorVolt);
00016     _CO_ppm = 10.938*exp(1.7742*sensorVolt);
00017     _Methane_ppm = 3.027*exp(1.0698*sensorVolt);
00018 
00019     return MQ9_STATUS_PASS;
00020 }
00021 
00022 float MQ9::getLPG_ppm()
00023 {
00024     return _LPG_ppm;
00025 }
00026 
00027 float MQ9::getCO_ppm()
00028 {
00029     return _CO_ppm;
00030 }
00031 
00032 float MQ9::getMethane_ppm()
00033 {
00034     return _Methane_ppm;
00035 }