Compare commits

..

22 Commits

Author SHA1 Message Date
39b4449899 Added parenthesis to make clear the operation 2020-04-04 10:16:15 -05:00
edd573ba0f Updated example and created release 2020-04-04 10:12:30 -05:00
6ecc769676 Updated example 2020-04-04 09:52:56 -05:00
e07c4b7f71 Added example for ESP-32 2020-04-04 09:52:34 -05:00
952a456a35 Fixed board name 2020-04-04 09:51:16 -05:00
ff0cb0562a Fixed ADC_Bit_Resolution for _ADC_Bit_Resolution 2020-04-04 09:50:14 -05:00
f8d1bcbc76 Update README.md 2020-04-04 09:38:27 -05:00
7c3cd5793c Update README.md 2020-04-04 09:23:47 -05:00
38f93037ce Update README.md 2020-04-02 11:02:50 -05:00
b9ba249140 Update README.md 2020-04-02 11:01:56 -05:00
a7554fa8dd Update README.md 2020-04-02 11:01:02 -05:00
f93b5128ce Update README.md 2020-04-02 09:56:03 -05:00
1a14e12450 Removed excel - Not needed now 2020-04-02 09:52:30 -05:00
9bfea58092 Update README.md 2020-04-02 09:51:43 -05:00
555e49d31e Update README.md 2020-04-02 09:35:18 -05:00
d0b00b4025 Updated props 2020-03-30 20:04:02 -05:00
f83e0fb0d7 Fixed bit comparation to strin 2020-03-30 19:54:22 -05:00
65a1246e51 Fixed ESP8266 volt resolution 3.3 2020-03-30 19:51:23 -05:00
28ce4c80f7 Removed setR0 before calibratioN 2020-03-30 19:46:49 -05:00
9497574e11 Fixed issue on calibratioN 2020-03-30 19:17:25 -05:00
9cbc753758 Updated MQ-board examples 2020-03-30 18:58:07 -05:00
c7b67d7fa5 Updated examples 2020-03-30 18:40:55 -05:00
27 changed files with 552 additions and 471 deletions

120
README.md
View File

