From 2cfb8324edb873a84aae1eb8e654bae6b4302e4c Mon Sep 17 00:00:00 2001 From: miguel5612 Date: Thu, 26 Mar 2020 14:45:28 -0500 Subject: [PATCH] Updated smoke detector example --- examples/MQ-Board/MQ-Board.ino | 14 ---------- examples/smokeDetector/smokeDetector.ino | 33 +++++++++++++++++------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/examples/MQ-Board/MQ-Board.ino b/examples/MQ-Board/MQ-Board.ino index 5ff7cb3..3366e84 100644 --- a/examples/MQ-Board/MQ-Board.ino +++ b/examples/MQ-Board/MQ-Board.ino @@ -29,20 +29,6 @@ #define pin7 A7 //Analog input 7 of your arduino #define pin8 A8 //Analog input 8 of your arduino #define pin9 A9 //Analog input 9 of your arduino - -#define RatioMQ2CleanAir 9.83 //RS / R0 = 9.83 ppm -#define RatioMQ3CleanAir 60 //RS / R0 = 60 ppm -#define RatioMQ4CleanAir 4.4 //RS / R0 = 4.4 ppm -#define RatioMQ5CleanAir 6.5 //RS / R0 = 6.5 ppm -#define RatioMQ6CleanAir 10 //RS / R0 = 10 ppm -#define RatioMQ7CleanAir 27.5 //RS / R0 = 27.5 ppm -#define RatioMQ8CleanAir 70 //RS / R0 = 70 ppm -#define RatioMQ9CleanAir 9.6 //RS / R0 = 9.6 ppm -#define RatioMQ131CleanAir 15 //RS / R0 = 15 ppm -#define RatioMQ135CleanAir 3.6//RS / R0 = 3.6 ppm -#define RatioMQ303CleanAir 1 //RS / R0 = 1 ppm -#define RatioMQ309CleanAir 11 //RS / R0 = 11 ppm - //#define calibration_button 13 //Pin to calibrate your sensor //Declare Sensor diff --git a/examples/smokeDetector/smokeDetector.ino b/examples/smokeDetector/smokeDetector.ino index f771486..d4f9f9d 100644 --- a/examples/smokeDetector/smokeDetector.ino +++ b/examples/smokeDetector/smokeDetector.ino @@ -17,22 +17,35 @@ #include //Definitions +#define placa "Arduino UNO" +#define Voltage_Resolution 5 #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 -MQUnifiedsensor MQ4(pin, type); +MQUnifiedsensor MQ4(placa, Voltage_Resolution, ADC_Bit_Resolution, pin, type); void setup() { //Init serial port Serial.begin(115200); - /***************************** MQInicializar**************************************** - Input: - Output: - Remarks: This function configure the pinMode - ************************************************************************************/ - //init the sensor - MQ4.inicializar(); + //Set math model to calculate the PPM concentration and the value of constants + MQ4.setRegressionMethod("Exponential"); //_PPM = a*ratio^b + MQ4.setA(30000000); MQ4.setB(-2.786); // Configurate the ecuation values to get CH4 concentration + /* + Exponential regression: + Gas | a | b + 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() { @@ -43,7 +56,7 @@ void setup() { ************************************************************************************/ //Read the sensor and print in serial port //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(lecture); Serial.println(" ppm");