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-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-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
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
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
|
|
|
}
|