@ -1,45 +1,118 @@
<!-- PROJECT SHIELDS -->
<!--
*** I'm using markdown "reference style" links for readability.
*** Reference links are enclosed in brackets [ ] instead of parentheses ( ).
*** See the bottom of this document for the declaration of the reference variables
*** for contributors-url, forks-url, etc. This is an optional, concise syntax you may use.
*** https://www.markdownguide.org/basic-syntax/#reference-style-links
-->
[![DOI](https://zenodo.org/badge/170540207.svg)](https://zenodo.org/badge/latestdoi/170540207)
![Build Status](https://travis-ci.org/dwyl/esta.svg?branch=master)
![Build Status][build-url]
[![Contributors][contributors-shield]][contributors-url]
[![Forks][forks-shield]][forks-url]
[![Stargazers][stars-shield]][stars-url]
[![Issues][issues-shield]][issues-url]
[![MIT License][license-shield]][license-url]
[![LinkedIn][linkedin-shield]][linkedin-url]
# MQSensorsLib
This is a unified library to use sensors MQ: 2, 3, 4, 5, 6, 7, 8, 9, 131, 135, 303A and 309A.
<!-- TABLE OF CONTENTS -->
## Table of Contents
* [Getting Started](#Getting-Started)
* [Wiring](#Wiring)
* [Sensor](#Sensor)
* [Arduino](#Arduino)
* [ESP8266](#ESP8266)
* [User Manual](#usage)
* [Sensor manufacturers](#Sensor-manufacturers)
* [Contributing](#Contributing)
* [Authors](#Authors)
## Getting Started
```
#define placa "Arduino UNO"
#define Voltage_Resolution 5
#define pin A0 //Analog input 0 of your arduino
#define type "MQ-4" //MQ4
#define ADC_Bit_Resolution 10 // For arduino UNO/MEGA/NANO
MQUnifiedsensor MQ4(placa, Voltage_Resolution, ADC_Bit_Resolution, pin, type); //Example if sensor is MQ4 on Arduino UNO board
//Include the library
#include <MQUnifiedsensor.h>
/************************Hardware Related Macros************************************/
#define Board ("Arduino UNO")
#define Pin (A4) //Analog input 4 of your arduino
/***********************Software Related Macros************************************/
#define Type ("MQ-4") //MQ4
#define Voltage_Resolution (5)
#define ADC_Bit_Resolution (10) // For arduino UNO/MEGA/NANO
#define RatioMQ4CleanAir (4.4) //RS / R0 = 60 ppm
/*****************************Globals***********************************************/
//Declare Sensor
MQUnifiedsensor MQ4(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin, Type);
// Setup
MQ4.setRegressionMethod("Exponential"); //_PPM = a*ratio^b
MQ4.setA(1012.7); MQ4.setB(-2.786); // Configurate the ecuation values to get CH4 concentration
MQ4.setR0(3.86018237);
MQ4.setR0(3.86018237); // Value getted on calibration
// Loop
MQ4.init();
MQ4.update();
float ppmCH4 = MQ4.readSensor();
```
## Wiring
### Sensor
#### Important points:
##### Points you should identify
* VCC -> 5V Power supply (+) wire
* GND -> GND Ground (-) wire
* AO -> Analog Output of the sensor
##### Data of board that you should have
* RL Value in KOhms
##### Graph
![Wiring_MQSensor](https://raw.githubusercontent.com/miguel5612/MQSensorsLib_Docs/master/static/img/Points_explanation.jpeg)
#### RS/R0 value (From datasheet of your sensor)
* RS/R0 (Clean air - English) -> (Aire puro - Spanish)
* **Note**: RS/R0 is equal to Ratio variable on the program
![Graph from datasheet](https://raw.githubusercontent.com/miguel5612/MQSensorsLib_Docs/master/static/img/Graph_Explanation.jpeg)
### Arduino
![Arduino_Wiring_MQSensor](https://raw.githubusercontent.com/miguel5612/MQSensorsLib_Docs/master/static/img/MQ_Arduino.PNG)
### ESP8266
![ESP8266_Wiring_MQSensor](https://raw.githubusercontent.com/miguel5612/MQSensorsLib_Docs/master/static/img/MQ_ESP8266.PNG)
### User Manual New!! 12.2019
### User Manual (v1.0) 12.2019
[Manual](https://drive.google.com/open?id=1BAFInlvqKR7h81zETtjz4_RC2EssvFWX)
### User Manual (v2.0) 04.2020
[Manual](https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/Docs/MQSensorLib_2.0.pdf)
[Excel_Help_Spreadsheet (Fill only Volaje Between RL - RS - RL Values)](https://drive.google.com/open?id=1MKDcudQ7BHL_vLGi-lgPh9-pblvygRMq)
### Serial debug (optional)
If your sensor is an **MQ2** (Same for others sensors):
* To enable on setup wrote
```
MQ2.serialDebug(true);
```
* And on Loop Wrote
```
MQ2.serialDebug();
```
* Result:
![Serial debug output](https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/static/img/Serial_Mon_Explanation.jpeg?raw=true)
**Note**:
* ![#c5f015](https://placehold.it/15/c5f015/000000?text=+) `Yellow -> Calibration status.`
* ![#008000](https://placehold.it/15/008000/000000?text=+) `Green -> Hardware and software characteristics.`
* ![#f03c15](https://placehold.it/15/f03c15/000000?text=+) `Red -> Headers of the library calculations.`
* Only valid for **1** gas sensor readings.
**Usage**
* Quick troubleshooting, since it shows everything the library does and the results of the calculations in each function.
### Prerequisites
You'll need Arduino desktop app 1.8.9 or later.
### Sensor manufacture:
### Sensor manufacturers:
| Sensor | Manufacture | URL Datasheet |
|----------|----------|----------|
| MQ-2 | Pololulu| [datasheet](https://www.pololu.com/file/0J309/MQ2.pdf) |
@ -105,8 +178,8 @@ Please read [CONTRIBUTING.md](https://github.com/miguel5612/MQSensorsLib/blob/ma
## Collaborators
* **Andres A. Martinez.**
* **Juan A. Rodríguez.** - [*Github*](https://github.com/Obiot24)
* **Andres A. Martinez.** - [*Github*](https://github.com/andresmacsi) - [CV](https://www.linkedin.com/in/andr%C3%A9s-acevedo-mart%C3%ADnez-73ab35185/?originalSubdomain=co)
* **Juan A. Rodríguez.** - [*Github*](https://github.com/Obiot24) - [CV]()
* **Mario A. Rodríguez O.** - [*GitHub*](https://github.com/MarioAndresR) - [CV](https://scienti.colciencias.gov.co/cvlac/visualizador/generarCurriculoCv.do?cod_rh=0000111304)
See also the list of [contributors](https://github.com/miguel5612/MQSensorsLib/contributors) who participated in this project.
@ -158,3 +231,22 @@ This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md
doi = {10.5281/zenodo.3384301},
url = {https://doi.org/10.5281/zenodo.3384301}
}
<!-- MARKDOWN LINKS & IMAGES -->
<!-- https://www.markdownguide.org/basic-syntax/#reference-style-links -->
[contributors-shield]: https://img.shields.io/github/contributors/miguel5612/MQSensorsLib.svg?style=flat-square
[contributors-url]: https://github.com/miguel5612/MQSensorsLib/graphs/contributors
[forks-shield]: https://img.shields.io/github/forks/miguel5612/MQSensorsLib.svg?style=flat-square
[forks-url]: https://github.com/miguel5612/MQSensorsLib/network/members
[stars-shield]: https://img.shields.io/github/stars/miguel5612/MQSensorsLib.svg?style=flat-square
[stars-url]: https://github.com/miguel5612/MQSensorsLib/stargazers
[issues-shield]: https://img.shields.io/github/issues/miguel5612/MQSensorsLib.svg?style=flat-square
[issues-url]: https://github.com/miguel5612/MQSensorsLib/issues
[license-shield]: https://img.shields.io/github/license/miguel5612/MQSensorsLib.svg?style=flat-square
[license-url]: https://github.com/miguel5612/MQSensorsLib/blob/master/LICENSE.txt
[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=flat-square&logo=linkedin&colorB=555
[build-url]: https://travis-ci.org/dwyl/esta.svg?branch=master
[linkedin-url]: https://www.linkedin.com/in/miguel5612
[product-screenshot]: images/screenshot.png

View File

@ -23,18 +23,18 @@
//Include the library
#include <MQUnifiedsensor.h>
/************************Hardware Related Macros************************************/
#define Board ("Arduino UNO")
#define Pin (A3) //Analog input 3 of your arduino
/***********************Software Related Macros************************************/
#define Type ("MQ-3") //MQ3
#define Voltage_Resolution (5)
#define ADC_Bit_Resolution (10) // For arduino UNO/MEGA/NANO
//Definitions
#define placa "Arduino UNO"
#define Voltage_Resolution 5
#define pin A3 //Analog input 3 of your arduino
#define type "MQ-3" //MQ3
#define ADC_Bit_Resolution 10 // For arduino UNO/MEGA/NANO
//#define calibration_button 13 //Pin to calibrate your sensor
double alcoholPPM = 0;
//Declare Sensor
MQUnifiedsensor MQ3(placa, Voltage_Resolution, ADC_Bit_Resolution, pin, type);
/*****************************Globals***********************************************/
double alcoholPPM = (0);
/**************************Object_Sensor********************************************/
MQUnifiedsensor MQ3(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin, Type);
void setup() {
//Init the serial port communication - to debug the library
@ -45,7 +45,7 @@ void setup() {
MQ3.setA(0.3934); MQ3.setB(-1.504); // Configurate the ecuation values to get Alcohol concentration
/*
Exponential regression:
Gas | a | b
Gas | a | b
LPG | 44771 | -3.245
CH4 | 2*10^31| 19.01
CO | 521853 | -3.821
@ -54,18 +54,35 @@ void setup() {
Hexane | 7585.3 | -2.849
*/
// Calibration setup
MQ3.setR0(3.86018237);
/*
//If the RL value is different from 10K please assign your RL value with the following method:
MQ3.setRL(10);
*/
/***************************** MQ Init ********************************************/
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ3.init();
MQ3.init();
/***************************** 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 calcR0 = 0;
for(int i = 1; i<=10; i ++)
{
MQ3.update(); // Update data, the arduino will be read the voltage on the analog pin
calcR0 += MQ3.calibrate(RatioMQ3CleanAir);
Serial.print(".");
}
MQ3.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 ********************************************/
}
void loop() {

View File

@ -13,20 +13,25 @@
with which the library was made.
*/
//Definitions
#define placa "Arduino Mega 2560"
#define Voltage_Resolution 5
#define type "Algorithm Tester"
#define ADC_Bit_Resolution 10 // For arduino UNO/MEGA/NANO
// On this program pin value doesn't matter
#define pin2 A2 //Analog input 2 of your arduino
//Declare Sensor
MQUnifiedsensor mySensor(placa, Voltage_Resolution, ADC_Bit_Resolution, pin2, type);
//Include the library
#include <MQUnifiedsensor.h>
/************************Hardware Related Macros************************************/
#define Board ("Arduino UNO")
#define Pin (A3) //Analog input 3 of your arduino
/***********************Software Related Macros************************************/
#define Type ("MQ-3") //MQ3
#define Voltage_Resolution (5)
#define ADC_Bit_Resolution (10) // For arduino UNO/MEGA/NANO
double ratio[4] = {};
double expectedValue[4] = {};
double calculatedValues[4] = {};
double error[4] = {};
//Declare Sensor
MQUnifiedsensor mySensor(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin, Type);
/*****************************Globals***********************************************/
double ratio[4] = {};
double expectedValue[4] = {};
double calculatedValues[4] = {};
double error[4] = {};
/**************************Object_Sensor********************************************/
void setup()
{

View File

@ -15,15 +15,16 @@
//Include the library
#include <MQUnifiedsensor.h>
/************************Hardware Related Macros************************************/
#define Board ("Arduino UNO")
#define Pin (A2) //Analog input 2 of your arduino
/***********************Software Related Macros************************************/
#define Type ("MQ-2") //MQ2
#define Voltage_Resolution (5)
#define ADC_Bit_Resolution (10) // For arduino UNO/MEGA/NANO
//Definitions
#define placa "Arduino UNO"
#define Voltage_Resolution 5
#define pin A2 //Analog input 2 of your arduino
#define type "MQ-2" //MQ2
#define ADC_Bit_Resolution 10 // For arduino UNO/MEGA/NANO
/*****************************Globals***********************************************/
double alcoholPPM = (0);
//Defaults, uncomment if you need
#define RatioMQ2CleanAir 9.83 //RS / R0 = 9.83 ppm
//#define RatioMQ3CleanAir 60 //RS / R0 = 60 ppm
@ -37,17 +38,20 @@
//#define RatioMQ135CleanAir 3.6//RS / R0 = 3.6 ppm
//#define RatioMQ303CleanAir 1 //RS / R0 = 1 ppm
//#define RatioMQ309CleanAir 11 //RS / R0 = 11 ppm
//Declare Sensor
MQUnifiedsensor MQ2(placa, Voltage_Resolution, ADC_Bit_Resolution, pin, type);
unsigned long contador = 0;
/**************************Object_Sensor********************************************/
MQUnifiedsensor MQ2(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin, Type);
void setup() {
//Init serial port
Serial.begin(115200);
MQ2.setRegressionMethod(1); //_PPM = a*ratio^b
MQ2.setA(574.25); MQ2.setB(-2.222); // Configurate the ecuation values to get LPG concentration
/*
//If the RL value is different from 10K please assign your RL value with the following method:
MQ3.setRL(10);
*/
//init the sensor
MQ2.init();
//Print in serial monitor

93
examples/ESP32/esp32.ino Normal file
View File

@ -0,0 +1,93 @@
// This is an example of implementation using ESP8266
// Never connect the sensor direct to the ESP8266, sensor high level is 5V
// ADC of ESP8266 high level is 3.3
// To connect use a voltage divisor, where 5V will 3v3 on the middle point like
// this {{URL}}
/*
MQUnifiedsensor Library - reading an MQSensor using ESP8266 board
For this example wi will demonstrates the use a MQ3 sensor.
Library originally added 01 may 2019
by Miguel A Califa, Yersson Carrillo, Ghiordy Contreras, Mario Rodriguez
Added ESP8266 example
29.03.2020
Wiring:
https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/static/img/MQ_ESP8266.PNG
This example code is in the public domain.
*/
//Include the library
#include <MQUnifiedsensor.h>
/************************Hardware Related Macros************************************/
#define Board ("ESP-32") // Wemos ESP-32 or other board, whatever have ESP32 core.
#define Pin (25) //IO25 for your ESP32 WeMos Board, pinout here: https://i.pinimg.com/originals/66/9a/61/669a618d9435c702f4b67e12c40a11b8.jpg
/***********************Software Related Macros************************************/
#define Type ("MQ-3") //MQ3 or other MQ Sensor, if change this verify your a and b values.
#define Voltage_Resolution (3.3) // 3V3 <- IMPORTANT. Source: https://randomnerdtutorials.com/esp32-adc-analog-read-arduino-ide/
#define ADC_Bit_Resolution (12) // ESP-32 bit resolution. Source: https://randomnerdtutorials.com/esp32-adc-analog-read-arduino-ide/
#define RatioMQ3CleanAir (60) // Ratio of your sensor, for this example an MQ-3
/*****************************Globals***********************************************/
MQUnifiedsensor MQ3(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin, Type);
/*****************************Globals***********************************************/
void setup() {
//Init the serial port communication - to debug the library
Serial.begin(9600); //Init serial port
//Set math model to calculate the PPM concentration and the value of constants
MQ3.setRegressionMethod(1); //_PPM = a*ratio^b
MQ3.setA(4.8387); MQ3.setB(-2.68); // Configurate the ecuation values to get Benzene concentration
/*
Exponential regression:
Gas | a | b
LPG | 44771 | -3.245
CH4 | 2*10^31| 19.01
CO | 521853 | -3.821
Alcohol| 0.3934 | -1.504
Benzene| 4.8387 | -2.68
Hexane | 7585.3 | -2.849
*/
/***************************** MQ Init ********************************************/
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ3.init();
/*
//If the RL value is different from 10K please assign your RL value with the following method:
MQ3.setRL(10);
*/
/***************************** 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 calcR0 = 0;
for(int i = 1; i<=10; i ++)
{
MQ3.update(); // Update data, the arduino will be read the voltage on the analog pin
calcR0 += MQ3.calibrate(RatioMQ3CleanAir);
Serial.print(".");
}
MQ3.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 ********************************************/
MQ3.serialDebug(true);
}
void loop() {
MQ3.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ3.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
MQ3.serialDebug(); // Will print the table on the serial port
delay(500); //Sampling frequency
}

View File

@ -22,16 +22,17 @@
//Include the library
#include <MQUnifiedsensor.h>
//Definitions
#define placa "ESP8266" //NodeMcu, WeMos D1, TTGo, ESP32.. etc
#define Voltage_Resolution 3.3
#define pin A0 //Analog input 0 of your ESP Board
#define type "MQ-3" //MQ3
#define ADC_Bit_Resolution 10 // For ESP8266
//Declare Sensor
MQUnifiedsensor MQ3(placa, Voltage_Resolution, ADC_Bit_Resolution, pin, type);
/************************Hardware Related Macros************************************/
#define Board ("ESP8266")
#define Pin (A0) //Analog input 3 of your arduino
/***********************Software Related Macros************************************/
#define Type ("MQ-3") //MQ3
#define Voltage_Resolution (3.3) // 3V3 <- IMPORTANT
#define ADC_Bit_Resolution (10) // For ESP8266
#define RatioMQ3CleanAir (60)
/*****************************Globals***********************************************/
MQUnifiedsensor MQ3(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin, Type);
/*****************************Globals***********************************************/
void setup() {
//Init the serial port communication - to debug the library
@ -51,23 +52,36 @@ void setup() {
Hexane | 7585.3 | -2.849
*/
// Calibration setup
MQ3.setR0(3.86018237);
/*
//If the RL value is different from 10K please assign your RL value with the following method:
MQ3.setRL(10);
*/
/***************************** MQ Init ********************************************/
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ3.init();
/***************************** MQ Init ********************************************/
//Input: setup flag, if this function are on setup will print the headers (Optional - Default value: False)
//Output: print on serial port the information about sensor and sensor readings
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
/*
//If the RL value is different from 10K please assign your RL value with the following method:
MQ3.setRL(10);
*/
/***************************** 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 calcR0 = 0;
for(int i = 1; i<=10; i ++)
{
MQ3.update(); // Update data, the arduino will be read the voltage on the analog pin
calcR0 += MQ3.calibrate(RatioMQ3CleanAir);
Serial.print(".");
}
MQ3.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 ********************************************/
MQ3.serialDebug(true);
}

View File

@ -52,7 +52,15 @@ void setup() {
O3 | 23.943 | -1.11
*/
/***************************** MQ Init ********************************************/
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ131.init();
/*
//If the RL value is different from 10K please assign your RL value with the following method:
MQ131.setRL(10);
*/
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
@ -74,21 +82,6 @@ void setup() {
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:
MQ131.setRL(10);
*/
/***************************** MQ Init ********************************************/
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ131.init();
/***************************** MQ Init ********************************************/
//Input: setup flag, if this function are on setup will print the headers (Optional - Default value: False)
//Output: print on serial port the information about sensor and sensor readings
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ131.serialDebug(true);
}

View File

@ -43,7 +43,14 @@ void setup() {
//Set math model to calculate the PPM concentration and the value of constants
MQ135.setRegressionMethod(1); //_PPM = a*ratio^b
/***************************** MQ Init ********************************************/
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ135.init();
/*
//If the RL value is different from 10K please assign your RL value with the following method:
MQ135.setRL(10);
*/
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
@ -65,19 +72,6 @@ void setup() {
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:
MQ135.setRL(10);
*/
MQ135.init();
/***************************** MQ Init ********************************************/
//Input: setup flag, if this function are on setup will print the headers (Optional - Default value: False)
//Output: print on serial port the information about sensor and sensor readings
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
Serial.println("** Lectures from MQ-135 ****");
Serial.println("| CO | Alcohol | CO2 | Tolueno | NH4 | Acteona |");
}

View File

@ -54,8 +54,15 @@ void setup() {
NH4 | 102.2 | -2.473
Acetona | 34.668 | -3.369
*/
/***************************** MQ Init ********************************************/
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ135.init();
/*
//If the RL value is different from 10K please assign your RL value with the following method:
MQ135.setRL(10);
*/
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
@ -77,21 +84,6 @@ void setup() {
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:
MQ135.setRL(10);
*/
/***************************** MQ Init ********************************************/
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ135.init();
/***************************** MQ Init ********************************************/
//Input: setup flag, if this function are on setup will print the headers (Optional - Default value: False)
//Output: print on serial port the information about sensor and sensor readings
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ135.serialDebug(true);
}

View File

@ -22,17 +22,18 @@
//Include the library
#include <MQUnifiedsensor.h>
/************************Hardware Related Macros************************************/
#define Board ("Arduino UNO")
#define Pin (A2) //Analog input 3 of your arduino
/***********************Software Related Macros************************************/
#define Type ("MQ-2") //MQ2
#define Voltage_Resolution (5)
#define ADC_Bit_Resolution (10) // For arduino UNO/MEGA/NANO
#define RatioMQ2CleanAir (9.83) //RS / R0 = 9.83 ppm
//Definitions
#define placa "Arduino UNO"
#define Voltage_Resolution 5
#define pin A0 //Analog input 0 of your arduino
#define type "MQ-2" //MQ2
#define ADC_Bit_Resolution 10 // For arduino UNO/MEGA/NANO
#define RatioMQ2CleanAir 9.83 //RS / R0 = 9.83 ppm
//Declare Sensor
MQUnifiedsensor MQ2(placa, Voltage_Resolution, ADC_Bit_Resolution, pin, type);
/*****************************Globals***********************************************/
MQUnifiedsensor MQ2(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin, Type);
/*****************************Globals***********************************************/
void setup() {
//Init the serial port communication - to debug the library
@ -51,6 +52,14 @@ void setup() {
Propane| 658.71 | -2.168
*/
/***************************** MQ Init ********************************************/
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ2.init();
/*
//If the RL value is different from 10K please assign your RL value with the following method:
MQ2.setRL(10);
*/
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
@ -72,20 +81,7 @@ void setup() {
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:
MQ2.setRL(10);
*/
/***************************** MQ Init ********************************************/
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ2.init();
/***************************** MQ Init ********************************************/
//Input: setup flag, if this function are on setup will print the headers (Optional - Default value: False)
//Output: print on serial port the information about sensor and sensor readings
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ2.serialDebug(true);
}

View File

@ -23,18 +23,17 @@
//Include the library
#include <MQUnifiedsensor.h>
//Definitions
#define placa "Arduino UNO"
#define Voltage_Resolution 5
#define pin A0 //Analog input 0 of your arduino
#define type "MQ-3" //MQ3
#define ADC_Bit_Resolution 10 // For arduino UNO/MEGA/NANO
#define RatioMQ3CleanAir 60 //RS / R0 = 60 ppm
//#define calibration_button 13 //Pin to calibrate your sensor
/************************Hardware Related Macros************************************/
#define Board ("Arduino UNO")
#define Pin (A3) //Analog input 3 of your arduino
/***********************Software Related Macros************************************/
#define Type ("MQ-3") //MQ3
#define Voltage_Resolution (5)
#define ADC_Bit_Resolution (10) // For arduino UNO/MEGA/NANO
#define RatioMQ3CleanAir (60) //RS / R0 = 60 ppm
/*****************************Globals***********************************************/
//Declare Sensor
MQUnifiedsensor MQ3(placa, Voltage_Resolution, ADC_Bit_Resolution, pin, type);
MQUnifiedsensor MQ3(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin, Type);
void setup() {
//Init the serial port communication - to debug the library
@ -54,7 +53,15 @@ void setup() {
Hexane | 7585.3 | -2.849
*/
/***************************** MQ Init ********************************************/
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ3.init();
/*
//If the RL value is different from 10K please assign your RL value with the following method:
MQ3.setRL(10);
*/
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
@ -76,21 +83,6 @@ void setup() {
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:
MQ3.setRL(10);
*/
/***************************** MQ Init ********************************************/
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ3.init();
/***************************** MQ Init ********************************************/
//Input: setup flag, if this function are on setup will print the headers (Optional - Default value: False)
//Output: print on serial port the information about sensor and sensor readings
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ3.serialDebug(true);
}

View File

@ -52,7 +52,14 @@ void setup() {
Ethanol | 3.4916 | -2.432
*/
/***************************** MQ Init ********************************************/
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ303.init();
/*
//If the RL value is different from 10K please assign your RL value with the following method:
MQ303.setRL(10);
*/
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
@ -74,21 +81,6 @@ void setup() {
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:
MQ303.setRL(10);
*/
/***************************** MQ Init ********************************************/
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ303.init();
/***************************** MQ Init ********************************************/
//Input: setup flag, if this function are on setup will print the headers (Optional - Default value: False)
//Output: print on serial port the information about sensor and sensor readings
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ303.serialDebug(true);
}

View File

@ -53,7 +53,14 @@ void setup() {
ALCOHOL | 473622 | -3.647
*/
/***************************** MQ Init ********************************************/
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ309.init();
/*
//If the RL value is different from 10K please assign your RL value with the following method:
MQ309.setRL(10);
*/
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
@ -75,21 +82,6 @@ void setup() {
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:
MQ309.setRL(10);
*/
/***************************** MQ Init ********************************************/
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ309.init();
/***************************** MQ Init ********************************************/
//Input: setup flag, if this function are on setup will print the headers (Optional - Default value: False)
//Output: print on serial port the information about sensor and sensor readings
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ309.serialDebug(true);
}

View File

@ -23,18 +23,17 @@
//Include the library
#include <MQUnifiedsensor.h>
//Definitions
#define placa "Arduino UNO"
#define Voltage_Resolution 5
#define pin A0 //Analog input 0 of your arduino
#define type "MQ-4" //MQ4
#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
/************************Hardware Related Macros************************************/
#define Board ("Arduino UNO")
#define Pin (A4) //Analog input 4 of your arduino
/***********************Software Related Macros************************************/
#define Type ("MQ-4") //MQ4
#define Voltage_Resolution (5)
#define ADC_Bit_Resolution (10) // For arduino UNO/MEGA/NANO
#define RatioMQ4CleanAir (4.4) //RS / R0 = 60 ppm
/*****************************Globals***********************************************/
//Declare Sensor
MQUnifiedsensor MQ4(placa, Voltage_Resolution, ADC_Bit_Resolution, pin, type);
MQUnifiedsensor MQ4(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin, Type);
void setup() {
//Init the serial port communication - to debug the library
@ -44,7 +43,14 @@ void setup() {
MQ4.setRegressionMethod(1); //_PPM = a*ratio^b
/***************************** MQ Init ********************************************/
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ4.init();
/*
//If the RL value is different from 10K please assign your RL value with the following method:
MQ4.setRL(10);
*/
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
@ -67,18 +73,6 @@ void setup() {
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:
MQ4.setRL(10);
*/
/***************************** MQ Init ********************************************/
//Input: setup flag, if this function are on setup will print the headers (Optional - Default value: False)
//Output: print on serial port the information about sensor and sensor readings
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ4.init();
Serial.println("*************** Lectures from MQ-4 **********************");
Serial.println("| LPG | CH4 | CO | Alcohol | Smoke |");
}

View File

@ -23,18 +23,17 @@
//Include the library
#include <MQUnifiedsensor.h>
//Definitions
#define placa "Arduino UNO"
#define Voltage_Resolution 5
#define pin A4 //Analog input 4 of your arduino
#define type "MQ-4" //MQ4
#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
/************************Hardware Related Macros************************************/
#define Board ("Arduino UNO")
#define Pin (A4) //Analog input 4 of your arduino
/***********************Software Related Macros************************************/
#define Type ("MQ-4") //MQ4
#define Voltage_Resolution (5)
#define ADC_Bit_Resolution (10) // For arduino UNO/MEGA/NANO
#define RatioMQ4CleanAir (4.4) //RS / R0 = 60 ppm
/*****************************Globals***********************************************/
//Declare Sensor
MQUnifiedsensor MQ4(placa, Voltage_Resolution, ADC_Bit_Resolution, pin, type);
MQUnifiedsensor MQ4(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin, Type);
void setup() {
//Init the serial port communication - to debug the library
@ -43,8 +42,14 @@ void setup() {
//Set math model to calculate the PPM concentration and the value of constants
MQ4.setRegressionMethod(0); //_PPM = pow(10, (log10(ratio)-b)/a)
/***************************** MQ Init ********************************************/
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ4.init();
/*
//If the RL value is different from 10K please assign your RL value with the following method:
MQ4.setRL(10);
*/
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
@ -67,18 +72,6 @@ void setup() {
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:
MQ4.setRL(10);
*/
/***************************** MQ Init ********************************************/
//Input: setup flag, if this function are on setup will print the headers (Optional - Default value: False)
//Output: print on serial port the information about sensor and sensor readings
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ4.init();
Serial.println("** Lectures from MQ-4**********");
Serial.println("| LPG |");
}

View File

@ -23,18 +23,17 @@
//Include the library
#include <MQUnifiedsensor.h>
//Definitions
#define placa "Arduino UNO"
#define Voltage_Resolution 5
#define pin A0 //Analog input 0 of your arduino
#define type "MQ-4" //MQ4
#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
/************************Hardware Related Macros************************************/
#define Board ("Arduino UNO")
#define Pin (A4) //Analog input 4 of your arduino
/***********************Software Related Macros************************************/
#define Type ("MQ-4") //MQ4
#define Voltage_Resolution (5)
#define ADC_Bit_Resolution (10) // For arduino UNO/MEGA/NANO
#define RatioMQ4CleanAir (4.4) //RS / R0 = 60 ppm
/*****************************Globals***********************************************/
//Declare Sensor
MQUnifiedsensor MQ4(placa, Voltage_Resolution, ADC_Bit_Resolution, pin, type);
MQUnifiedsensor MQ4(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin, Type);
void setup() {
//Init the serial port communication - to debug the library
@ -54,7 +53,14 @@ void setup() {
*/
/***************************** MQ Init ********************************************/
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ4.init();
/*
//If the RL value is different from 10K please assign your RL value with the following method:
MQ4.setRL(10);
*/
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
@ -76,21 +82,6 @@ void setup() {
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:
MQ4.setRL(10);
*/
/***************************** MQ Init ********************************************/
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ4.init();
/***************************** MQ Init ********************************************/
//Input: setup flag, if this function are on setup will print the headers (Optional - Default value: False)
//Output: print on serial port the information about sensor and sensor readings
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ4.serialDebug(true);
}

View File

@ -53,7 +53,14 @@ void setup() {
Alcohol| 97124 | -4.918
*/
/***************************** MQ Init ********************************************/
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ5.init();
/*
//If the RL value is different from 10K please assign your RL value with the following method:
MQ5.setRL(10);
*/
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
@ -75,21 +82,6 @@ void setup() {
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:
MQ5.setRL(10);
*/
/***************************** MQ Init ********************************************/
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ5.init();
/***************************** MQ Init ********************************************/
//Input: setup flag, if this function are on setup will print the headers (Optional - Default value: False)
//Output: print on serial port the information about sensor and sensor readings
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ5.serialDebug(true);
}

View File

@ -53,7 +53,14 @@ void setup() {
Alcohol | 50000000 | -6.017
*/
/***************************** MQ Init ********************************************/
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ6.init();
/*
//If the RL value is different from 10K please assign your RL value with the following method:
MQ6.setRL(10);
*/
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
@ -75,20 +82,6 @@ void setup() {
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:
MQ6.setRL(10);
*/
/***************************** MQ Init ********************************************/
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ6.init();
/***************************** MQ Init ********************************************/
//Input: setup flag, if this function are on setup will print the headers (Optional - Default value: False)
//Output: print on serial port the information about sensor and sensor readings
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ6.serialDebug(true);
}

View File

@ -54,7 +54,14 @@ void setup() {
Alcohol | 40000000000000000 | -12.35
*/
/***************************** MQ Init ********************************************/
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ7.init();
/*
//If the RL value is different from 10K please assign your RL value with the following method:
MQ7.setRL(10);
*/
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
@ -76,21 +83,6 @@ void setup() {
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:
MQ7.setRL(10);
*/
/***************************** MQ Init ********************************************/
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ7.init();
/***************************** MQ Init ********************************************/
//Input: setup flag, if this function are on setup will print the headers (Optional - Default value: False)
//Output: print on serial port the information about sensor and sensor readings
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ7.serialDebug(true);
}

View File

@ -54,7 +54,14 @@ void setup() {
Alcohol | 76101 | -1.86
*/
/***************************** MQ Init ********************************************/
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ8.init();
/*
//If the RL value is different from 10K please assign your RL value with the following method:
MQ8.setRL(10);
*/
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
@ -76,20 +83,6 @@ void setup() {
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:
MQ8.setRL(10);
*/
/***************************** MQ Init ********************************************/
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ8.init();
/***************************** MQ Init ********************************************/
//Input: setup flag, if this function are on setup will print the headers (Optional - Default value: False)
//Output: print on serial port the information about sensor and sensor readings
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ8.serialDebug(true);
}

View File

@ -23,18 +23,17 @@
//Include the library
#include <MQUnifiedsensor.h>
//Definitions
#define placa "Arduino UNO"
#define Voltage_Resolution 5
#define pin A0 //Analog input 0 of your arduino
#define type "MQ-9" //MQ9
#define ADC_Bit_Resolution 10 // For arduino UNO/MEGA/NANO
#define RatioMQ9CleanAir 9.6 //RS / R0 = 9.6 ppm
//#define calibration_button 13 //Pin to calibrate your sensor
/************************Hardware Related Macros************************************/
#define Board ("Arduino UNO")
#define Pin (A9) //Analog input 4 of your arduino
/***********************Software Related Macros************************************/
#define Type ("MQ-9") //MQ9
#define Voltage_Resolution (5)
#define ADC_Bit_Resolution (10) // For arduino UNO/MEGA/NANO
#define RatioMQ9CleanAir (9.6) //RS / R0 = 60 ppm
/*****************************Globals***********************************************/
//Declare Sensor
MQUnifiedsensor MQ9(placa, Voltage_Resolution, ADC_Bit_Resolution, pin, type);
MQUnifiedsensor MQ9(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin, Type);
void setup() {
//Init the serial port communication - to debug the library
@ -44,6 +43,14 @@ void setup() {
MQ9.setRegressionMethod(1); //_PPM = a*ratio^b
/***************************** MQ Init ********************************************/
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ9.init();
/*
//If the RL value is different from 10K please assign your RL value with the following method:
MQ9.setRL(10);
*/
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
@ -65,19 +72,6 @@ void setup() {
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:
MQ9.setRL(10);
*/
/***************************** MQ Init ********************************************/
//Input: setup flag, if this function are on setup will print the headers (Optional - Default value: False)
//Output: print on serial port the information about sensor and sensor readings
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ9.init();
Serial.println("** Lectures from MQ-9 ****");
Serial.println("| LPG | CH4 | CO |");
}

View File

@ -23,18 +23,17 @@
//Include the library
#include <MQUnifiedsensor.h>
//Definitions
#define placa "Arduino UNO"
#define Voltage_Resolution 5
#define pin A0 //Analog input 0 of your arduino
#define type "MQ-9" //MQ9
#define ADC_Bit_Resolution 10 // For arduino UNO/MEGA/NANO
#define RatioMQ9CleanAir 9.6 //RS / R0 = 9.6 ppm
//#define calibration_button 13 //Pin to calibrate your sensor
/************************Hardware Related Macros************************************/
#define Board ("Arduino UNO")
#define Pin (A9) //Analog input 4 of your arduino
/***********************Software Related Macros************************************/
#define Type ("MQ-9") //MQ9
#define Voltage_Resolution (5)
#define ADC_Bit_Resolution (10) // For arduino UNO/MEGA/NANO
#define RatioMQ9CleanAir (9.6) //RS / R0 = 60 ppm
/*****************************Globals***********************************************/
//Declare Sensor
MQUnifiedsensor MQ9(placa, Voltage_Resolution, ADC_Bit_Resolution, pin, type);
MQUnifiedsensor MQ9(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin, Type);
void setup() {
//Init the serial port communication - to debug the library
@ -51,8 +50,15 @@ void setup() {
CH4 | 4269.6 | -2.648
CO | 599.65 | -2.244
*/
/***************************** MQ Init ********************************************/
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ9.init();
/*
//If the RL value is different from 10K please assign your RL value with the following method:
MQ9.setRL(10);
*/
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
@ -74,21 +80,6 @@ void setup() {
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:
MQ9.setRL(10);
*/
/***************************** MQ Init ********************************************/
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ9.init();
/***************************** MQ Init ********************************************/
//Input: setup flag, if this function are on setup will print the headers (Optional - Default value: False)
//Output: print on serial port the information about sensor and sensor readings
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ9.serialDebug(true);
}

View File

@ -19,39 +19,38 @@
//Include the library
#include <MQUnifiedsensor.h>
//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
/************************Hardware Related Macros************************************/
#define Board ("Arduino Mega")
#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
/***********************Software Related Macros************************************/
#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 ADC_Bit_Resolution (10) // 10 bit ADC
#define Voltage_Resolution (5) // Volt resolution to calc the voltage
#define Type ("Arduino Mega 2560") //Board used
/*****************************Globals***********************************************/
//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);
MQUnifiedsensor MQ2(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin2, Type);
MQUnifiedsensor MQ3(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin3, Type);
MQUnifiedsensor MQ4(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin4, Type);
MQUnifiedsensor MQ5(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin5, Type);
MQUnifiedsensor MQ6(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin6, Type);
MQUnifiedsensor MQ7(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin7, Type);
MQUnifiedsensor MQ8(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin8, Type);
MQUnifiedsensor MQ9(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin9, Type);
void setup() {
//Init serial port
@ -178,28 +177,6 @@ void loop() {
MQ7.update();
MQ8.update();
MQ9.update();
/*
//Rutina de calibracion - Uncomment if you need (setup too and header)
if(calibration_button)
{
float R0 = MQ2.calibrate();
MQ2.setR0(R0):
R0 = MQ3.calibrate();
MQ3.setR0(R0):
R0 = MQ4.calibrate();
MQ4.setR0(R0):
R0 = MQ5.calibrate();
MQ5.setR0(R0):
R0 = MQ6.calibrate();
MQ6.setR0(R0):
R0 = MQ7.calibrate();
MQ7.setR0(R0):
R0 = MQ8.calibrate();
MQ8.setR0(R0):
R0 = MQ9.calibrate();
MQ9.setR0(R0):
}
*/
//Read the sensor and print in serial port
float MQ2Lecture = MQ2.readSensor();
float MQ3Lecture = MQ3.readSensor();

View File

@ -18,6 +18,8 @@
Please take care, arduino A0 pin represent the analog input configured on #define pin - For this example this doesn't matter
You will connect your sensor to your external A2D Sensor
This example code is in the public domain.
Important:
1. Although it doesn't matter what pin you put in when initializing your MQ sensor function it is important that you don't
for any reason invoke the MQ.init() method because that method configures the selected pin as input and you may need it for
@ -27,10 +29,6 @@
3. You must ensure that when invoking the setADC(value) method the value you are passing is within the expected parameters,
for example if it is a 10-bit ADC converter, we expect a value between 0 and 2^10 = 1024
This example code is in the public domain.
*/
//Include the library
@ -67,6 +65,11 @@ void setup() {
*/
/*
//If the RL value is different from 10K please assign your RL value with the following method:
MQ3.setRL(10);
*/
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
@ -90,11 +93,6 @@ void setup() {
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:
MQ3.setRL(10);
*/
MQ3.serialDebug(true);
}

View File

@ -51,7 +51,10 @@ void setup() {
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ4.init();
/*
//If the RL value is different from 10K please assign your RL value with the following method:
MQ4.setRL(10);
*/
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
@ -73,12 +76,6 @@ void setup() {
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:
MQ4.setRL(10);
*/
MQ4.serialDebug(true);
}

View File

@ -1,6 +1,6 @@
name=MQUnifiedsensor
version=1.10
author= Miguel Califa <miguelangel5612@gmail.com>, Yersson Carrillo, Ghiordy Contreras
version=2.0.1
author= Miguel Califa <miguelangel5612@gmail.com>, Yersson Carrillo<miguelangel5612@gmail.com>, Ghiordy Contreras<miguelangel5612@gmail.com>
maintainer= Miguel Califa <miguelangel5612@gmail.com>
sentence= This library allows you to read the MQ sensors very easily.
paragraph= This library allows an Arduino/Genuino/ESP8266 board to read MQ Sensors (AIr quality meter) references: MQ2, MQ3, MQ4, MQ5, MQ6, MQ7, MQ8, MQ9, MQ131, MQ135, MQ303A, MQ309A.

View File

@ -27,7 +27,7 @@ void MQUnifiedsensor::setRL(float RL) {
}
void MQUnifiedsensor::setADC(int value)
{
this-> _sensor_volt = (value) * _VOLT_RESOLUTION / (pow(2, ADC_RESOLUTION) - 1);
this-> _sensor_volt = (value) * _VOLT_RESOLUTION / ((pow(2, _ADC_Bit_Resolution)) - 1);
this-> _adc = value;
}
void MQUnifiedsensor::setVoltResolution(float voltage_resolution)
@ -80,7 +80,7 @@ void MQUnifiedsensor::serialDebug(bool onSetup)
Serial.print("R0: "); Serial.print(_R0); Serial.println("");
Serial.print("RL: "); Serial.print(_RL); Serial.println("");
Serial.print("Model: "); if(_regressionMethod == "Exponential") Serial.println("Exponential"); else Serial.println("Linear");
Serial.print("Model: "); if(_regressionMethod == 1) Serial.println("Exponential"); else Serial.println("Linear");
Serial.print(_type); Serial.print(" -> a: "); Serial.print(_a); Serial.print(" | b: "); Serial.println(_b);
Serial.print("Development board: "); Serial.println(_placa);
@ -95,7 +95,7 @@ void MQUnifiedsensor::serialDebug(bool onSetup)
}
else
{
Serial.print("|"); Serial.print(_adc); Serial.print("| v = ADC*"); Serial.print(_VOLT_RESOLUTION); Serial.print("/"); Serial.print(pow(2, _ADC_Bit_Resolution)); Serial.print(" | "); Serial.print(_sensor_volt);
Serial.print("|"); Serial.print(_adc); Serial.print("| v = ADC*"); Serial.print(_VOLT_RESOLUTION); Serial.print("/"); Serial.print((pow(2, _ADC_Bit_Resolution)) - 1); Serial.print(" | "); Serial.print(_sensor_volt);
Serial.print(" | RS = ((" ); Serial.print(_VOLT_RESOLUTION ); Serial.print("*RL)/Voltage) - RL| "); Serial.print(_RS_Calc); Serial.print(" | Ratio = RS/R0| ");
Serial.print(_ratio); Serial.print( " | ");
if(_regressionMethod == 1) Serial.print("ratio*a + b");
@ -174,7 +174,7 @@ float MQUnifiedsensor::getVoltage(int read) {
avg += _adc;
delay(retry_interval);
}
voltage = (avg/ retries) * _VOLT_RESOLUTION / (pow(2, ADC_RESOLUTION) - 1);
voltage = (avg/ retries) * _VOLT_RESOLUTION / ((pow(2, _ADC_Bit_Resolution)) - 1);
}
else
{