2019-05-23 16:51:24 -05:00
|
|
|
/*
|
2019-05-23 16:57:25 -05:00
|
|
|
MQUnifiedsensor Library - reading an MQ2
|
2019-05-23 16:51:24 -05:00
|
|
|
|
2019-05-23 16:55:13 -05:00
|
|
|
Demonstrates the use a MQ2 sensor.
|
2019-05-23 16:51:24 -05:00
|
|
|
Library originally added 01 may 2019
|
|
|
|
by Miguel A Califa, Yersson Carrillo, Ghiordy Contreras, Mario Rodriguez
|
|
|
|
|
|
|
|
Added example
|
|
|
|
modified 23 May 2019
|
|
|
|
by Miguel Califa
|
|
|
|
|
|
|
|
This example code is in the public domain.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
//Include the library
|
2019-05-19 13:27:00 -05:00
|
|
|
#include <MQUnifiedsensor.h>
|
|
|
|
|
2019-05-23 16:51:24 -05:00
|
|
|
//Definitions
|
|
|
|
#define pin A0 //Analog input 0 of your arduino
|
2019-05-23 16:55:13 -05:00
|
|
|
#define type 2 //MQ2
|
2019-05-19 13:27:00 -05:00
|
|
|
|
2019-05-29 20:41:04 -05:00
|
|
|
/***************************** MQInicializar****************************************
|
|
|
|
Input: pin, type
|
|
|
|
Output:
|
|
|
|
Remarks: This function create the sensor object.
|
|
|
|
************************************************************************************/
|
2019-05-23 16:51:24 -05:00
|
|
|
//Declare Sensor
|
2019-05-23 16:55:13 -05:00
|
|
|
MQUnifiedsensor MQ2(pin, type);
|
2019-05-19 13:27:00 -05:00
|
|
|
|
2019-05-23 16:51:24 -05:00
|
|
|
void setup() {
|
2019-05-26 15:18:16 -05:00
|
|
|
//Init serial port
|
|
|
|
Serial.begin(115200);
|
2019-05-29 20:41:04 -05:00
|
|
|
/***************************** MQInicializar****************************************
|
|
|
|
Input:
|
|
|
|
Output:
|
|
|
|
Remarks: This function configure the pinMode
|
|
|
|
************************************************************************************/
|
2019-05-23 16:51:24 -05:00
|
|
|
//init the sensor
|
2019-05-23 16:55:13 -05:00
|
|
|
MQ2.inicializar();
|
2019-05-19 13:27:00 -05:00
|
|
|
}
|
|
|
|
|
2019-05-29 20:41:04 -05:00
|
|
|
void loop() {
|
|
|
|
/***************************** MQReadSensor ****************************************
|
|
|
|
Input: Gas - Serial print flag
|
|
|
|
Output: Value in PPM
|
|
|
|
Remarks: This function use readPPM to read the value in PPM the gas in the air.
|
|
|
|
************************************************************************************/
|
2019-05-26 15:18:16 -05:00
|
|
|
//Read the sensor and print in serial port
|
|
|
|
int lecture = MQ2.readSensor("", true);
|
|
|
|
delay(400);
|
2019-05-19 13:27:00 -05:00
|
|
|
}
|