mirror of
https://github.com/miguel5612/MQSensorsLib.git
synced 2025-03-15 05:17:30 +03:00
Changed variable types
This commit is contained in:
parent
9a1974033e
commit
3d1bb90e38
@ -19,7 +19,7 @@
|
|||||||
//Definitions
|
//Definitions
|
||||||
#define placa "Arduino UNO"
|
#define placa "Arduino UNO"
|
||||||
#define Voltage_Resolution 5
|
#define Voltage_Resolution 5
|
||||||
#define pin A0 //Analog input 0 of your arduino
|
#define pin A2 //Analog input 0 of your arduino
|
||||||
#define type "MQ-2" //MQ2
|
#define type "MQ-2" //MQ2
|
||||||
#define ADC_Bit_Resolution 10 // For arduino UNO/MEGA/NANO
|
#define ADC_Bit_Resolution 10 // For arduino UNO/MEGA/NANO
|
||||||
|
|
||||||
@ -40,7 +40,7 @@
|
|||||||
|
|
||||||
//Declare Sensor
|
//Declare Sensor
|
||||||
|
|
||||||
MQUnifiedsensor MQ2(placa, Voltage_Resolution, ADC_Bit_Resolution, pin2, type);
|
MQUnifiedsensor MQ2(placa, Voltage_Resolution, ADC_Bit_Resolution, pin, type);
|
||||||
unsigned long contador = 0;
|
unsigned long contador = 0;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
@ -51,16 +51,18 @@ void setup() {
|
|||||||
//init the sensor
|
//init the sensor
|
||||||
MQ2.init();
|
MQ2.init();
|
||||||
//Print in serial monitor
|
//Print in serial monitor
|
||||||
Serial.print("MQ2 - Calibracion");
|
Serial.println("MQ2 - Calibracion");
|
||||||
Serial.print("Note - Make sure you are in a clean room and the sensor has pre-heated almost 4 hours");
|
Serial.println("Note - Make sure you are in a clean room and the sensor has pre-heated almost 4 hours");
|
||||||
Serial.print("Autonumeric, lecture");
|
Serial.println("Autonumeric | lecture (R0)");
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
MQ2.update();
|
||||||
//Read the sensor and print in serial port
|
//Read the sensor and print in serial port
|
||||||
int lecture = MQ2.calibrate(RatioMQ2CleanAir);
|
float lecture = MQ2.calibrate(RatioMQ2CleanAir);
|
||||||
//Print in serial monitor
|
//Print in serial monitor
|
||||||
Serial.print(String(contador) + ",");
|
Serial.print(contador);
|
||||||
|
Serial.print(" | ");
|
||||||
Serial.println(lecture);
|
Serial.println(lecture);
|
||||||
//Increment counter
|
//Increment counter
|
||||||
contador++;
|
contador++;
|
||||||
|
@ -57,7 +57,7 @@ void setup() {
|
|||||||
// This routine not need to execute to every restart, you can load your R0 if you know the value
|
// This routine not need to execute to every restart, you can load your R0 if you know the value
|
||||||
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||||
Serial.print("Calibrating please wait.");
|
Serial.print("Calibrating please wait.");
|
||||||
int calcR0 = 0;
|
float calcR0 = 0;
|
||||||
for(int i = 0; i<=10; i ++)
|
for(int i = 0; i<=10; i ++)
|
||||||
{
|
{
|
||||||
MQ131.update(); // Update data, the arduino will be read the voltage on the analog pin
|
MQ131.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||||
|
@ -60,7 +60,7 @@ void setup() {
|
|||||||
// This routine not need to execute to every restart, you can load your R0 if you know the value
|
// This routine not need to execute to every restart, you can load your R0 if you know the value
|
||||||
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||||
Serial.print("Calibrating please wait.");
|
Serial.print("Calibrating please wait.");
|
||||||
int calcR0 = 0;
|
float calcR0 = 0;
|
||||||
for(int i = 0; i<=10; i ++)
|
for(int i = 0; i<=10; i ++)
|
||||||
{
|
{
|
||||||
MQ135.update(); // Update data, the arduino will be read the voltage on the analog pin
|
MQ135.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||||
|
@ -56,7 +56,7 @@ void setup() {
|
|||||||
// This routine not need to execute to every restart, you can load your R0 if you know the value
|
// This routine not need to execute to every restart, you can load your R0 if you know the value
|
||||||
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||||
Serial.print("Calibrating please wait.");
|
Serial.print("Calibrating please wait.");
|
||||||
int calcR0 = 0;
|
float calcR0 = 0;
|
||||||
for(int i = 0; i<=10; i ++)
|
for(int i = 0; i<=10; i ++)
|
||||||
{
|
{
|
||||||
MQ2.update(); // Update data, the arduino will be read the voltage on the analog pin
|
MQ2.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||||
|
@ -59,7 +59,7 @@ void setup() {
|
|||||||
// This routine not need to execute to every restart, you can load your R0 if you know the value
|
// This routine not need to execute to every restart, you can load your R0 if you know the value
|
||||||
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||||
Serial.print("Calibrating please wait.");
|
Serial.print("Calibrating please wait.");
|
||||||
int calcR0 = 0;
|
float calcR0 = 0;
|
||||||
for(int i = 0; i<=10; i ++)
|
for(int i = 0; i<=10; i ++)
|
||||||
{
|
{
|
||||||
MQ3.update(); // Update data, the arduino will be read the voltage on the analog pin
|
MQ3.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||||
|
@ -57,7 +57,7 @@ void setup() {
|
|||||||
// This routine not need to execute to every restart, you can load your R0 if you know the value
|
// This routine not need to execute to every restart, you can load your R0 if you know the value
|
||||||
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||||
Serial.print("Calibrating please wait.");
|
Serial.print("Calibrating please wait.");
|
||||||
int calcR0 = 0;
|
float calcR0 = 0;
|
||||||
for(int i = 0; i<=10; i ++)
|
for(int i = 0; i<=10; i ++)
|
||||||
{
|
{
|
||||||
MQ303.update(); // Update data, the arduino will be read the voltage on the analog pin
|
MQ303.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||||
|
@ -58,7 +58,7 @@ void setup() {
|
|||||||
// This routine not need to execute to every restart, you can load your R0 if you know the value
|
// This routine not need to execute to every restart, you can load your R0 if you know the value
|
||||||
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||||
Serial.print("Calibrating please wait.");
|
Serial.print("Calibrating please wait.");
|
||||||
int calcR0 = 0;
|
float calcR0 = 0;
|
||||||
for(int i = 0; i<=10; i ++)
|
for(int i = 0; i<=10; i ++)
|
||||||
{
|
{
|
||||||
MQ309.update(); // Update data, the arduino will be read the voltage on the analog pin
|
MQ309.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||||
|
@ -59,7 +59,7 @@ void setup() {
|
|||||||
// This routine not need to execute to every restart, you can load your R0 if you know the value
|
// This routine not need to execute to every restart, you can load your R0 if you know the value
|
||||||
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||||
Serial.print("Calibrating please wait.");
|
Serial.print("Calibrating please wait.");
|
||||||
int calcR0 = 0;
|
float calcR0 = 0;
|
||||||
for(int i = 0; i<=10; i ++)
|
for(int i = 0; i<=10; i ++)
|
||||||
{
|
{
|
||||||
MQ4.update(); // Update data, the arduino will be read the voltage on the analog pin
|
MQ4.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||||
|
@ -58,7 +58,7 @@ void setup() {
|
|||||||
// This routine not need to execute to every restart, you can load your R0 if you know the value
|
// This routine not need to execute to every restart, you can load your R0 if you know the value
|
||||||
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||||
Serial.print("Calibrating please wait.");
|
Serial.print("Calibrating please wait.");
|
||||||
int calcR0 = 0;
|
float calcR0 = 0;
|
||||||
for(int i = 0; i<=10; i ++)
|
for(int i = 0; i<=10; i ++)
|
||||||
{
|
{
|
||||||
MQ5.update(); // Update data, the arduino will be read the voltage on the analog pin
|
MQ5.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||||
|
@ -58,7 +58,7 @@ void setup() {
|
|||||||
// This routine not need to execute to every restart, you can load your R0 if you know the value
|
// This routine not need to execute to every restart, you can load your R0 if you know the value
|
||||||
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||||
Serial.print("Calibrating please wait.");
|
Serial.print("Calibrating please wait.");
|
||||||
int calcR0 = 0;
|
float calcR0 = 0;
|
||||||
for(int i = 0; i<=10; i ++)
|
for(int i = 0; i<=10; i ++)
|
||||||
{
|
{
|
||||||
MQ6.update(); // Update data, the arduino will be read the voltage on the analog pin
|
MQ6.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||||
|
@ -59,7 +59,7 @@ void setup() {
|
|||||||
// This routine not need to execute to every restart, you can load your R0 if you know the value
|
// This routine not need to execute to every restart, you can load your R0 if you know the value
|
||||||
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||||
Serial.print("Calibrating please wait.");
|
Serial.print("Calibrating please wait.");
|
||||||
int calcR0 = 0;
|
float calcR0 = 0;
|
||||||
for(int i = 0; i<=10; i ++)
|
for(int i = 0; i<=10; i ++)
|
||||||
{
|
{
|
||||||
MQ7.update(); // Update data, the arduino will be read the voltage on the analog pin
|
MQ7.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||||
|
@ -59,7 +59,7 @@ void setup() {
|
|||||||
// This routine not need to execute to every restart, you can load your R0 if you know the value
|
// This routine not need to execute to every restart, you can load your R0 if you know the value
|
||||||
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||||
Serial.print("Calibrating please wait.");
|
Serial.print("Calibrating please wait.");
|
||||||
int calcR0 = 0;
|
float calcR0 = 0;
|
||||||
for(int i = 0; i<=10; i ++)
|
for(int i = 0; i<=10; i ++)
|
||||||
{
|
{
|
||||||
MQ8.update(); // Update data, the arduino will be read the voltage on the analog pin
|
MQ8.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||||
|
@ -57,7 +57,7 @@ void setup() {
|
|||||||
// This routine not need to execute to every restart, you can load your R0 if you know the value
|
// This routine not need to execute to every restart, you can load your R0 if you know the value
|
||||||
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||||
Serial.print("Calibrating please wait.");
|
Serial.print("Calibrating please wait.");
|
||||||
int calcR0 = 0;
|
float calcR0 = 0;
|
||||||
for(int i = 0; i<=10; i ++)
|
for(int i = 0; i<=10; i ++)
|
||||||
{
|
{
|
||||||
MQ9.update(); // Update data, the arduino will be read the voltage on the analog pin
|
MQ9.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||||
|
@ -1,207 +0,0 @@
|
|||||||
/*
|
|
||||||
MQUnifiedsensor Library - calibrating an MQ2 to MQ9
|
|
||||||
|
|
||||||
Demonstrates the use a MQ2 sensor.
|
|
||||||
Library originally added 01 may 2019
|
|
||||||
by Miguel A Califa, Yersson Carrillo, Ghiordy Contreras, Mario Rodriguez
|
|
||||||
|
|
||||||
Added example
|
|
||||||
modified 27 May 2019
|
|
||||||
by Miguel Califa
|
|
||||||
|
|
||||||
Added LCD
|
|
||||||
modified 26 May 2019
|
|
||||||
by Miguel Califa
|
|
||||||
|
|
||||||
Changed sample frecuency
|
|
||||||
modified 28 May 2019
|
|
||||||
by Ghiordy contreras, Miguel Califa
|
|
||||||
|
|
||||||
Added voltaje to log
|
|
||||||
modified 29 May 2019
|
|
||||||
by Miguel Califa
|
|
||||||
|
|
||||||
This example code is in the public domain.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
//Include the library
|
|
||||||
#include <MQUnifiedsensor.h>
|
|
||||||
//And lcd library
|
|
||||||
#include <Wire.h>
|
|
||||||
#include <LiquidCrystal_I2C.h>
|
|
||||||
|
|
||||||
// Set the LCD address to 0x27 for a 16 chars and 2 line display
|
|
||||||
LiquidCrystal_I2C lcd(0x27, 16, 2);
|
|
||||||
|
|
||||||
//Definitions
|
|
||||||
#define placa "Arduino Mega 2560"
|
|
||||||
#define Voltage_Resolution 5
|
|
||||||
#define type "MQ-Board"
|
|
||||||
#define ADC_Bit_Resolution 10 // For arduino UNO/MEGA/NANO
|
|
||||||
#define pin2 A2 //Analog input 2 of your arduino
|
|
||||||
#define pin3 A3 //Analog input 3 of your arduino
|
|
||||||
#define pin4 A4 //Analog input 4 of your arduino
|
|
||||||
#define pin5 A5 //Analog input 5 of your arduino
|
|
||||||
#define pin6 A6 //Analog input 6 of your arduino
|
|
||||||
#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 timeDelay 500
|
|
||||||
//Declare Sensor
|
|
||||||
|
|
||||||
MQUnifiedsensor MQ2(placa, Voltage_Resolution, ADC_Bit_Resolution, pin2, type);
|
|
||||||
MQUnifiedsensor MQ3(placa, Voltage_Resolution, ADC_Bit_Resolution, pin3, type);
|
|
||||||
MQUnifiedsensor MQ4(placa, Voltage_Resolution, ADC_Bit_Resolution, pin4, type);
|
|
||||||
MQUnifiedsensor MQ5(placa, Voltage_Resolution, ADC_Bit_Resolution, pin5, type);
|
|
||||||
MQUnifiedsensor MQ6(placa, Voltage_Resolution, ADC_Bit_Resolution, pin6, type);
|
|
||||||
MQUnifiedsensor MQ7(placa, Voltage_Resolution, ADC_Bit_Resolution, pin7, type);
|
|
||||||
MQUnifiedsensor MQ8(placa, Voltage_Resolution, ADC_Bit_Resolution, pin8, type);
|
|
||||||
MQUnifiedsensor MQ9(placa, Voltage_Resolution, ADC_Bit_Resolution, pin9, type);
|
|
||||||
|
|
||||||
unsigned long contador = 0;
|
|
||||||
unsigned long time = millis();
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
//Init serial port
|
|
||||||
Serial.begin(9600);
|
|
||||||
// initialize the LCD
|
|
||||||
lcd.begin();
|
|
||||||
// Turn on the blacklight and print a message.
|
|
||||||
lcd.backlight();
|
|
||||||
//Welcome message
|
|
||||||
lcd.clear();
|
|
||||||
lcd.setCursor(0,0);
|
|
||||||
lcd.print("MQ2 to MQ9");
|
|
||||||
lcd.setCursor(0,1);
|
|
||||||
lcd.print(" Calibrating");
|
|
||||||
//init the sensor
|
|
||||||
|
|
||||||
MQ2.init();
|
|
||||||
MQ2.setRegressionMethod(1); //_PPM = a*ratio^b
|
|
||||||
MQ2.setA(574.25); MQ2.setB(-2.222); // Configurate the ecuation values to get LPG concentration
|
|
||||||
MQ2.setR0(9.659574468);
|
|
||||||
|
|
||||||
MQ3.init();
|
|
||||||
MQ3.setRegressionMethod(1); //_PPM = a*ratio^b
|
|
||||||
MQ3.setA(4.8387); MQ3.setB(-2.68); // Configurate the ecuation values to get Benzene concentration
|
|
||||||
MQ3.setR0(3.86018237);
|
|
||||||
|
|
||||||
MQ4.init();
|
|
||||||
MQ4.setRegressionMethod(1); //_PPM = a*ratio^b
|
|
||||||
MQ4.setA(1012.7); MQ4.setB(-2.786); // Configurate the ecuation values to get CH4 concentration
|
|
||||||
MQ4.setR0(3.86018237);
|
|
||||||
|
|
||||||
MQ5.init();
|
|
||||||
MQ5.setRegressionMethod(1); //_PPM = a*ratio^b
|
|
||||||
MQ5.setA(1163.8); MQ5.setB(-3.874); // Configurate the ecuation values to get H2 concentration
|
|
||||||
MQ5.setR0(71.100304);
|
|
||||||
|
|
||||||
MQ6.init();
|
|
||||||
MQ6.setRegressionMethod(1); //_PPM = a*ratio^b
|
|
||||||
MQ6.setA(2127.2); MQ6.setB(-2.526); // Configurate the ecuation values to get CH4 concentration
|
|
||||||
MQ6.setR0(13.4285714);
|
|
||||||
|
|
||||||
MQ7.init();
|
|
||||||
MQ7.setRegressionMethod(1); //_PPM = a*ratio^b
|
|
||||||
MQ7.setA(99.042); MQ7.setB(-1.518); // Configurate the ecuation values to get CO concentration
|
|
||||||
MQ7.setR0(4);
|
|
||||||
|
|
||||||
MQ8.init();
|
|
||||||
MQ8.setRegressionMethod(1); //_PPM = a*ratio^b
|
|
||||||
MQ8.setA(976.97); MQ8.setB(-0.688); // Configurate the ecuation values to get H2 concentration
|
|
||||||
MQ8.setR0(1);
|
|
||||||
|
|
||||||
MQ9.init();
|
|
||||||
MQ9.setRegressionMethod(1); //_PPM = a*ratio^b
|
|
||||||
MQ9.setA(1000.5); MQ9.setB(-2.186); // Configurate the ecuation values to get LPG concentration
|
|
||||||
MQ9.setR0(9.42857143);
|
|
||||||
|
|
||||||
//Print in serial monitor
|
|
||||||
Serial.println("MQ2 to MQ9 - Calibracion");
|
|
||||||
Serial.println("Note - Make sure you are in a clean room and the sensor has pre-heated almost 4 hours");
|
|
||||||
Serial.println("Note - All values are in KOhms");
|
|
||||||
Serial.println("Autonumeric, MQ2(R0), MQ3(R0), MQ4(R0), MQ5(R0), MQ6(R0), MQ7(R0), MQ8(R0), MQ9(R0), v2(VDC), v3(VDC), v4(VDC), v5(VDC), v6(VDC), v7(VDC), v8(VDC), v9(VDC)");
|
|
||||||
//Wait one second to continue
|
|
||||||
delay(timeDelay/10);
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
//Update the voltage lectures
|
|
||||||
MQ2.update();
|
|
||||||
MQ3.update();
|
|
||||||
MQ4.update();
|
|
||||||
MQ5.update();
|
|
||||||
MQ6.update();
|
|
||||||
MQ7.update();
|
|
||||||
MQ8.update();
|
|
||||||
MQ9.update();
|
|
||||||
|
|
||||||
//Read the sensor
|
|
||||||
float lecture2 = MQ2.calibrate(RatioMQ2CleanAir);
|
|
||||||
float lecture3 = MQ3.calibrate(RatioMQ3CleanAir);
|
|
||||||
float lecture4 = MQ4.calibrate(RatioMQ4CleanAir);
|
|
||||||
float lecture5 = MQ5.calibrate(RatioMQ5CleanAir);
|
|
||||||
float lecture6 = MQ6.calibrate(RatioMQ6CleanAir);
|
|
||||||
float lecture7 = MQ7.calibrate(RatioMQ7CleanAir);
|
|
||||||
float lecture8 = MQ8.calibrate(RatioMQ8CleanAir);
|
|
||||||
float lecture9 = MQ9.calibrate(RatioMQ9CleanAir);
|
|
||||||
|
|
||||||
//Read voltage the sensor
|
|
||||||
float v2 = MQ2.getVoltage(false);
|
|
||||||
float v3 = MQ3.getVoltage(false);
|
|
||||||
float v4 = MQ4.getVoltage(false);
|
|
||||||
float v5 = MQ5.getVoltage(false);
|
|
||||||
float v6 = MQ6.getVoltage(false);
|
|
||||||
float v7 = MQ7.getVoltage(false);
|
|
||||||
float v8 = MQ8.getVoltage(false);
|
|
||||||
float v9 = MQ9.getVoltage(false);
|
|
||||||
|
|
||||||
|
|
||||||
//Print in serial monitor
|
|
||||||
Serial.print(contador);Serial.print(",");
|
|
||||||
Serial.print(lecture2);Serial.print(",");
|
|
||||||
Serial.print(lecture3);Serial.print(",");
|
|
||||||
Serial.print(lecture4);Serial.print(",");
|
|
||||||
Serial.print(lecture5);Serial.print(",");
|
|
||||||
Serial.print(lecture6);Serial.print(",");
|
|
||||||
Serial.print(lecture7);Serial.print(",");
|
|
||||||
Serial.print(lecture8);Serial.print(",");
|
|
||||||
Serial.print(lecture9);Serial.print(",");
|
|
||||||
//Print voltages
|
|
||||||
Serial.print(v2);Serial.print(",");
|
|
||||||
Serial.print(v3);Serial.print(",");
|
|
||||||
Serial.print(v4);Serial.print(",");
|
|
||||||
Serial.print(v5);Serial.print(",");
|
|
||||||
Serial.print(v6);Serial.print(",");
|
|
||||||
Serial.print(v7);Serial.print(",");
|
|
||||||
Serial.print(v8);Serial.print(",");
|
|
||||||
Serial.println(v9);
|
|
||||||
|
|
||||||
|
|
||||||
//Print in LCD
|
|
||||||
lcd.clear();
|
|
||||||
lcd.setCursor(0,0);
|
|
||||||
lcd.print("**CALIBRATING***");
|
|
||||||
lcd.setCursor(0,1);
|
|
||||||
lcd.print("Time: " + String((millis() - time)/60000) + "min");
|
|
||||||
//Increment counter
|
|
||||||
contador++;
|
|
||||||
//Wait to measure next sample
|
|
||||||
delay(timeDelay/4);
|
|
||||||
}
|
|
@ -29,7 +29,15 @@
|
|||||||
#define pin7 A7 //Analog input 7 of your arduino
|
#define pin7 A7 //Analog input 7 of your arduino
|
||||||
#define pin8 A8 //Analog input 8 of your arduino
|
#define pin8 A8 //Analog input 8 of your arduino
|
||||||
#define pin9 A9 //Analog input 9 of your arduino
|
#define pin9 A9 //Analog input 9 of your arduino
|
||||||
//#define calibration_button 13 //Pin to calibrate your sensor
|
|
||||||
|
#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
|
||||||
|
|
||||||
//Declare Sensor
|
//Declare Sensor
|
||||||
MQUnifiedsensor MQ2(placa, Voltage_Resolution, ADC_Bit_Resolution, pin2, type);
|
MQUnifiedsensor MQ2(placa, Voltage_Resolution, ADC_Bit_Resolution, pin2, type);
|
||||||
@ -87,8 +95,75 @@ void setup() {
|
|||||||
MQ9.setRegressionMethod(1); //_PPM = a*ratio^b
|
MQ9.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||||
MQ9.setA(1000.5); MQ9.setB(-2.186); // Configurate the ecuation values to get LPG concentration
|
MQ9.setA(1000.5); MQ9.setB(-2.186); // Configurate the ecuation values to get LPG concentration
|
||||||
MQ9.setR0(9.42857143);
|
MQ9.setR0(9.42857143);
|
||||||
|
|
||||||
|
/***************************** MQ CAlibration ********************************************/
|
||||||
|
// Explanation:
|
||||||
|
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
|
||||||
|
// and now is on clean air (Calibration conditions), and it will setup R0 value.
|
||||||
|
// We recomend execute this routine only on setup or on the laboratory and save on the eeprom of your arduino
|
||||||
|
// This routine not need to execute to every restart, you can load your R0 if you know the value
|
||||||
|
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||||
|
Serial.print("Calibrating please wait.");
|
||||||
|
float MQ2calcR0 = 0,
|
||||||
|
MQ3calcR0 = 0,
|
||||||
|
MQ4calcR0 = 0,
|
||||||
|
MQ5calcR0 = 0,
|
||||||
|
MQ6calcR0 = 0,
|
||||||
|
MQ7calcR0 = 0,
|
||||||
|
MQ8calcR0 = 0,
|
||||||
|
MQ9calcR0 = 0;
|
||||||
|
for(int i = 0; i<=20; i ++)
|
||||||
|
{
|
||||||
|
//Update the voltage lectures
|
||||||
|
MQ2.update();
|
||||||
|
MQ3.update();
|
||||||
|
MQ4.update();
|
||||||
|
MQ5.update();
|
||||||
|
MQ6.update();
|
||||||
|
MQ7.update();
|
||||||
|
MQ8.update();
|
||||||
|
MQ9.update();
|
||||||
|
|
||||||
|
MQ2calcR0 += MQ2.calibrate(RatioMQ2CleanAir);
|
||||||
|
MQ3calcR0 += MQ2.calibrate(RatioMQ3CleanAir);
|
||||||
|
MQ4calcR0 += MQ2.calibrate(RatioMQ4CleanAir);
|
||||||
|
MQ5calcR0 += MQ2.calibrate(RatioMQ5CleanAir);
|
||||||
|
MQ6calcR0 += MQ2.calibrate(RatioMQ6CleanAir);
|
||||||
|
MQ7calcR0 += MQ2.calibrate(RatioMQ7CleanAir);
|
||||||
|
MQ8calcR0 += MQ2.calibrate(RatioMQ8CleanAir);
|
||||||
|
MQ9calcR0 += MQ2.calibrate(RatioMQ9CleanAir);
|
||||||
|
|
||||||
|
Serial.print(".");
|
||||||
|
}
|
||||||
|
MQ2.setR0(MQ2calcR0/20);
|
||||||
|
MQ3.setR0(MQ3calcR0/20);
|
||||||
|
MQ4.setR0(MQ4calcR0/20);
|
||||||
|
MQ5.setR0(MQ5calcR0/20);
|
||||||
|
MQ6.setR0(MQ6calcR0/20);
|
||||||
|
MQ7.setR0(MQ7calcR0/20);
|
||||||
|
MQ8.setR0(MQ8calcR0/20);
|
||||||
|
MQ9.setR0(MQ9calcR0/20);
|
||||||
|
Serial.println(" done!.");
|
||||||
|
|
||||||
|
Serial.print("Valores de R0 para cada sensor (MQ2 - MQ9):");
|
||||||
|
Serial.print(MQ2calcR0/10); Serial.print(" | ");
|
||||||
|
Serial.print(MQ3calcR0/10); Serial.print(" | ");
|
||||||
|
Serial.print(MQ4calcR0/10); Serial.print(" | ");
|
||||||
|
Serial.print(MQ5calcR0/10); Serial.print(" | ");
|
||||||
|
Serial.print(MQ6calcR0/10); Serial.print(" | ");
|
||||||
|
Serial.print(MQ7calcR0/10); Serial.print(" | ");
|
||||||
|
Serial.print(MQ8calcR0/10); Serial.print(" | ");
|
||||||
|
Serial.print(MQ9calcR0/10); Serial.println(" |");
|
||||||
|
|
||||||
|
if(isinf(MQ2calcR0) || isinf(MQ3calcR0) || isinf(MQ4calcR0) || isinf(MQ5calcR0) || isinf(MQ6calcR0) || isinf(MQ7calcR0) || isinf(MQ8calcR0) || isinf(MQ9calcR0)) {Serial.println("Warning: Conection issue founded, R0 is infite (Open circuit detected) please check your wiring and supply"); while(1);}
|
||||||
|
if(MQ2calcR0 == 0 || MQ3calcR0 == 0 || MQ4calcR0 == 0 || MQ5calcR0 == 0 || MQ6calcR0 == 0 || MQ7calcR0 == 0 || MQ8calcR0 == 0 || MQ9calcR0 == 0){Serial.println("Warning: Conection issue founded, R0 is zero (Analog pin with short circuit to ground) please check your wiring and supply"); while(1);}
|
||||||
|
/***************************** MQ CAlibration ********************************************/
|
||||||
|
|
||||||
//Print in serial monitor
|
//Print in serial monitor
|
||||||
Serial.print("MQ2 to MQ9 - lecture");
|
Serial.println("MQ2 to MQ9 - lecture");
|
||||||
|
Serial.println("*************************** Lectures from MQ-board ***************************");
|
||||||
|
Serial.println("| LPG | Benzene | CH4 | H2 | CH4 | CO | H2 | LPG |");
|
||||||
|
Serial.println("| MQ-2 | MQ-3 | MQ-4 | MQ-5 | MQ-6 | MQ-7 | MQ-8 | MQ-9 |");
|
||||||
//pinMode(calibration_button, INPUT);
|
//pinMode(calibration_button, INPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,24 +200,22 @@ void loop() {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
//Read the sensor and print in serial port
|
//Read the sensor and print in serial port
|
||||||
LPG = MQ2.readSensor();
|
float MQ2Lecture = MQ2.readSensor();
|
||||||
Alcohol = MQ3.readSensor();
|
float MQ3Lecture = MQ3.readSensor();
|
||||||
CH4 = MQ4.readSensor();
|
float MQ4Lecture = MQ4.readSensor();
|
||||||
H2 = MQ5.readSensor();
|
float MQ5Lecture = MQ5.readSensor();
|
||||||
CH42 = MQ6.readSensor();
|
float MQ6Lecture = MQ6.readSensor();
|
||||||
CO = MQ7.readSensor();
|
float MQ7Lecture = MQ7.readSensor();
|
||||||
H22 = MQ8.readSensor();
|
float MQ8Lecture = MQ8.readSensor();
|
||||||
LPG2 = MQ9.readSensor();
|
float MQ9Lecture = MQ9.readSensor();
|
||||||
|
|
||||||
Serial.println("***************************");
|
Serial.print("| "); Serial.print(MQ2Lecture);
|
||||||
Serial.println("Lectures for MQ-Board");
|
Serial.print(" | "); Serial.print(MQ3Lecture);
|
||||||
Serial.print("LPG: ");Serial.print(LPG,2);Serial.println(" PPM");
|
Serial.print(" | "); Serial.print(MQ4Lecture);
|
||||||
Serial.print("Alcohol: ");Serial.print(Alcohol,2);Serial.println(" PPM");
|
Serial.print(" | "); Serial.print(MQ5Lecture);
|
||||||
Serial.print("CH4: ");Serial.print(CH4,2);Serial.println(" PPM");
|
Serial.print(" | "); Serial.print(MQ6Lecture);
|
||||||
Serial.print("H2: ");Serial.print(H2,2);Serial.println(" PPM");
|
Serial.print(" | "); Serial.print(MQ7Lecture);
|
||||||
Serial.print("CH4_2: ");Serial.print(CH42,2);Serial.println(" PPM");
|
Serial.print(" | "); Serial.print(MQ8Lecture);
|
||||||
Serial.print("CO: ");Serial.print(CO,2);Serial.println(" PPM");
|
Serial.print(" | "); Serial.print(MQ9Lecture);
|
||||||
Serial.print("H2_2: ");Serial.print(H22,2);Serial.println(" PPM");
|
Serial.println("|");
|
||||||
Serial.print("LPG_2: ");Serial.print(LPG2,2);Serial.println(" PPM");
|
|
||||||
Serial.println("***************************");
|
|
||||||
}
|
}
|
||||||
|
@ -19,9 +19,10 @@
|
|||||||
//Definitions
|
//Definitions
|
||||||
#define placa "Arduino UNO"
|
#define placa "Arduino UNO"
|
||||||
#define Voltage_Resolution 5
|
#define Voltage_Resolution 5
|
||||||
#define pin A0 //Analog input 0 of your arduino
|
#define pin A4 //Analog input 0 of your arduino
|
||||||
#define type "MQ-4" //MQ4
|
#define type "MQ-4" //MQ4
|
||||||
#define ADC_Bit_Resolution 10 // For arduino UNO/MEGA/NANO
|
#define ADC_Bit_Resolution 10 // For arduino UNO/MEGA/NANO
|
||||||
|
#define RatioMQ4CleanAir 4.4 //RS / R0 = 4.4 ppm
|
||||||
//#define calibration_button 13 //Pin to calibrate your sensor
|
//#define calibration_button 13 //Pin to calibrate your sensor
|
||||||
|
|
||||||
//Declare Sensor
|
//Declare Sensor
|
||||||
@ -47,13 +48,34 @@ void setup() {
|
|||||||
/************************************************************************************/
|
/************************************************************************************/
|
||||||
MQ4.init();
|
MQ4.init();
|
||||||
|
|
||||||
// Calibration setup
|
/***************************** MQ CAlibration ********************************************/
|
||||||
MQ4.setR0(3.86018237);
|
// Explanation:
|
||||||
|
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
|
||||||
|
// and now is on clean air (Calibration conditions), and it will setup R0 value.
|
||||||
|
// We recomend execute this routine only on setup or on the laboratory and save on the eeprom of your arduino
|
||||||
|
// This routine not need to execute to every restart, you can load your R0 if you know the value
|
||||||
|
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||||
|
Serial.print("Calibrating please wait.");
|
||||||
|
float calcR0 = 0;
|
||||||
|
for(int i = 0; i<=10; i ++)
|
||||||
|
{
|
||||||
|
MQ4.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||||
|
calcR0 += MQ4.calibrate(RatioMQ4CleanAir);
|
||||||
|
Serial.print(".");
|
||||||
|
}
|
||||||
|
MQ4.setR0(calcR0/10);
|
||||||
|
Serial.println(" done!.");
|
||||||
|
|
||||||
|
if(isinf(calcR0)) {Serial.println("Warning: Conection issue founded, R0 is infite (Open circuit detected) please check your wiring and supply"); while(1);}
|
||||||
|
if(calcR0 == 0){Serial.println("Warning: Conection issue founded, R0 is zero (Analog pin with short circuit to ground) please check your wiring and supply"); while(1);}
|
||||||
|
/***************************** MQ CAlibration ********************************************/
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
//If the RL value is different from 10K please assign your RL value with the following method:
|
//If the RL value is different from 10K please assign your RL value with the following method:
|
||||||
MQ4.setRL(10);
|
MQ4.setRL(10);
|
||||||
*/
|
*/
|
||||||
|
MQ4.serialDebug(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
@ -64,9 +86,8 @@ 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(); // Return smoke concentration
|
MQ4.update();
|
||||||
Serial.print("MQ4 smoke ppm lecture: ");
|
MQ4.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||||
Serial.print(lecture);
|
MQ4.serialDebug(); // Will print the table on the serial port
|
||||||
Serial.println(" ppm");
|
delay(400);
|
||||||
delay(400);
|
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
/***********************Software Related Macros************************************/
|
/***********************Software Related Macros************************************/
|
||||||
|
|
||||||
#define ADC_RESOLUTION 10 // for 10bit analog to digital converter.
|
#define ADC_RESOLUTION 10 // for 10bit analog to digital converter.
|
||||||
#define retries 5
|
#define retries 2
|
||||||
#define retry_interval 20
|
#define retry_interval 20
|
||||||
|
|
||||||
class MQUnifiedsensor
|
class MQUnifiedsensor
|
||||||
|
Loading…
x
Reference in New Issue
Block a user