upm  1.3.0
Sensor/Actuator repository for libmraa (v1.7.0)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Public Member Functions
MQ3 Class Reference

API for the MQ3 Gas Sensor. More...

Detailed Description

The MQ3 Gas Sensor module is useful for gas leakage detection (in home and industry). It can detect alcohol vapors and benzine. It's highly sensitive but has a long warm-up time of about 1 minute. It's detection range is 0.04-4 mg/L Alcohol.

main(int argc, char **argv)
// Attach gas sensor to A0
sensor = new upm::MQ3(0);
signal(SIGINT, sig_handler);
ctx.averageReading = 0;
ctx.runningAverage = 0;
ctx.averagedOver = 2;
// Infinite loop, ends when script is cancelled
// Repeatedly, take a sample every 2 milliseconds;
// find the average of 128 samples; and
// print a running graph of the averages using a resolution of 5
while (!is_running) {
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 ....
std::cout << "exiting application" << std::endl;
delete sensor;
return 0;

Public Member Functions

 MQ3 (int gasPin)
 ~MQ3 ()
std::string name ()
- Public Member Functions inherited from Gas
 Gas (int gasPin)
virtual ~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

MQ3 ( int  gasPin)

MQ3 constructor

gasPinAnalog pin where the sensor is connected
~MQ3 ( )

MQ3 destructor

Member Function Documentation

std::string name ( )

Returns the name of the sensor

Inheritance diagram for MQ3:
Inheritance graph
Collaboration diagram for MQ3:
Collaboration graph

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