MQ-X Arduino Library 1.0.0
This is a library for the MQ-X Sensors.
Loading...
Searching...
No Matches
MQ_Sensor Class Reference

#include <MQ-Sensor-SOLDERED.h>

Inherits MQUnifiedsensor.

Inherited by MQ131, MQ135, MQ136, MQ137, MQ138, MQ2, MQ214, MQ3, MQ4, MQ5, MQ6, MQ7, MQ8, and MQ9.

Public Member Functions

 MQ_Sensor (int _aPin, int _dPin, String type, sensorType sType)
 
void begin ()
 Initializes the sensor with default configuration. Sets pin modes for analog and digital pins if they are defined.
 
void begin (sensorType configcustom)
 Initializes the sensor with custom configuration. Sets pin modes for analog and digital pins if they are defined.
 
bool begin (int _addr)
 Initializes the sensor with a specific I2C address. Overloaded function for virtual in base class to initialize sensor specific.
 
bool begin (int _addr, sensorType configcustom)
 Initializes the sensor with a specific I2C address and custom configuration. Overloaded function for virtual in base class to initialize sensor specific.
 
void setRegressionModel (const sensorType &type)
 Sets the regression model parameters for the sensor based on given type.
 
bool calibrateSensor (int numOfCalibrations)
 Calibrates the sensor by taking multiple readings and averaging them.
 
bool digitalRead ()
 Reads the digital pin state of the sensor. Overloaded function for virtual in base class to initialize sensor specific.
 
- Public Member Functions inherited from MQUnifiedsensor
 MQUnifiedsensor (int pin=1, String Placa="Arduino", float Voltage_Resolution=5, int ADC_Bit_Resolution=10, String type="CUSTOM MQ")
 
void init (int addr)
 
void update ()
 
void setR0 (float R0=10)
 
void setRL (float RL=10)
 
void setA (float a)
 
void setB (float b)
 
void setRegressionMethod (int regressionMethod)
 
void setVoltResolution (float voltage_resolution=5)
 
void serialDebug (bool onSetup=false)
 
void setADC (int value)
 
float calibrate (float ratioInCleanAir)
 
float readSensor ()
 
float validateEcuation (float ratioInput=0)
 
float getA ()
 
float getB ()
 
float getR0 ()
 
float getRL ()
 
float getVoltResolution ()
 
String getRegressionMethod ()
 
float getVoltage (int read=true)
 
float stringTofloat (String &str)
 

Private Member Functions

void setConfiguration (sensorType &type)
 Configures the sensor with the given sensor type parameters.
 

Private Attributes

int aPin
 
int dPin
 
sensorType sensor_type
 

Additional Inherited Members

- Public Attributes inherited from MQUnifiedsensor
bool native = 1
 
byte addr = 0
 

Constructor & Destructor Documentation

◆ MQ_Sensor()

MQ_Sensor::MQ_Sensor ( int _aPin,
int _dPin,
String type,
sensorType sType )
inline

Member Function Documentation

◆ begin() [1/4]

void MQ_Sensor::begin ( )

Initializes the sensor with default configuration. Sets pin modes for analog and digital pins if they are defined.

◆ begin() [2/4]

bool MQ_Sensor::begin ( int _addr)

Initializes the sensor with a specific I2C address. Overloaded function for virtual in base class to initialize sensor specific.

Parameters
_addrI2C address of the sensor
Returns
bool True if initialization successful, false if I2C communication fails

◆ begin() [3/4]

bool MQ_Sensor::begin ( int _addr,
sensorType configcustom )

Initializes the sensor with a specific I2C address and custom configuration. Overloaded function for virtual in base class to initialize sensor specific.

Parameters
_addrI2C address of the sensor
configcustomCustom sensor configuration of type sensorType
Returns
bool True if initialization successful, false if I2C communication fails

◆ begin() [4/4]

void MQ_Sensor::begin ( sensorType configcustom)

Initializes the sensor with custom configuration. Sets pin modes for analog and digital pins if they are defined.

Parameters
configcustomCustom sensor configuration of type sensorType

◆ calibrateSensor()

bool MQ_Sensor::calibrateSensor ( int numOfCalibrations)

Calibrates the sensor by taking multiple readings and averaging them.

Parameters
numOfCalibrationsNumber of calibration readings to take
Returns
bool True if calibration successful, false if calculated R0 is invalid

◆ digitalRead()

bool MQ_Sensor::digitalRead ( )

Reads the digital pin state of the sensor. Overloaded function for virtual in base class to initialize sensor specific.

Returns
bool True if sensor is triggered, false otherwise

◆ setConfiguration()

void MQ_Sensor::setConfiguration ( sensorType & type)
private

Configures the sensor with the given sensor type parameters.

Parameters
typeSensor type configuration containing all necessary parameters

◆ setRegressionModel()

void MQ_Sensor::setRegressionModel ( const sensorType & type)

Sets the regression model parameters for the sensor based on given type.

Parameters
typeSensor type configuration containing regression method and coefficients

Member Data Documentation

◆ aPin

int MQ_Sensor::aPin
private

◆ dPin

int MQ_Sensor::dPin
private

◆ sensor_type

sensorType MQ_Sensor::sensor_type
private

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