Updated smoke detector example

This commit is contained in:
miguel5612 2020-03-26 14:45:28 -05:00
parent b6da8a2181
commit 2cfb8324ed
2 changed files with 23 additions and 24 deletions

View File

@ -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

View File

@ -17,22 +17,35 @@
#include <MQUnifiedsensor.h>
//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");