mirror of
https://github.com/miguel5612/MQSensorsLib.git
synced 2025-07-03 10:51:03 +03:00
Compare commits
32 Commits
Author | SHA1 | Date | |
---|---|---|---|
688827ffb4 | |||
b9a5e62899 | |||
a906388c5c | |||
948afddf0d | |||
090de8f9e0 | |||
5053b10498 | |||
8a87cce57e | |||
972c79578e | |||
4246716355 | |||
1fe32c4b6e | |||
39b4449899 | |||
edd573ba0f | |||
6ecc769676 | |||
e07c4b7f71 | |||
952a456a35 | |||
ff0cb0562a | |||
f8d1bcbc76 | |||
7c3cd5793c | |||
38f93037ce | |||
b9ba249140 | |||
a7554fa8dd | |||
f93b5128ce | |||
1a14e12450 | |||
9bfea58092 | |||
555e49d31e | |||
d0b00b4025 | |||
f83e0fb0d7 | |||
65a1246e51 | |||
28ce4c80f7 | |||
9497574e11 | |||
9cbc753758 | |||
c7b67d7fa5 |
49
.github/pull_request_template.md
vendored
Normal file
49
.github/pull_request_template.md
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
# Description
|
||||
|
||||
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.
|
||||
|
||||
Fixes # (issue)
|
||||
|
||||
## Type of change
|
||||
|
||||
Please delete options that are not relevant.
|
||||
|
||||
- [ ] Bug fix (non-breaking change which fixes an issue)
|
||||
- [ ] New feature (non-breaking change which adds functionality)
|
||||
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
|
||||
- [ ] This change requires a documentation update
|
||||
|
||||
# How Has This Been Tested?
|
||||
|
||||
Please describe the examples that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
|
||||
|
||||
- [ ] MQ-3
|
||||
- [ ] MQ-4
|
||||
- [ ] MQ-5
|
||||
- [ ] MQ-6
|
||||
- [ ] MQ-7
|
||||
- [ ] MQ-8
|
||||
- [ ] MQ-9
|
||||
- [ ] MQ-131
|
||||
- [ ] MQ-135
|
||||
- [ ] MQ-303
|
||||
- [ ] MQ-309
|
||||
- [ ] ESP8266
|
||||
- [ ] ESP-32
|
||||
|
||||
**Test Configuration**:
|
||||
* Board:
|
||||
* Software (Version of your arduino):
|
||||
* Result (Good - Medium - Bad):
|
||||
* Your Comments:
|
||||
|
||||
# Checklist:
|
||||
|
||||
- [ ] My code follows the style guidelines of this project
|
||||
- [ ] I have performed a self-review of my own code
|
||||
- [ ] I have commented my code, particularly in hard-to-understand areas
|
||||
- [ ] I have made corresponding changes to the documentation
|
||||
- [ ] My changes generate no new warnings
|
||||
- [ ] I have added tests that prove my fix is effective or that my feature works
|
||||
- [ ] New and existing unit tests pass locally with my changes
|
||||
- [ ] Any dependent changes have been merged and published in downstream modules
|
129
README.md
129
README.md
@ -1,45 +1,121 @@
|
||||
<!-- 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
|
||||
-->
|
||||
[](https://zenodo.org/badge/latestdoi/170540207)
|
||||

|
||||
![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.
|
||||
We present a unified library for MQ sensors, this library allows to read MQ signals easily from Arduino, Genuino, ESP8266, ESP-32 boards whose references are MQ2, MQ3, MQ4, MQ5, MQ6, MQ7, MQ8, MQ9, MQ131, MQ135, MQ303A, MQ309A.
|
||||
|
||||
<!-- TABLE OF CONTENTS -->
|
||||
## Table of Contents
|
||||
|
||||
* [Getting Started](#Getting-Started)
|
||||
* [Wiring](#Wiring)
|
||||
* [Sensor](#Sensor)
|
||||
* [Arduino](#Arduino)
|
||||
* [ESP8266 or ESP-32](#ESP8266-ESP32)
|
||||
* [User Manual](#Manuals)
|
||||
* [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
|
||||

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

|
||||
### Arduino
|
||||

|
||||
|
||||
### ESP8266
|
||||
#### MQ-7 / MQ-309A
|
||||
** Note ** [issue](https://github.com/miguel5612/MQSensorsLib/issues/26): MQ-7 and MQ-309 needs two different voltages for heater, they can be supplied by PWM and DC Signal controlled by your controller, another option is to use two different power sources, you should use the best option for you, next i will show the PWM option and on the examples this will be the way .
|
||||

|
||||
### ESP8266-ESP32
|
||||

|
||||
|
||||
### User Manual New!! 12.2019
|
||||
### Manuals
|
||||
#### 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:
|
||||
|
||||

|
||||
|
||||
**Note**:
|
||||
*  `Yellow -> Calibration status.`
|
||||
*  `Green -> Hardware and software characteristics.`
|
||||
*  `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 +181,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 +234,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
|
||||
|
@ -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() {
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -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
93
examples/ESP32/esp32.ino
Normal 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
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,8 @@
|
||||
https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/static/img/MQ_Arduino.PNG
|
||||
Please take care, arduino A0 pin represent the analog input configured on #define pin
|
||||
|
||||
Note: high concentration MQ-131 sensor.
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
*/
|
||||
@ -52,7 +54,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,27 +84,13 @@ 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);
|
||||
Serial.println("Ignore Ratio = RS/R0, for this example we will use readSensorR0Rs, the ratio calculated will be R0/Rs. Thanks :)");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
MQ131.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ131.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
MQ131.readSensorR0Rs(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
MQ131.serialDebug(); // Will print the table on the serial port
|
||||
delay(500); //Sampling frequency
|
||||
}
|
@ -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 |");
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -31,14 +31,16 @@
|
||||
#define type "MQ-309" //MQ309
|
||||
#define ADC_Bit_Resolution 10 // For arduino UNO/MEGA/NANO
|
||||
#define RatioMQ309CleanAir 11 //RS / R0 = 11 ppm
|
||||
//#define calibration_button 13 //Pin to calibrate your sensor
|
||||
#define PWMPin 5 // Pin connected to mosfet
|
||||
|
||||
//Declare Sensor
|
||||
MQUnifiedsensor MQ309(placa, Voltage_Resolution, ADC_Bit_Resolution, pin, type);
|
||||
unsigned long oldTime = 0;
|
||||
|
||||
void setup() {
|
||||
//Init the serial port communication - to debug the library
|
||||
Serial.begin(9600); //Init serial port
|
||||
pinMode(PWMPin, OUTPUT);
|
||||
|
||||
//Set math model to calculate the PPM concentration and the value of constants
|
||||
MQ309.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
@ -53,7 +55,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,27 +84,32 @@ 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);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
MQ309.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ309.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
MQ309.serialDebug(); // Will print the table on the serial port
|
||||
delay(500); //Sampling frequency
|
||||
// 60s cycle
|
||||
oldTime = millis();
|
||||
while(millis() - oldTime <= (30*1000))
|
||||
{
|
||||
// VH 0.9 Volts
|
||||
analogWrite(5, 2); // 255 is 100%, 2.295 is aprox 0.9% of Duty cycle for 60s
|
||||
MQ309.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ309.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
MQ309.serialDebug(); // Will print the table on the serial port
|
||||
delay(500); //Sampling frequency
|
||||
}
|
||||
|
||||
// 90s cycle
|
||||
oldTime = millis();
|
||||
while(millis() - oldTime <= (120*1000))
|
||||
{
|
||||
// VL 0.2 Volts
|
||||
analogWrite(5, 1); // 255 is 100%, 0.51 is aprox 0.2% of Duty cycle for 120s
|
||||
MQ309.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ309.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
MQ309.serialDebug(); // Will print the table on the serial port
|
||||
delay(500); //Sampling frequency
|
||||
}
|
||||
// Total: 30 + 120s = 2.5 minutes.
|
||||
}
|
@ -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 |");
|
||||
}
|
||||
|
@ -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 |");
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,10 @@
|
||||
modified 26 March 2020
|
||||
by Miguel Califa
|
||||
|
||||
Updated example of MQ-7 AND MQ-309A
|
||||
modified 20 April 2020
|
||||
by Miguel Califa
|
||||
|
||||
Wiring:
|
||||
https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/static/img/MQ_Arduino.PNG
|
||||
Please take care, arduino A0 pin represent the analog input configured on #define pin
|
||||
@ -31,14 +35,16 @@
|
||||
#define type "MQ-7" //MQ7
|
||||
#define ADC_Bit_Resolution 10 // For arduino UNO/MEGA/NANO
|
||||
#define RatioMQ7CleanAir 27.5 //RS / R0 = 27.5 ppm
|
||||
//#define calibration_button 13 //Pin to calibrate your sensor
|
||||
#define PWMPin 5 // Pin connected to mosfet
|
||||
|
||||
//Declare Sensor
|
||||
MQUnifiedsensor MQ7(placa, Voltage_Resolution, ADC_Bit_Resolution, pin, type);
|
||||
unsigned long oldTime = 0;
|
||||
|
||||
void setup() {
|
||||
//Init the serial port communication - to debug the library
|
||||
Serial.begin(9600); //Init serial port
|
||||
pinMode(PWMPin, OUTPUT);
|
||||
|
||||
//Set math model to calculate the PPM concentration and the value of constants
|
||||
MQ7.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
@ -54,7 +60,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,27 +89,32 @@ 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);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
MQ7.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ7.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
MQ7.serialDebug(); // Will print the table on the serial port
|
||||
delay(500); //Sampling frequency
|
||||
// 60s cycle
|
||||
oldTime = millis();
|
||||
while(millis() - oldTime <= (60*1000))
|
||||
{
|
||||
// VH 5 Volts
|
||||
analogWrite(5, 255); // 255 is DC 5V output
|
||||
MQ7.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ7.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
MQ7.serialDebug(); // Will print the table on the serial port
|
||||
delay(500); //Sampling frequency
|
||||
}
|
||||
|
||||
// 90s cycle
|
||||
oldTime = millis();
|
||||
while(millis() - oldTime <= (90*1000))
|
||||
{
|
||||
// VH 1.4 Volts
|
||||
analogWrite(5, 20); // 255 is 100%, 20.4 is aprox 8% of Duty cycle for 90s
|
||||
MQ7.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ7.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
MQ7.serialDebug(); // Will print the table on the serial port
|
||||
delay(500); //Sampling frequency
|
||||
}
|
||||
// Total: 60 + 90s = 2.5 minutes.
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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 |");
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -19,39 +19,41 @@
|
||||
|
||||
//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
|
||||
#define PWMPin (5) // Pin connected to mosfet
|
||||
/***********************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);
|
||||
|
||||
unsigned long oldTime = 0;
|
||||
|
||||
void setup() {
|
||||
//Init serial port
|
||||
@ -169,6 +171,27 @@ void setup() {
|
||||
}
|
||||
|
||||
void loop() {
|
||||
oldTime = millis();
|
||||
while(millis() - oldTime <= (60*1000))
|
||||
{
|
||||
// VH 5 Volts
|
||||
analogWrite(5, 255); // 255 is DC 5V output
|
||||
readAllSensors();
|
||||
delay(500);
|
||||
}
|
||||
// 90s cycle
|
||||
oldTime = millis();
|
||||
while(millis() - oldTime <= (90*1000))
|
||||
{
|
||||
// VH 1.4 Volts
|
||||
analogWrite(5, 20); // 255 is 100%, 20.4 is aprox 8% of Duty cycle for 90s
|
||||
readAllSensors();
|
||||
delay(500);
|
||||
}
|
||||
}
|
||||
|
||||
void readAllSensors()
|
||||
{
|
||||
//Update the voltage lectures
|
||||
MQ2.update();
|
||||
MQ3.update();
|
||||
@ -178,28 +201,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();
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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(" KΩ");
|
||||
Serial.print("RL: "); Serial.print(_RL); Serial.println(" KΩ");
|
||||
|
||||
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");
|
||||
@ -143,6 +143,24 @@ float MQUnifiedsensor::readSensor()
|
||||
//if(_PPM > 10000) _PPM = 99999999; //No negative values accepted or upper datasheet recomendation.
|
||||
return _PPM;
|
||||
}
|
||||
float MQUnifiedsensor::readSensorR0Rs()
|
||||
{
|
||||
//More explained in: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||
_RS_Calc = ((_VOLT_RESOLUTION*_RL)/_sensor_volt)-_RL; //Get value of RS in a gas
|
||||
if(_RS_Calc < 0) _RS_Calc = 0; //No negative values accepted.
|
||||
_ratio = this->_R0/_RS_Calc; // Get ratio RS_air/RS_gas <- INVERTED for MQ-131 issue 28 https://github.com/miguel5612/MQSensorsLib/issues/28
|
||||
if(_ratio <= 0) _ratio = 0; //No negative values accepted or upper datasheet recomendation.
|
||||
if(_regressionMethod == 1) _PPM= _a*pow(_ratio, _b); // <- Source excel analisis https://github.com/miguel5612/MQSensorsLib_Docs/tree/master/Internal_design_documents
|
||||
else
|
||||
{
|
||||
// https://jayconsystems.com/blog/understanding-a-gas-sensor <- Source of linear ecuation
|
||||
double ppm_log = (log10(_ratio)-_b)/_a; //Get ppm value in linear scale according to the the ratio value
|
||||
_PPM = pow(10, ppm_log); //Convert ppm value to log scale
|
||||
}
|
||||
if(_PPM < 0) _PPM = 0; //No negative values accepted or upper datasheet recomendation.
|
||||
//if(_PPM > 10000) _PPM = 99999999; //No negative values accepted or upper datasheet recomendation.
|
||||
return _PPM;
|
||||
}
|
||||
float MQUnifiedsensor::calibrate(float ratioInCleanAir) {
|
||||
//More explained in: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||
/*
|
||||
@ -174,7 +192,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
|
||||
{
|
||||
|
@ -30,6 +30,7 @@ class MQUnifiedsensor
|
||||
//user functions
|
||||
float calibrate(float ratioInCleanAir);
|
||||
float readSensor();
|
||||
float readSensorR0Rs();
|
||||
float validateEcuation(float ratioInput = 0);
|
||||
|
||||
//get function for info
|
||||
|
Reference in New Issue
Block a user