upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
Public Member Functions
MQ8 Class Reference

API for the DFRobot MQ8 Hydrogen (H2) Gas Sensor. More...

Detailed Description

The MQ8 Gas Sensor module is useful for detecting Hydrogen gas concentrations in the air. It has a detection range of 100-10000 ppm.

For optimum use, it requires calibration after a pre-heat time of at least 24 hours. See the datasheet for details.

mq2-5.jpeg
int main(int argc, char **argv)
{
// Attach gas sensor to Analog A0
upm::MQ8 *sensor = new upm::MQ8(0);
signal(SIGINT, sig_handler);
uint16_t buffer [128];
ctx.averageReading = 0;
ctx.runningAverage = 0;
ctx.averagedOver = 2;
// Infinite loop, ends when script is cancelled
// Repeatedly, take a sample every 2 microseconds;
// find the average of 128 samples; and
// print a running graph of asteriskss as averages
while (shouldRun)
{
int len = sensor->getSampledWindow (2, 128, buffer);
if (len) {
int thresh = sensor->findThreshold (&ctx, 30, buffer, len);
sensor->printGraph(&ctx, 5);
if (thresh) {
// do something ....
}
}
}
cout << "Exiting" << endl;
delete sensor;
return 0;
}

Public Member Functions

 MQ8 (int gasPin)
 
 ~MQ8 ()
 
std::string name ()
 
- Public Member Functions inherited from Gas
 Gas (int gasPin)
 
 ~Gas ()
 
virtual int getSampledWindow (unsigned int freqMS, int numberOfSamples, uint16_t *buffer)
 
virtual int findThreshold (thresholdContext *ctx, unsigned int threshold, uint16_t *buffer, int len)
 
virtual int getSampledData (thresholdContext *ctx)
 
virtual int getSample ()
 
virtual void printGraph (thresholdContext *ctx, uint8_t resolution)
 

Additional Inherited Members

- Protected Attributes inherited from Gas
mraa::Aio m_aio
 

Constructor & Destructor Documentation

MQ8 ( int  gasPin)

MQ8 constructor

Parameters
gasPinAnalog pin where the sensor is connected
~MQ8 ( )

MQ8 destructor

Member Function Documentation

std::string name ( )
inline

Returns the name of the sensor

Inheritance diagram for MQ8:
Inheritance graph
[legend]
Collaboration diagram for MQ8:
Collaboration graph
[legend]

The documentation for this class was generated from the following files: