upm  0.4.1
Sensor/Actuator repository for libmraa (v0.8.0)
Public Member Functions | List of all members

API for the Grove MQ2 Gas Sensor. More...

Detailed Description

The Grove MQ2 Gas Sensor module is useful for gas leakage detection (in home and industry). It can detect LPG, i-butane, methane, alcohol, hydrogen, smoke, and other combustible gases. It's a medium-sensitivity sensor with a detection range of 300-10,000 ppm.

mq2-5.jpeg
short[] buffer = new short[128];
// Attach gas sensor to A0
upm_gas.MQ2 sensor = new upm_gas.MQ2(0);
ctx.setAverageReading(0);
ctx.setRunningAverage(0);
ctx.setAveragedOver(2);
while (true) {
int len = sensor.getSampledWindow(2, buffer);
if (len != 0) {
int thresh = sensor.findThreshold(ctx, 30, buffer);
sensor.printGraph(ctx, resolution);
if (thresh != 0) {
System.out.println("---Threshold reached---");
}
}
Thread.sleep(1000);
}

Public Member Functions

synchronized void delete ()
 
 MQ2 (int gasPin)
 
String name ()
 
- Public Member Functions inherited from Gas
synchronized void delete ()
 
 Gas (int gasPin)
 
int getSampledWindow (long freqMS, short[] numberOfSamples)
 
int findThreshold (thresholdContext ctx, long threshold, short[] buffer)
 
int getSampledData (thresholdContext ctx)
 
int getSample ()
 
void printGraph (thresholdContext ctx, short resolution)
 

Constructor & Destructor Documentation

MQ2 ( int  gasPin)

MQ2 constructor

Parameters
gasPinAnalog pin where the sensor is connected

Member Function Documentation

String name ( )

Returns the name of the sensor

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

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