|
|
@ -17,22 +17,35 @@
|
|
|
|
#include <MQUnifiedsensor.h>
|
|
|
|
#include <MQUnifiedsensor.h>
|
|
|
|
|
|
|
|
|
|
|
|
//Definitions
|
|
|
|
//Definitions
|
|
|
|
|
|
|
|
#define placa "Arduino UNO"
|
|
|
|
|
|
|
|
#define Voltage_Resolution 5
|
|
|
|
#define pin A0 //Analog input 0 of your arduino
|
|
|
|
#define pin A0 //Analog input 0 of your arduino
|
|
|
|
#define type 4 //MQ4
|
|
|
|
#define type "MQ-4" //MQ4
|
|
|
|
|
|
|
|
#define ADC_Bit_Resolution 10 // For arduino UNO/MEGA/NANO
|
|
|
|
|
|
|
|
//#define calibration_button 13 //Pin to calibrate your sensor
|
|
|
|
|
|
|
|
|
|
|
|
//Declare Sensor
|
|
|
|
//Declare Sensor
|
|
|
|
MQUnifiedsensor MQ4(pin, type);
|
|
|
|
MQUnifiedsensor MQ4(placa, Voltage_Resolution, ADC_Bit_Resolution, pin, type);
|
|
|
|
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
void setup() {
|
|
|
|
//Init serial port
|
|
|
|
//Init serial port
|
|
|
|
Serial.begin(115200);
|
|
|
|
Serial.begin(115200);
|
|
|
|
/***************************** MQInicializar****************************************
|
|
|
|
//Set math model to calculate the PPM concentration and the value of constants
|
|
|
|
Input:
|
|
|
|
MQ4.setRegressionMethod("Exponential"); //_PPM = a*ratio^b
|
|
|
|
Output:
|
|
|
|
MQ4.setA(30000000); MQ4.setB(-2.786); // Configurate the ecuation values to get CH4 concentration
|
|
|
|
Remarks: This function configure the pinMode
|
|
|
|
/*
|
|
|
|
************************************************************************************/
|
|
|
|
Exponential regression:
|
|
|
|
//init the sensor
|
|
|
|
Gas | a | b
|
|
|
|
MQ4.inicializar();
|
|
|
|
LPG | 3811.9 | -3.113
|
|
|
|
|
|
|
|
CH4 | 1012.7 | -2.786
|
|
|
|
|
|
|
|
CO | 200000000000000 | -19.05
|
|
|
|
|
|
|
|
Alcohol| 60000000000 | -14.01
|
|
|
|
|
|
|
|
smoke | 30000000 | -8.308
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
/***************************** MQ Init ********************************************/
|
|
|
|
|
|
|
|
//Remarks: Configure the pin of arduino as input.
|
|
|
|
|
|
|
|
/************************************************************************************/
|
|
|
|
|
|
|
|
MQ4.init();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
void loop() {
|
|
|
@ -43,7 +56,7 @@ void setup() {
|
|
|
|
************************************************************************************/
|
|
|
|
************************************************************************************/
|
|
|
|
//Read the sensor and print in serial port
|
|
|
|
//Read the sensor and print in serial port
|
|
|
|
//Lecture will be saved in lecture variable
|
|
|
|
//Lecture will be saved in lecture variable
|
|
|
|
int lecture = MQ4.readSensor("smoke"); // Return smoke concentration
|
|
|
|
int lecture = MQ4.readSensor(); // Return smoke concentration
|
|
|
|
Serial.print("MQ4 smoke ppm lecture: ");
|
|
|
|
Serial.print("MQ4 smoke ppm lecture: ");
|
|
|
|
Serial.print(lecture);
|
|
|
|
Serial.print(lecture);
|
|
|
|
Serial.println(" ppm");
|
|
|
|
Serial.println(" ppm");
|
|
|
|