mirror of
https://github.com/miguel5612/MQSensorsLib.git
synced 2025-03-14 21:07:36 +03:00
Compare commits
38 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
c927504bf5 | ||
![]() |
337d962862 | ||
![]() |
f7f2c1f3f4 | ||
![]() |
1c131eed65 | ||
![]() |
b6bff185f3 | ||
![]() |
a7e89570fd | ||
![]() |
35180270ac | ||
![]() |
52bccfbff1 | ||
![]() |
3368613dd7 | ||
![]() |
9f41530cda | ||
![]() |
e862774fe0 | ||
![]() |
27465dfb99 | ||
![]() |
e3f5e2ec0c | ||
![]() |
6a035cc5d0 | ||
![]() |
80025e8398 | ||
![]() |
d3241a1e2f | ||
![]() |
4b71c626b0 | ||
![]() |
07b6948f76 | ||
![]() |
990e6878ef | ||
![]() |
6322e9c03d | ||
![]() |
964204706f | ||
![]() |
1f8310a6e7 | ||
![]() |
700d367d93 | ||
![]() |
4be0a40997 | ||
![]() |
6aa78fd575 | ||
![]() |
c934152cd7 | ||
![]() |
525a09644b | ||
![]() |
16affe479f | ||
![]() |
4a3d46f47e | ||
![]() |
bf6d90db69 | ||
![]() |
1818c3cf1a | ||
![]() |
874be50106 | ||
![]() |
71c0d82314 | ||
![]() |
11bef492e5 | ||
![]() |
728450025a | ||
![]() |
a059971123 | ||
![]() |
e9425f7047 | ||
![]() |
beab80c403 |
2
.github/pull_request_template.md
vendored
2
.github/pull_request_template.md
vendored
@ -12,6 +12,8 @@ Please delete options that are not relevant.
|
||||
- [ ] 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
|
||||
- [ ] I have updated the version in `library.properties` to reflect my changes (advance by 0.01 for minor changes, or a whole number for new features)
|
||||
- [ ] I have submitted the pull request
|
||||
|
||||
# How Has This Been Tested?
|
||||
|
||||
|
@ -20,3 +20,7 @@ Pull request will be check by three main authors who are linked in
|
||||
[REAMDE.md](https://github.com/miguel5612/MQSensorsLib/README.md) and they determine to merge to
|
||||
master branch. Later than assessment and debbuging procedures was completed, the contribution
|
||||
will be released.
|
||||
|
||||
## Versioning
|
||||
|
||||
When making a pull request, please remember to update the `library.properties` file to reflect the changes you've made. If your change is minor, consider advancing the version by 0.01. If you're adding a new feature, you may want to advance the version by a whole number.
|
34
README.md
34
README.md
@ -31,6 +31,7 @@ We present a unified library for MQ sensors, this library allows to read MQ sign
|
||||
* [Sensor manufacturers](#Sensor-manufacturers)
|
||||
* [Contributing](#Contributing)
|
||||
* [Authors](#Authors)
|
||||
* [Be a sponsor 💖](#Sponsor)
|
||||
|
||||
## Getting Started
|
||||
|
||||
@ -50,7 +51,7 @@ We present a unified library for MQ sensors, this library allows to read MQ sign
|
||||
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.setA(1012.7); MQ4.setB(-2.786); // Configure the equation to to calculate CH4 concentration
|
||||
MQ4.setR0(3.86018237); // Value getted on calibration
|
||||
// Loop
|
||||
MQ4.init();
|
||||
@ -81,13 +82,15 @@ float ppmCH4 = MQ4.readSensor();
|
||||
### ESP8266-ESP32
|
||||

|
||||
|
||||
### ESP32 WROOM 32D
|
||||
The ESP32 WROOM 32D does not need an external power supply. A0 goes to PIN36, Vcc to 3v3 and GND to any GND port on the board. Check the **ESP2/ESP32_WROOM_32** folder to fixing the measuring issue when connecting to wifi.
|
||||
|
||||
### 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)
|
||||
|
||||
|
||||
### Serial debug (optional)
|
||||
If your sensor is an **MQ2** (Same for others sensors):
|
||||
* To enable on setup wrote
|
||||
@ -118,16 +121,17 @@ You'll need Arduino desktop app 1.8.9 or later.
|
||||
### Sensor manufacturers:
|
||||
| Sensor | Manufacture | URL Datasheet |
|
||||
|----------|----------|----------|
|
||||
| MQ-2 | Pololulu| [datasheet](https://www.pololu.com/file/0J309/MQ2.pdf) |
|
||||
| MQ-3 | Sparkfun | [datasheet](https://www.sparkfun.com/datasheets/Sensors/MQ-3.pdf) |
|
||||
| MQ-4 | Sparkfun | [datasheet](https://www.sparkfun.com/datasheets/Sensors/Biometric/MQ-4.pdf) |
|
||||
| MQ-5 | parallax | [datasheet](https://www.parallax.com/sites/default/files/downloads/605-00009-MQ-5-Datasheet.pdf) |
|
||||
| MQ-6 | Sparkfun | [datasheet](https://www.sparkfun.com/datasheets/Sensors/Biometric/MQ-6.pdf) |
|
||||
| MQ-7 | Sparkfun | [datasheet](https://www.sparkfun.com/datasheets/Sensors/Biometric/MQ-7.pdf) |
|
||||
| MQ-8 | Sparkfun | [datasheet](https://dlnmh9ip6v2uc.cloudfront.net/datasheets/Sensors/Biometric/MQ-8.pdf) |
|
||||
| MQ-9 | Haoyuelectronics | [datasheet](http://www.haoyuelectronics.com/Attachment/MQ-9/MQ9.pdf) |
|
||||
| MQ-131 | Sensorsportal | [datasheet](http://www.sensorsportal.com/DOWNLOADS/MQ131.pdf) |
|
||||
| MQ-2 | HANWEI Electronics| [datasheet](https://www.pololu.com/file/0J309/MQ2.pdf) |
|
||||
| MQ-3 | HANWEI Electronics | [datasheet](https://www.sparkfun.com/datasheets/Sensors/MQ-3.pdf) |
|
||||
| MQ-4 | HANWEI Electronics | [datasheet](https://www.sparkfun.com/datasheets/Sensors/Biometric/MQ-4.pdf) |
|
||||
| MQ-5 | HANWEI Electronics | [datasheet](https://www.parallax.com/sites/default/files/downloads/605-00009-MQ-5-Datasheet.pdf) |
|
||||
| MQ-6 | HANWEI Electronics | [datasheet](https://www.sparkfun.com/datasheets/Sensors/Biometric/MQ-6.pdf) |
|
||||
| MQ-7 | HANWEI Electronics | [datasheet](https://www.sparkfun.com/datasheets/Sensors/Biometric/MQ-7.pdf) |
|
||||
| MQ-8 | HANWEI Electronics | [datasheet](https://dlnmh9ip6v2uc.cloudfront.net/datasheets/Sensors/Biometric/MQ-8.pdf) |
|
||||
| MQ-9 | HANWEI Electronics | [datasheet](http://www.haoyuelectronics.com/Attachment/MQ-9/MQ9.pdf) |
|
||||
| MQ-131 | HANWEI Electronics | [datasheet](http://www.sensorsportal.com/DOWNLOADS/MQ131.pdf) |
|
||||
| MQ-135 | HANWEI Electronics | [datasheet](https://www.electronicoscaldas.com/datasheet/MQ-135_Hanwei.pdf) |
|
||||
| MQ-136 | HANWEI Electronics | [datasheet](https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/Datasheets/MQ136%20-%20Hanwei.pdf) |
|
||||
| MQ-303A | HANWEI Electronics | [datasheet](http://www.kosmodrom.com.ua/pdf/MQ303A.pdf) |
|
||||
| MQ-309A | HANWEI Electronics | [datasheet](http://www.sensorica.ru/pdf/MQ-309A.pdf) |
|
||||
|
||||
@ -173,6 +177,10 @@ Examples/MQ-board.ino
|
||||
|
||||
Please read [CONTRIBUTING.md](https://github.com/miguel5612/MQSensorsLib/blob/master/CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.
|
||||
|
||||
## Reviewers
|
||||
|
||||
* **PhD. Jacipt A Ramón V.** - [*GitHub*]() - [CV](https://scienti.minciencias.gov.co/cvlac/visualizador/generarCurriculoCv.do?cod_rh=0000512702)
|
||||
|
||||
## Authors
|
||||
|
||||
* **Miguel A. Califa U.** - [*GitHub*](https://github.com/miguel5612) - [CV](https://scienti.colciencias.gov.co/cvlac/visualizador/generarCurriculoCv.do?cod_rh=0000050477)
|
||||
@ -236,6 +244,10 @@ This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md
|
||||
}
|
||||
|
||||
|
||||
## Sponsor
|
||||
|
||||
* [Paypal](https://www.paypal.com/paypalme/miguel5612)
|
||||
|
||||
|
||||
<!-- MARKDOWN LINKS & IMAGES -->
|
||||
<!-- https://www.markdownguide.org/basic-syntax/#reference-style-links -->
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
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
|
||||
Please make sure arduino A0 pin represents the analog input configured on #define pin
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
@ -42,7 +42,7 @@ void setup() {
|
||||
|
||||
//Set math model to calculate the PPM concentration and the value of constants
|
||||
MQ3.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
MQ3.setA(0.3934); MQ3.setB(-1.504); // Configurate the ecuation values to get Alcohol concentration
|
||||
MQ3.setA(0.3934); MQ3.setB(-1.504); //Configure the equation to calculate Alcohol concentration value
|
||||
/*
|
||||
Exponential regression:
|
||||
Gas | a | b
|
||||
@ -64,30 +64,30 @@ void setup() {
|
||||
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
|
||||
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
|
||||
// and on clean air (Calibration conditions), setting up R0 value.
|
||||
// We recomend executing this routine only on setup in laboratory conditions.
|
||||
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
|
||||
// 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
|
||||
MQ3.update(); // Update data, the arduino will read the voltage from 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);}
|
||||
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
|
||||
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
|
||||
/***************************** MQ CAlibration ********************************************/
|
||||
}
|
||||
|
||||
void loop() {
|
||||
MQ3.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
alcoholPPM = MQ3.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
MQ3.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
alcoholPPM = MQ3.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
Serial.print("Alcohol now (PPM): ");
|
||||
Serial.println(alcoholPPM);
|
||||
delay(500); //Sampling frequency
|
||||
|
@ -47,7 +47,7 @@ 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
|
||||
MQ2.setA(574.25); MQ2.setB(-2.222); // Configure the equation to to calculate LPG concentration
|
||||
/*
|
||||
//If the RL value is different from 10K please assign your RL value with the following method:
|
||||
MQ3.setRL(10);
|
||||
|
136
examples/ESP32/ESP32_WROOM_32D/ESP32_WROOM_32D.ino
Normal file
136
examples/ESP32/ESP32_WROOM_32D/ESP32_WROOM_32D.ino
Normal file
@ -0,0 +1,136 @@
|
||||
/*
|
||||
* This sketch fixes the MQ2 measuring issue when using Wifi.h
|
||||
* Wifi.h deactivates pin 25 analogical input on esp32.ino default sketch.
|
||||
* This is because Wifi.h works only with ADC1 for analogical measurement
|
||||
* Please check the esp32-wroom-32d.jpg image on ESP32 folder
|
||||
*
|
||||
|
||||
* ADC1 GPIO
|
||||
* ADC1_CH0 (GPIO 36) // only tested on this and it works as expected :)
|
||||
* ADC1_CH1 (GPIO 37)
|
||||
* ADC1_CH2 (GPIO 38)
|
||||
* ADC1_CH3 (GPIO 39)
|
||||
* ADC1_CH4 (GPIO 32)
|
||||
* ADC1_CH5 (GPIO 33)
|
||||
* ADC1_CH6 (GPIO 34)
|
||||
* ADC1_CH7 (GPIO 35)
|
||||
*
|
||||
* ADC2 GPIO
|
||||
* ADC2_CH0 (GPIO 4)
|
||||
* ADC2_CH1 (GPIO 0)
|
||||
* ADC2_CH2 (GPIO 2)
|
||||
* ADC2_CH3 (GPIO 15)
|
||||
* ADC2_CH4 (GPIO 13)
|
||||
* ADC2_CH5 (GPIO 12)
|
||||
* ADC2_CH6 (GPIO 14)
|
||||
* ADC2_CH7 (GPIO 27)
|
||||
* ADC2_CH8 (GPIO 25)
|
||||
* ADC2_CH9 (GPIO 26)
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <WiFi.h>
|
||||
|
||||
//Include the library
|
||||
#include <MQUnifiedsensor.h>
|
||||
/************************Hardware Related Macros************************************/
|
||||
#define Board ("ESP-32") // Wemos ESP-32 or other board, whatever have ESP32 core.
|
||||
|
||||
//https://www.amazon.com/HiLetgo-ESP-WROOM-32-Development-Microcontroller-Integrated/dp/B0718T232Z (Although Amazon shows ESP-WROOM-32 ESP32 ESP-32S, the board is the ESP-WROOM-32D)
|
||||
#define Pin (36) //check the esp32-wroom-32d.jpg image on ESP32 folder
|
||||
|
||||
/***********************Software Related Macros************************************/
|
||||
#define Type ("MQ-2") //MQ2 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 RatioMQ2CleanAir (9.83) //RS / R0 = 9.83 ppm
|
||||
/*****************************Globals***********************************************/
|
||||
MQUnifiedsensor MQ2(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin, Type);
|
||||
/*****************************Globals***********************************************/
|
||||
|
||||
const char* ssid = "your-ssid";
|
||||
const char* password = "your-password";
|
||||
|
||||
void setup()
|
||||
{
|
||||
|
||||
//Init the serial port communication - to debug the library
|
||||
Serial.begin(115200); //Init serial port
|
||||
delay(10);
|
||||
|
||||
//Set math model to calculate the PPM concentration and the value of constants
|
||||
MQ2.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
MQ2.setA(987.99); MQ2.setB(-2.162); // Configure the equation to to calculate H2 concentration
|
||||
|
||||
/*
|
||||
Exponential regression:
|
||||
Gas | a | b
|
||||
H2 | 987.99 | -2.162
|
||||
LPG | 574.25 | -2.222
|
||||
CO | 36974 | -3.109
|
||||
Alcohol| 3616.1 | -2.675
|
||||
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 supposedly before being pre-heated
|
||||
// and on clean air (Calibration conditions), setting up R0 value.
|
||||
// We recomend executing this routine only on setup in laboratory conditions.
|
||||
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
|
||||
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||
Serial.print("Calibrating please wait.");
|
||||
float calcR0 = 0;
|
||||
for(int i = 1; i<=10; i ++)
|
||||
{
|
||||
MQ2.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
calcR0 += MQ2.calibrate(RatioMQ2CleanAir);
|
||||
Serial.print(".");
|
||||
}
|
||||
MQ2.setR0(calcR0/10);
|
||||
Serial.println(" done!.");
|
||||
|
||||
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
|
||||
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
|
||||
/***************************** MQ CAlibration ********************************************/
|
||||
//MQ2.serialDebug(true); uncomment if you want to print the table on the serial port
|
||||
|
||||
// We start by connecting to a WiFi network
|
||||
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
Serial.print("Connecting to ");
|
||||
Serial.println(ssid);
|
||||
|
||||
WiFi.begin(ssid, password);
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
}
|
||||
|
||||
Serial.println("");
|
||||
Serial.println("WiFi connected");
|
||||
Serial.println("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
MQ2.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
//MQ2.serialDebug(); // Will print the table on the serial port
|
||||
Serial.print(MQ2.readSensor()); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
Serial.println(" PPM");
|
||||
delay(500); //Sampling frequency
|
||||
}
|
||||
|
BIN
examples/ESP32/ESP32_WROOM_32D/images/esp-32-wroom-32d-board.jpg
Normal file
BIN
examples/ESP32/ESP32_WROOM_32D/images/esp-32-wroom-32d-board.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 32 KiB |
BIN
examples/ESP32/ESP32_WROOM_32D/images/esp32-wroom-32d-pinout.jpg
Normal file
BIN
examples/ESP32/ESP32_WROOM_32D/images/esp32-wroom-32d-pinout.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 484 KiB |
@ -40,7 +40,7 @@ void setup() {
|
||||
|
||||
//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
|
||||
MQ3.setA(4.8387); MQ3.setB(-2.68); // Configure the equation to to calculate Benzene concentration
|
||||
/*
|
||||
Exponential regression:
|
||||
Gas | a | b
|
||||
@ -63,31 +63,31 @@ void setup() {
|
||||
*/
|
||||
/***************************** 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
|
||||
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
|
||||
// and on clean air (Calibration conditions), setting up R0 value.
|
||||
// We recomend executing this routine only on setup in laboratory conditions.
|
||||
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
|
||||
// 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
|
||||
MQ3.update(); // Update data, the arduino will read the voltage from 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);}
|
||||
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
|
||||
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts 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.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
MQ3.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
MQ3.serialDebug(); // Will print the table on the serial port
|
||||
delay(500); //Sampling frequency
|
||||
}
|
@ -40,7 +40,7 @@ void setup() {
|
||||
|
||||
//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
|
||||
MQ3.setA(4.8387); MQ3.setB(-2.68); // Configure the equation to to calculate Benzene concentration
|
||||
/*
|
||||
Exponential regression:
|
||||
Gas | a | b
|
||||
@ -63,31 +63,31 @@ void setup() {
|
||||
*/
|
||||
/***************************** 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
|
||||
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
|
||||
// and on clean air (Calibration conditions), setting up R0 value.
|
||||
// We recomend executing this routine only on setup in laboratory conditions.
|
||||
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
|
||||
// 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
|
||||
MQ3.update(); // Update data, the arduino will read the voltage from 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);}
|
||||
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
|
||||
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts 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.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
MQ3.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
MQ3.serialDebug(); // Will print the table on the serial port
|
||||
delay(500); //Sampling frequency
|
||||
}
|
@ -43,24 +43,24 @@ void setup() {
|
||||
|
||||
/***************************** 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
|
||||
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
|
||||
// and on clean air (Calibration conditions), setting up R0 value.
|
||||
// We recomend executing this routine only on setup in laboratory conditions.
|
||||
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
|
||||
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||
Serial.print("Calibrating please wait.");
|
||||
float calcR0 = 0;
|
||||
for(int i = 1; i<=10; i ++)
|
||||
{
|
||||
MQ4.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ4.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
calcR0 += MQ4.calibrate(RatioMQ4CleanAir);
|
||||
Serial.print(".");
|
||||
}
|
||||
MQ4.setR0(calcR0/10);
|
||||
Serial.println(" done!.");
|
||||
|
||||
if(isinf(calcR0)) {Serial.println("Warning: Conection issue founded, R0 is infite (Open circuit detected) please check your wiring and supply"); while(1);}
|
||||
if(calcR0 == 0){Serial.println("Warning: Conection issue founded, R0 is zero (Analog pin with short circuit to ground) please check your wiring and supply"); while(1);}
|
||||
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
|
||||
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
|
||||
/***************************** MQ CAlibration ********************************************/
|
||||
|
||||
/*
|
||||
@ -75,23 +75,23 @@ void setup() {
|
||||
/************************************************************************************/
|
||||
MQ4.init();
|
||||
|
||||
Serial.println("** Lectures from MQ-4**********");
|
||||
Serial.println("** Values from MQ-4**********");
|
||||
Serial.println("| LPG (Linear EQ) | LPG (Exponential EQ) |");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
MQ4.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ4.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
|
||||
//https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||
//Set math model to calculate the PPM concentration and the value of constants
|
||||
MQ4.setRegressionMethod(0); //_PPM = pow(10, (log10(ratio)-b)/a)
|
||||
MQ4.setA(-0.318); MQ4.setB(1.133); // A -> Slope, B -> Intersect with X - Axis
|
||||
float LPG1 = MQ4.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
float LPG1 = MQ4.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
|
||||
//Set math model to calculate the PPM concentration and the value of constants
|
||||
MQ4.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
MQ4.setA(1012.7); MQ4.setB(-2.786); // Configurate the ecuation values to get CH4 concentration
|
||||
float LPG2 = MQ4.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
MQ4.setA(1012.7); MQ4.setB(-2.786); // Configure the equation to to calculate CH4 concentration
|
||||
float LPG2 = MQ4.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
|
||||
// exposure to 2000 ppm of LPG gas is immediately dangerous to life and health. In this section
|
||||
if(LPG1>=2000 || LPG2>=2000) Serial.println("Warning - Very high concentrations detected!");
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
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
|
||||
Please make sure arduino A0 pin represents the analog input configured on #define pin
|
||||
|
||||
Note: high concentration MQ-131 sensor.
|
||||
|
||||
@ -44,7 +44,7 @@ void setup() {
|
||||
|
||||
//Set math model to calculate the PPM concentration and the value of constants
|
||||
MQ131.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
MQ131.setA(23.943); MQ131.setB(-1.11); // Configurate the ecuation values to get O3 concentration
|
||||
MQ131.setA(23.943); MQ131.setB(-1.11); // Configure the equation to to calculate O3 concentration
|
||||
|
||||
/*
|
||||
Exponential regression:
|
||||
@ -65,32 +65,32 @@ void setup() {
|
||||
*/
|
||||
/***************************** 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
|
||||
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
|
||||
// and on clean air (Calibration conditions), setting up R0 value.
|
||||
// We recomend executing this routine only on setup in laboratory conditions.
|
||||
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
|
||||
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||
Serial.print("Calibrating please wait.");
|
||||
float calcR0 = 0;
|
||||
for(int i = 1; i<=10; i ++)
|
||||
{
|
||||
MQ131.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ131.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
calcR0 += MQ131.calibrate(RatioMQ131CleanAir);
|
||||
Serial.print(".");
|
||||
}
|
||||
MQ131.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);}
|
||||
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
|
||||
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
|
||||
/***************************** MQ CAlibration ********************************************/
|
||||
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.readSensorR0Rs(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
MQ131.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
MQ131.readSensorR0Rs(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
MQ131.serialDebug(); // Will print the table on the serial port
|
||||
delay(500); //Sampling frequency
|
||||
}
|
@ -15,7 +15,7 @@
|
||||
|
||||
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
|
||||
Please make sure arduino A0 pin represents the analog input configured on #define pin
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
@ -53,56 +53,62 @@ void setup() {
|
||||
*/
|
||||
/***************************** 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
|
||||
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
|
||||
// and on clean air (Calibration conditions), setting up R0 value.
|
||||
// We recomend executing this routine only on setup in laboratory conditions.
|
||||
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
|
||||
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||
Serial.print("Calibrating please wait.");
|
||||
float calcR0 = 0;
|
||||
for(int i = 1; i<=10; i ++)
|
||||
{
|
||||
MQ135.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ135.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
calcR0 += MQ135.calibrate(RatioMQ135CleanAir);
|
||||
Serial.print(".");
|
||||
}
|
||||
MQ135.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);}
|
||||
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
|
||||
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
|
||||
/***************************** MQ CAlibration ********************************************/
|
||||
Serial.println("** Lectures from MQ-135 ****");
|
||||
Serial.println("| CO | Alcohol | CO2 | Tolueno | NH4 | Acteona |");
|
||||
Serial.println("** Values from MQ-135 ****");
|
||||
Serial.println("| CO | Alcohol | CO2 | Toluen | NH4 | Aceton |");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
MQ135.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ135.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
|
||||
MQ135.setA(605.18); MQ135.setB(-3.937); // Configurate the ecuation values to get CO concentration
|
||||
float CO = MQ135.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
MQ135.setA(605.18); MQ135.setB(-3.937); // Configure the equation to calculate CO concentration value
|
||||
float CO = MQ135.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
|
||||
MQ135.setA(77.255); MQ135.setB(-3.18); // Configurate the ecuation values to get Alcohol concentration
|
||||
float Alcohol = MQ135.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
MQ135.setA(77.255); MQ135.setB(-3.18); //Configure the equation to calculate Alcohol concentration value
|
||||
float Alcohol = MQ135.readSensor(); // SSensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
|
||||
MQ135.setA(110.47); MQ135.setB(-2.862); // Configurate the ecuation values to get CO2 concentration
|
||||
float CO2 = MQ135.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
MQ135.setA(110.47); MQ135.setB(-2.862); // Configure the equation to calculate CO2 concentration value
|
||||
float CO2 = MQ135.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
|
||||
MQ135.setA(44.947); MQ135.setB(-3.445); // Configurate the ecuation values to get Tolueno concentration
|
||||
float Tolueno = MQ135.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
|
||||
MQ135.setA(102.2 ); MQ135.setB(-2.473); // Configurate the ecuation values to get NH4 concentration
|
||||
float NH4 = MQ135.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
|
||||
MQ135.setA(34.668); MQ135.setB(-3.369); // Configurate the ecuation values to get Acetona concentration
|
||||
float Acetona = MQ135.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
MQ135.setA(44.947); MQ135.setB(-3.445); // Configure the equation to calculate Toluen concentration value
|
||||
float Toluen = MQ135.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
|
||||
MQ135.setA(102.2 ); MQ135.setB(-2.473); // Configure the equation to calculate NH4 concentration value
|
||||
float NH4 = MQ135.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
|
||||
MQ135.setA(34.668); MQ135.setB(-3.369); // Configure the equation to calculate Aceton concentration value
|
||||
float Aceton = MQ135.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
Serial.print("| "); Serial.print(CO);
|
||||
Serial.print(" | "); Serial.print(Alcohol);
|
||||
Serial.print(" | "); Serial.print(CO2);
|
||||
Serial.print(" | "); Serial.print(Tolueno);
|
||||
Serial.print(" | "); Serial.print(Alcohol);
|
||||
// Note: 400 Offset for CO2 source: https://github.com/miguel5612/MQSensorsLib/issues/29
|
||||
/*
|
||||
Motivation:
|
||||
We have added 400 PPM because when the library is calibrated it assumes the current state of the
|
||||
air as 0 PPM, and it is considered today that the CO2 present in the atmosphere is around 400 PPM.
|
||||
https://www.lavanguardia.com/natural/20190514/462242832581/concentracion-dioxido-cabono-co2-atmosfera-bate-record-historia-humanidad.html
|
||||
*/
|
||||
Serial.print(" | "); Serial.print(CO2 + 400);
|
||||
Serial.print(" | "); Serial.print(Toluen);
|
||||
Serial.print(" | "); Serial.print(NH4);
|
||||
Serial.print(" | "); Serial.print(Acetona);
|
||||
Serial.print(" | "); Serial.print(Aceton);
|
||||
Serial.println(" |");
|
||||
/*
|
||||
Exponential regression:
|
||||
@ -110,10 +116,10 @@ void loop() {
|
||||
CO | 605.18 | -3.937
|
||||
Alcohol | 77.255 | -3.18
|
||||
CO2 | 110.47 | -2.862
|
||||
Tolueno | 44.947 | -3.445
|
||||
Toluen | 44.947 | -3.445
|
||||
NH4 | 102.2 | -2.473
|
||||
Acetona | 34.668 | -3.369
|
||||
Aceton | 34.668 | -3.369
|
||||
*/
|
||||
|
||||
delay(500); //Sampling frequency
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,183 @@
|
||||
/*
|
||||
MQUnifiedsensor Library - reading an MQ135
|
||||
|
||||
Demonstrates the use a MQ135 sensor.
|
||||
Library originally added 01 may 2019
|
||||
by Miguel A Califa, Yersson Carrillo, Ghiordy Contreras, Mario Rodriguez
|
||||
|
||||
Added example
|
||||
modified 23 May 2019
|
||||
by Miguel Califa
|
||||
|
||||
Updated library usage
|
||||
modified 26 March 2020
|
||||
by Miguel Califa
|
||||
|
||||
Wiring:
|
||||
https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/static/img/MQ_Arduino.PNG
|
||||
Please make sure arduino A0 pin represents the analog input configured on #define pin
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
*/
|
||||
|
||||
//Include the library
|
||||
#include <MQUnifiedsensor.h>
|
||||
#include <Adafruit_Sensor.h>
|
||||
#include <DHT.h>
|
||||
#include <DHT_U.h>
|
||||
|
||||
//Definitions
|
||||
#define placa "Arduino UNO"
|
||||
#define Voltage_Resolution 5
|
||||
#define pin A0 //Analog input 0 of your arduino
|
||||
#define type "MQ-135" //MQ135
|
||||
#define ADC_Bit_Resolution 10 // For arduino UNO/MEGA/NANO
|
||||
#define RatioMQ135CleanAir 3.6//RS / R0 = 3.6 ppm
|
||||
//#define calibration_button 13 //Pin to calibrate your sensor
|
||||
|
||||
#define MQ135_DEFAULTPPM 399 //default ppm of CO2 for calibration
|
||||
#define MQ135_DEFAULTRO 68550 //default Ro for MQ135_DEFAULTPPM ppm of CO2
|
||||
#define MQ135_SCALINGFACTOR 116.6020682 //CO2 gas value
|
||||
#define MQ135_EXPONENT -2.769034857 //CO2 gas value
|
||||
#define MQ135_MAXRSRO 2.428 //for CO2
|
||||
#define MQ135_MINRSRO 0.358 //for CO2
|
||||
|
||||
|
||||
/// Parameters for calculating ppm of CO2 from sensor resistance
|
||||
#define PARA 116.6020682
|
||||
#define PARB 2.769034857
|
||||
|
||||
/// Parameters to model temperature and humidity dependence
|
||||
#define CORA 0.00035
|
||||
#define CORB 0.02718
|
||||
#define CORC 1.39538
|
||||
#define CORD 0.0018
|
||||
|
||||
#define DHTPIN 2 // Digital pin connected to the DHT sensor
|
||||
// Feather HUZZAH ESP8266 note: use pins 3, 4, 5, 12, 13 or 14 --
|
||||
// Pin 15 can work but DHT must be disconnected during program upload.
|
||||
|
||||
// Uncomment the type of sensor in use:
|
||||
//#define DHTTYPE DHT11 // DHT 11
|
||||
#define DHTTYPE DHT22 // DHT 22 (AM2302)
|
||||
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
|
||||
|
||||
// See guide for details on sensor wiring and usage:
|
||||
// https://learn.adafruit.com/dht/overview
|
||||
|
||||
DHT_Unified dht(DHTPIN, DHTTYPE);
|
||||
|
||||
uint32_t delayMS;
|
||||
|
||||
//Declare Sensor
|
||||
MQUnifiedsensor MQ135(placa, Voltage_Resolution, ADC_Bit_Resolution, pin, type);
|
||||
|
||||
void setup() {
|
||||
//Init the serial port communication - to debug the library
|
||||
Serial.begin(9600); //Init serial port
|
||||
dht.begin();
|
||||
sensor_t sensor;
|
||||
|
||||
//Set math model to calculate the PPM concentration and the value of constants
|
||||
MQ135.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
MQ135.setA(102.2); MQ135.setB(-2.473); // Configure the equation to to calculate NH4 concentration
|
||||
|
||||
/*
|
||||
Exponential regression:
|
||||
GAS | a | b
|
||||
CO | 605.18 | -3.937
|
||||
Alcohol | 77.255 | -3.18
|
||||
CO2 | 110.47 | -2.862
|
||||
Toluen | 44.947 | -3.445
|
||||
NH4 | 102.2 | -2.473
|
||||
Aceton | 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 supposedly before being pre-heated
|
||||
// and on clean air (Calibration conditions), setting up R0 value.
|
||||
// We recomend executing this routine only on setup in laboratory conditions.
|
||||
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
|
||||
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||
Serial.print("Calibrating please wait.");
|
||||
float calcR0 = 0;
|
||||
for(int i = 1; i<=10; i ++)
|
||||
{
|
||||
MQ135.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
calcR0 += MQ135.calibrate(RatioMQ135CleanAir);
|
||||
Serial.print(".");
|
||||
}
|
||||
MQ135.setR0(calcR0/10);
|
||||
Serial.println(" done!.");
|
||||
|
||||
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
|
||||
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
|
||||
/***************************** MQ CAlibration ********************************************/
|
||||
MQ135.serialDebug(true);
|
||||
// Set delay between sensor readings based on sensor details.
|
||||
delayMS = sensor.min_delay / 1000;
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
delay(delayMS); //Sampling frequency
|
||||
|
||||
// if you want to apply corelation factor, you will add in this program the temperature and humidity sensor
|
||||
sensors_event_t event;
|
||||
dht.temperature().getEvent(&event);
|
||||
float cFactor = 0;
|
||||
if (!isnan(event.temperature) && !isnan(event.relative_humidity)) cFactor = getCorrectionFactor(event.temperature, event.relative_humidity);
|
||||
Serial.print("Correction Factor: "); Serial.println(cFactor);
|
||||
MQ135.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
MQ135.readSensor(false, cFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
MQ135.serialDebug(); // Will print the table on the serial port
|
||||
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Get the correction factor to correct for temperature and humidity
|
||||
@param[in] t The ambient air temperature
|
||||
@param[in] h The relative humidity
|
||||
@return The calculated correction factor
|
||||
*/
|
||||
/**************************************************************************/
|
||||
float getCorrectionFactor(float t, float h) {
|
||||
return CORA * t * t - CORB * t + CORC - (h-33.)*CORD;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Get the resistance of the sensor, ie. the measurement value corrected
|
||||
for temp/hum
|
||||
@param[in] t The ambient air temperature
|
||||
@param[in] h The relative humidity
|
||||
@return The corrected sensor resistance kOhm
|
||||
*/
|
||||
/**************************************************************************/
|
||||
float getCorrectedResistance(long resvalue, float t, float h) {
|
||||
return resvalue/getCorrectionFactor(t, h);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Get the ppm of CO2 sensed (assuming only CO2 in the air), corrected
|
||||
for temp/hum
|
||||
@param[in] t The ambient air temperature
|
||||
@param[in] h The relative humidity
|
||||
@return The ppm of CO2 in the air
|
||||
*/
|
||||
/**************************************************************************/
|
||||
float getCorrectedPPM(long resvalue,float t, float h, long ro) {
|
||||
return PARA * pow((getCorrectedResistance(resvalue, t, h)/ro), -PARB);
|
||||
}
|
@ -15,7 +15,7 @@
|
||||
|
||||
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
|
||||
Please make sure arduino A0 pin represents the analog input configured on #define pin
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
@ -42,7 +42,7 @@ void setup() {
|
||||
|
||||
//Set math model to calculate the PPM concentration and the value of constants
|
||||
MQ135.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
MQ135.setA(102.2); MQ135.setB(-2.473); // Configurate the ecuation values to get NH4 concentration
|
||||
MQ135.setA(102.2); MQ135.setB(-2.473); // Configure the equation to to calculate NH4 concentration
|
||||
|
||||
/*
|
||||
Exponential regression:
|
||||
@ -50,9 +50,9 @@ void setup() {
|
||||
CO | 605.18 | -3.937
|
||||
Alcohol | 77.255 | -3.18
|
||||
CO2 | 110.47 | -2.862
|
||||
Tolueno | 44.947 | -3.445
|
||||
Toluen | 44.947 | -3.445
|
||||
NH4 | 102.2 | -2.473
|
||||
Acetona | 34.668 | -3.369
|
||||
Aceton | 34.668 | -3.369
|
||||
*/
|
||||
|
||||
/***************************** MQ Init ********************************************/
|
||||
@ -65,31 +65,31 @@ void setup() {
|
||||
*/
|
||||
/***************************** 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
|
||||
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
|
||||
// and on clean air (Calibration conditions), setting up R0 value.
|
||||
// We recomend executing this routine only on setup in laboratory conditions.
|
||||
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
|
||||
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||
Serial.print("Calibrating please wait.");
|
||||
float calcR0 = 0;
|
||||
for(int i = 1; i<=10; i ++)
|
||||
{
|
||||
MQ135.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ135.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
calcR0 += MQ135.calibrate(RatioMQ135CleanAir);
|
||||
Serial.print(".");
|
||||
}
|
||||
MQ135.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);}
|
||||
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
|
||||
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
|
||||
/***************************** MQ CAlibration ********************************************/
|
||||
MQ135.serialDebug(true);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
MQ135.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ135.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
MQ135.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
MQ135.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
MQ135.serialDebug(); // Will print the table on the serial port
|
||||
delay(500); //Sampling frequency
|
||||
}
|
88
examples/MQ-136/MQ-136.ino
Normal file
88
examples/MQ-136/MQ-136.ino
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
MQUnifiedsensor Library - reading an MQ136
|
||||
|
||||
Demonstrates the use a MQ136 sensor.
|
||||
Library originally added 01 may 2019
|
||||
by Miguel A Califa, Yersson Carrillo, Ghiordy Contreras, Mario Rodriguez
|
||||
|
||||
Added example
|
||||
modified 21 March 2022
|
||||
by Miguel Califa
|
||||
|
||||
Wiring:
|
||||
https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/static/img/MQ_Arduino.PNG
|
||||
Please make sure arduino A0 pin represents the analog input configured on #define pin
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
*/
|
||||
|
||||
//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-136" //MQ136
|
||||
#define ADC_Bit_Resolution 10 // For arduino UNO/MEGA/NANO
|
||||
#define RatioMQ136CleanAir 3.6//RS / R0 = 3.6 ppm
|
||||
//#define calibration_button 13 //Pin to calibrate your sensor
|
||||
|
||||
//Declare Sensor
|
||||
MQUnifiedsensor MQ136(placa, Voltage_Resolution, ADC_Bit_Resolution, pin, type);
|
||||
|
||||
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
|
||||
MQ136.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
MQ136.setA(36.737); MQ136.setB(-3.536); // Configure the equation to to calculate H2S Concentration
|
||||
|
||||
/*
|
||||
Exponential regression:
|
||||
GAS | a | b
|
||||
H2S | 36.737 | -3.536
|
||||
NH4 | 98.551 | -2.475
|
||||
CO | 503.34 | -3.774
|
||||
*/
|
||||
|
||||
/***************************** MQ Init ********************************************/
|
||||
//Remarks: Configure the pin of arduino as input.
|
||||
/************************************************************************************/
|
||||
MQ136.init();
|
||||
/*
|
||||
//If the RL value is different from 10K please assign your RL value with the following method:
|
||||
MQ136.setRL(10);
|
||||
*/
|
||||
/***************************** MQ CAlibration ********************************************/
|
||||
// Explanation:
|
||||
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
|
||||
// and on clean air (Calibration conditions), setting up R0 value.
|
||||
// We recomend executing this routine only on setup in laboratory conditions.
|
||||
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
|
||||
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||
Serial.print("Calibrating please wait.");
|
||||
float calcR0 = 0;
|
||||
for(int i = 1; i<=10; i ++)
|
||||
{
|
||||
MQ136.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
calcR0 += MQ136.calibrate(RatioMQ136CleanAir);
|
||||
Serial.print(".");
|
||||
}
|
||||
MQ136.setR0(calcR0/10);
|
||||
Serial.println(" done!.");
|
||||
|
||||
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
|
||||
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
|
||||
/***************************** MQ CAlibration ********************************************/
|
||||
MQ136.serialDebug(true);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
MQ136.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
MQ136.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
MQ136.serialDebug(); // Will print the table on the serial port
|
||||
delay(500); //Sampling frequency
|
||||
}
|
@ -14,7 +14,7 @@
|
||||
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
|
||||
Please make sure arduino A0 pin represents the analog input configured on #define pin
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
@ -41,7 +41,7 @@ void setup() {
|
||||
|
||||
//Set math model to calculate the PPM concentration and the value of constants
|
||||
MQ2.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
MQ2.setA(574.25); MQ2.setB(-2.222); // Configurate the ecuation values to get LPG concentration
|
||||
MQ2.setA(574.25); MQ2.setB(-2.222); // Configure the equation to to calculate LPG concentration
|
||||
/*
|
||||
Exponential regression:
|
||||
Gas | a | b
|
||||
@ -62,32 +62,32 @@ void setup() {
|
||||
*/
|
||||
/***************************** 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
|
||||
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
|
||||
// and on clean air (Calibration conditions), setting up R0 value.
|
||||
// We recomend executing this routine only on setup in laboratory conditions.
|
||||
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
|
||||
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||
Serial.print("Calibrating please wait.");
|
||||
float calcR0 = 0;
|
||||
for(int i = 1; i<=10; i ++)
|
||||
{
|
||||
MQ2.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ2.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
calcR0 += MQ2.calibrate(RatioMQ2CleanAir);
|
||||
Serial.print(".");
|
||||
}
|
||||
MQ2.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);}
|
||||
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
|
||||
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
|
||||
/***************************** MQ CAlibration ********************************************/
|
||||
|
||||
MQ2.serialDebug(true);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
MQ2.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ2.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
MQ2.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
MQ2.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
MQ2.serialDebug(); // Will print the table on the serial port
|
||||
delay(500); //Sampling frequency
|
||||
}
|
@ -15,7 +15,7 @@
|
||||
|
||||
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
|
||||
Please make sure arduino A0 pin represents the analog input configured on #define pin
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
@ -41,7 +41,7 @@ void setup() {
|
||||
|
||||
//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
|
||||
MQ3.setA(4.8387); MQ3.setB(-2.68); // Configure the equation to to calculate Benzene concentration
|
||||
/*
|
||||
Exponential regression:
|
||||
Gas | a | b
|
||||
@ -64,31 +64,31 @@ void setup() {
|
||||
*/
|
||||
/***************************** 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
|
||||
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
|
||||
// and on clean air (Calibration conditions), setting up R0 value.
|
||||
// We recomend executing this routine only on setup in laboratory conditions.
|
||||
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
|
||||
// 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
|
||||
MQ3.update(); // Update data, the arduino will read the voltage from 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);}
|
||||
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
|
||||
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts 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.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
MQ3.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
MQ3.serialDebug(); // Will print the table on the serial port
|
||||
delay(500); //Sampling frequency
|
||||
}
|
@ -15,7 +15,7 @@
|
||||
|
||||
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
|
||||
Please make sure arduino A0 pin represents the analog input configured on #define pin
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
@ -42,7 +42,7 @@ void setup() {
|
||||
|
||||
//Set math model to calculate the PPM concentration and the value of constants
|
||||
MQ303.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
MQ303.setA(6.2144); MQ303.setB(-2.894); // Configurate the ecuation values to get Isobutano concentration
|
||||
MQ303.setA(6.2144); MQ303.setB(-2.894); // Configure the equation to to calculate Isobutano concentration
|
||||
|
||||
/*
|
||||
Exponential regression:
|
||||
@ -62,31 +62,31 @@ void setup() {
|
||||
*/
|
||||
/***************************** 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
|
||||
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
|
||||
// and on clean air (Calibration conditions), setting up R0 value.
|
||||
// We recomend executing this routine only on setup in laboratory conditions.
|
||||
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
|
||||
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||
Serial.print("Calibrating please wait.");
|
||||
float calcR0 = 0;
|
||||
for(int i = 1; i<=10; i ++)
|
||||
{
|
||||
MQ303.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ303.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
calcR0 += MQ303.calibrate(RatioMQ303CleanAir);
|
||||
Serial.print(".");
|
||||
}
|
||||
MQ303.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);}
|
||||
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
|
||||
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
|
||||
/***************************** MQ CAlibration ********************************************/
|
||||
MQ303.serialDebug(true);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
MQ303.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ303.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
MQ303.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
MQ303.readSensor(true); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
MQ303.serialDebug(); // Will print the table on the serial port
|
||||
delay(500); //Sampling frequency
|
||||
}
|
@ -15,7 +15,7 @@
|
||||
|
||||
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
|
||||
Please make sure arduino A0 pin represents the analog input configured on #define pin
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
@ -44,7 +44,7 @@ void setup() {
|
||||
|
||||
//Set math model to calculate the PPM concentration and the value of constants
|
||||
MQ309.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
MQ309.setA(1000000); MQ309.setB(-4.01); // Configurate the ecuation values to get CO concentration
|
||||
MQ309.setA(1000000); MQ309.setB(-4.01); // Configure the equation to calculate CO concentration value
|
||||
|
||||
/*
|
||||
Exponential regression:
|
||||
@ -65,24 +65,24 @@ void setup() {
|
||||
*/
|
||||
/***************************** 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
|
||||
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
|
||||
// and on clean air (Calibration conditions), setting up R0 value.
|
||||
// We recomend executing this routine only on setup in laboratory conditions.
|
||||
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
|
||||
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||
Serial.print("Calibrating please wait.");
|
||||
float calcR0 = 0;
|
||||
for(int i = 1; i<=10; i ++)
|
||||
{
|
||||
MQ309.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ309.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
calcR0 += MQ309.calibrate(RatioMQ309CleanAir);
|
||||
Serial.print(".");
|
||||
}
|
||||
MQ309.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);}
|
||||
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
|
||||
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
|
||||
/***************************** MQ CAlibration ********************************************/
|
||||
MQ309.serialDebug(true);
|
||||
}
|
||||
@ -94,8 +94,8 @@ void loop() {
|
||||
{
|
||||
// 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.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
MQ309.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
MQ309.serialDebug(); // Will print the table on the serial port
|
||||
delay(500); //Sampling frequency
|
||||
}
|
||||
@ -106,8 +106,8 @@ void loop() {
|
||||
{
|
||||
// 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.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
MQ309.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
MQ309.serialDebug(); // Will print the table on the serial port
|
||||
delay(500); //Sampling frequency
|
||||
}
|
@ -15,7 +15,7 @@
|
||||
|
||||
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
|
||||
Please make sure arduino A0 pin represents the analog input configured on #define pin
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
@ -53,32 +53,32 @@ void setup() {
|
||||
*/
|
||||
/***************************** 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
|
||||
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
|
||||
// and on clean air (Calibration conditions), setting up R0 value.
|
||||
// We recomend executing this routine only on setup in laboratory conditions.
|
||||
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
|
||||
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||
Serial.print("Calibrating please wait.");
|
||||
float calcR0 = 0;
|
||||
for(int i = 1; i<=10; i ++)
|
||||
{
|
||||
MQ4.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ4.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
calcR0 += MQ4.calibrate(RatioMQ4CleanAir);
|
||||
Serial.print(".");
|
||||
}
|
||||
MQ4.setR0(calcR0/10);
|
||||
Serial.println(" done!.");
|
||||
|
||||
if(isinf(calcR0)) {Serial.println("Warning: Conection issue founded, R0 is infite (Open circuit detected) please check your wiring and supply"); while(1);}
|
||||
if(calcR0 == 0){Serial.println("Warning: Conection issue founded, R0 is zero (Analog pin with short circuit to ground) please check your wiring and supply"); while(1);}
|
||||
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
|
||||
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
|
||||
/***************************** MQ CAlibration ********************************************/
|
||||
|
||||
Serial.println("*************** Lectures from MQ-4 **********************");
|
||||
Serial.println("*************** Values from MQ-4 **********************");
|
||||
Serial.println("| LPG | CH4 | CO | Alcohol | Smoke |");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
MQ4.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ4.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
|
||||
/*
|
||||
Exponential regression:
|
||||
@ -89,20 +89,20 @@ void loop() {
|
||||
Alcohol| 60000000000 | -14.01
|
||||
smoke | 30000000 | -8.308
|
||||
*/
|
||||
MQ4.setA(3811.9); MQ4.setB(-3.113); // Configurate the ecuation values to get CH4 concentration
|
||||
float LPG = MQ4.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
MQ4.setA(3811.9); MQ4.setB(-3.113); // Configure the equation to to calculate CH4 concentration
|
||||
float LPG = MQ4.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
|
||||
MQ4.setA(1012.7); MQ4.setB(-2.786); // Configurate the ecuation values to get CH4 concentration
|
||||
float CH4 = MQ4.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
MQ4.setA(1012.7); MQ4.setB(-2.786); // Configure the equation to to calculate CH4 concentration
|
||||
float CH4 = MQ4.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
|
||||
MQ4.setA(200000000000000); MQ4.setB(-19.05); // Configurate the ecuation values to get CH4 concentration
|
||||
float CO = MQ4.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
MQ4.setA(200000000000000); MQ4.setB(-19.05); // Configure the equation to to calculate CH4 concentration
|
||||
float CO = MQ4.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
|
||||
MQ4.setA(60000000000); MQ4.setB(-14.01); // Configurate the ecuation values to get CH4 concentration
|
||||
float Alcohol = MQ4.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
MQ4.setA(60000000000); MQ4.setB(-14.01); // Configure the equation to to calculate CH4 concentration
|
||||
float Alcohol = MQ4.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
|
||||
MQ4.setA(30000000); MQ4.setB(-8.308); // Configurate the ecuation values to get CH4 concentration
|
||||
float Smoke = MQ4.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
MQ4.setA(30000000); MQ4.setB(-8.308); // Configure the equation to to calculate CH4 concentration
|
||||
float Smoke = MQ4.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
|
||||
Serial.print("| "); Serial.print(LPG);
|
||||
Serial.print(" | "); Serial.print(CH4);
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
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
|
||||
Please make sure arduino A0 pin represents the analog input configured on #define pin
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
@ -52,36 +52,36 @@ void setup() {
|
||||
*/
|
||||
/***************************** 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
|
||||
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
|
||||
// and on clean air (Calibration conditions), setting up R0 value.
|
||||
// We recomend executing this routine only on setup in laboratory conditions.
|
||||
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
|
||||
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||
Serial.print("Calibrating please wait.");
|
||||
float calcR0 = 0;
|
||||
for(int i = 1; i<=10; i ++)
|
||||
{
|
||||
MQ4.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ4.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
calcR0 += MQ4.calibrate(RatioMQ4CleanAir);
|
||||
Serial.print(".");
|
||||
}
|
||||
MQ4.setR0(calcR0/10);
|
||||
Serial.println(" done!.");
|
||||
|
||||
if(isinf(calcR0)) {Serial.println("Warning: Conection issue founded, R0 is infite (Open circuit detected) please check your wiring and supply"); while(1);}
|
||||
if(calcR0 == 0){Serial.println("Warning: Conection issue founded, R0 is zero (Analog pin with short circuit to ground) please check your wiring and supply"); while(1);}
|
||||
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
|
||||
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
|
||||
/***************************** MQ CAlibration ********************************************/
|
||||
|
||||
Serial.println("** Lectures from MQ-4**********");
|
||||
Serial.println("** Values from MQ-4**********");
|
||||
Serial.println("| LPG |");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
MQ4.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ4.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
|
||||
//https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||
MQ4.setA(-0.318); MQ4.setB(1.133); // A -> Slope, B -> Intersect with X - Axis
|
||||
float LPG = MQ4.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
float LPG = MQ4.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
|
||||
// exposure to 2000 ppm of LPG gas is immediately dangerous to life and health. In this section
|
||||
if(LPG>=2000) Serial.println("Warning - Very high concentrations detected!");
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
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
|
||||
Please make sure arduino A0 pin represents the analog input configured on #define pin
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
@ -41,7 +41,7 @@ void setup() {
|
||||
|
||||
//Set math model to calculate the PPM concentration and the value of constants
|
||||
MQ4.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
MQ4.setA(1012.7); MQ4.setB(-2.786); // Configurate the ecuation values to get CH4 concentration
|
||||
MQ4.setA(1012.7); MQ4.setB(-2.786); // Configure the equation to to calculate CH4 concentration
|
||||
/*
|
||||
Exponential regression:
|
||||
Gas | a | b
|
||||
@ -63,31 +63,31 @@ void setup() {
|
||||
*/
|
||||
/***************************** 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
|
||||
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
|
||||
// and on clean air (Calibration conditions), setting up R0 value.
|
||||
// We recomend executing this routine only on setup in laboratory conditions.
|
||||
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
|
||||
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||
Serial.print("Calibrating please wait.");
|
||||
float calcR0 = 0;
|
||||
for(int i = 1; i<=10; i ++)
|
||||
{
|
||||
MQ4.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ4.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
calcR0 += MQ4.calibrate(RatioMQ4CleanAir);
|
||||
Serial.print(".");
|
||||
}
|
||||
MQ4.setR0(calcR0/10);
|
||||
Serial.println(" done!.");
|
||||
|
||||
if(isinf(calcR0)) {Serial.println("Warning: Conection issue founded, R0 is infite (Open circuit detected) please check your wiring and supply"); while(1);}
|
||||
if(calcR0 == 0){Serial.println("Warning: Conection issue founded, R0 is zero (Analog pin with short circuit to ground) please check your wiring and supply"); while(1);}
|
||||
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
|
||||
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
|
||||
/***************************** MQ CAlibration ********************************************/
|
||||
MQ4.serialDebug(true);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
MQ4.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ4.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
MQ4.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
MQ4.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
MQ4.serialDebug(); // Will print the table on the serial port
|
||||
delay(500); //Sampling frequency
|
||||
}
|
@ -15,7 +15,7 @@
|
||||
|
||||
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
|
||||
Please make sure arduino A0 pin represents the analog input configured on #define pin
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
@ -42,7 +42,7 @@ void setup() {
|
||||
|
||||
//Set math model to calculate the PPM concentration and the value of constants
|
||||
MQ5.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
MQ5.setA(1163.8); MQ5.setB(-3.874); // Configurate the ecuation values to get H2 concentration
|
||||
MQ5.setA(1163.8); MQ5.setB(-3.874); // Configure the equation to to calculate H2 concentration
|
||||
/*
|
||||
Exponential regression:
|
||||
Gas | a | b
|
||||
@ -63,31 +63,31 @@ void setup() {
|
||||
*/
|
||||
/***************************** 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
|
||||
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
|
||||
// and on clean air (Calibration conditions), setting up R0 value.
|
||||
// We recomend executing this routine only on setup in laboratory conditions.
|
||||
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
|
||||
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||
Serial.print("Calibrating please wait.");
|
||||
float calcR0 = 0;
|
||||
for(int i = 1; i<=10; i ++)
|
||||
{
|
||||
MQ5.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ5.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
calcR0 += MQ5.calibrate(RatioMQ5CleanAir);
|
||||
Serial.print(".");
|
||||
}
|
||||
MQ5.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);}
|
||||
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
|
||||
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
|
||||
/***************************** MQ CAlibration ********************************************/
|
||||
MQ5.serialDebug(true);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
MQ5.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ5.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
MQ5.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
MQ5.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
MQ5.serialDebug(); // Will print the table on the serial port
|
||||
delay(500); //Sampling frequency
|
||||
}
|
@ -15,7 +15,7 @@
|
||||
|
||||
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
|
||||
Please make sure arduino A0 pin represents the analog input configured on #define pin
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
@ -42,7 +42,7 @@ void setup() {
|
||||
|
||||
//Set math model to calculate the PPM concentration and the value of constants
|
||||
MQ6.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
MQ6.setA(2127.2); MQ6.setB(-2.526); // Configurate the ecuation values to get CH4 concentration
|
||||
MQ6.setA(2127.2); MQ6.setB(-2.526); // Configure the equation to to calculate CH4 concentration
|
||||
/*
|
||||
Exponential regression:
|
||||
GAS | a | b
|
||||
@ -63,31 +63,31 @@ void setup() {
|
||||
*/
|
||||
/***************************** 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
|
||||
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
|
||||
// and on clean air (Calibration conditions), setting up R0 value.
|
||||
// We recomend executing this routine only on setup in laboratory conditions.
|
||||
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
|
||||
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||
Serial.print("Calibrating please wait.");
|
||||
float calcR0 = 0;
|
||||
for(int i = 1; i<=10; i ++)
|
||||
{
|
||||
MQ6.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ6.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
calcR0 += MQ6.calibrate(RatioMQ6CleanAir);
|
||||
Serial.print(".");
|
||||
}
|
||||
MQ6.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);}
|
||||
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
|
||||
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
|
||||
/***************************** MQ CAlibration ********************************************/
|
||||
MQ6.serialDebug(true);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
MQ6.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ6.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
MQ6.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
MQ6.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
MQ6.serialDebug(); // Will print the table on the serial port
|
||||
delay(500); //Sampling frequency
|
||||
}
|
@ -19,7 +19,7 @@
|
||||
|
||||
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
|
||||
Please make sure arduino A0 pin represents the analog input configured on #define pin
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
@ -48,7 +48,7 @@ void setup() {
|
||||
|
||||
//Set math model to calculate the PPM concentration and the value of constants
|
||||
MQ7.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
MQ7.setA(99.042); MQ7.setB(-1.518); // Configurate the ecuation values to get CO concentration
|
||||
MQ7.setA(99.042); MQ7.setB(-1.518); // Configure the equation to calculate CO concentration value
|
||||
|
||||
/*
|
||||
Exponential regression:
|
||||
@ -70,24 +70,24 @@ void setup() {
|
||||
*/
|
||||
/***************************** 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
|
||||
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
|
||||
// and on clean air (Calibration conditions), setting up R0 value.
|
||||
// We recomend executing this routine only on setup in laboratory conditions.
|
||||
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
|
||||
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||
Serial.print("Calibrating please wait.");
|
||||
float calcR0 = 0;
|
||||
for(int i = 1; i<=10; i ++)
|
||||
{
|
||||
MQ7.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ7.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
calcR0 += MQ7.calibrate(RatioMQ7CleanAir);
|
||||
Serial.print(".");
|
||||
}
|
||||
MQ7.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);}
|
||||
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
|
||||
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
|
||||
/***************************** MQ CAlibration ********************************************/
|
||||
MQ7.serialDebug(true);
|
||||
}
|
||||
@ -99,8 +99,8 @@ void loop() {
|
||||
{
|
||||
// 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.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
MQ7.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
MQ7.serialDebug(); // Will print the table on the serial port
|
||||
delay(500); //Sampling frequency
|
||||
}
|
||||
@ -111,8 +111,8 @@ void loop() {
|
||||
{
|
||||
// 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.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
MQ7.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
MQ7.serialDebug(); // Will print the table on the serial port
|
||||
delay(500); //Sampling frequency
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
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
|
||||
Please make sure arduino A0 pin represents the analog input configured on #define pin
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
@ -42,7 +42,7 @@ void setup() {
|
||||
|
||||
//Set math model to calculate the PPM concentration and the value of constants
|
||||
MQ8.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
MQ8.setA(976.97); MQ8.setB(-0.688); // Configurate the ecuation values to get H2 concentration
|
||||
MQ8.setA(976.97); MQ8.setB(-0.688); // Configure the equation to to calculate H2 concentration
|
||||
|
||||
/*
|
||||
Exponential regression:
|
||||
@ -64,31 +64,31 @@ void setup() {
|
||||
*/
|
||||
/***************************** 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
|
||||
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
|
||||
// and on clean air (Calibration conditions), setting up R0 value.
|
||||
// We recomend executing this routine only on setup in laboratory conditions.
|
||||
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
|
||||
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||
Serial.print("Calibrating please wait.");
|
||||
float calcR0 = 0;
|
||||
for(int i = 1; i<=10; i ++)
|
||||
{
|
||||
MQ8.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ8.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
calcR0 += MQ8.calibrate(RatioMQ8CleanAir);
|
||||
Serial.print(".");
|
||||
}
|
||||
MQ8.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);}
|
||||
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
|
||||
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
|
||||
/***************************** MQ CAlibration ********************************************/
|
||||
MQ8.serialDebug(true);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
MQ8.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ8.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
MQ8.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
MQ8.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
MQ8.serialDebug(); // Will print the table on the serial port
|
||||
delay(500); //Sampling frequency
|
||||
}
|
@ -15,7 +15,7 @@
|
||||
|
||||
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
|
||||
Please make sure arduino A0 pin represents the analog input configured on #define pin
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
@ -53,31 +53,31 @@ void setup() {
|
||||
*/
|
||||
/***************************** 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
|
||||
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
|
||||
// and on clean air (Calibration conditions), setting up R0 value.
|
||||
// We recomend executing this routine only on setup in laboratory conditions.
|
||||
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
|
||||
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||
Serial.print("Calibrating please wait.");
|
||||
float calcR0 = 0;
|
||||
for(int i = 1; i<=10; i ++)
|
||||
{
|
||||
MQ9.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ9.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
calcR0 += MQ9.calibrate(RatioMQ9CleanAir);
|
||||
Serial.print(".");
|
||||
}
|
||||
MQ9.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);}
|
||||
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
|
||||
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
|
||||
/***************************** MQ CAlibration ********************************************/
|
||||
Serial.println("** Lectures from MQ-9 ****");
|
||||
Serial.println("** Values from MQ-9 ****");
|
||||
Serial.println("| LPG | CH4 | CO |");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
MQ9.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ9.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
/*
|
||||
Exponential regression:
|
||||
GAS | a | b
|
||||
@ -86,14 +86,14 @@ void loop() {
|
||||
CO | 599.65 | -2.244
|
||||
*/
|
||||
|
||||
MQ9.setA(1000.5); MQ9.setB(-2.186); // Configurate the ecuation values to get LPG concentration
|
||||
float LPG = MQ9.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
MQ9.setA(1000.5); MQ9.setB(-2.186); // Configure the equation to to calculate LPG concentration
|
||||
float LPG = MQ9.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
|
||||
MQ9.setA(4269.6); MQ9.setB(-2.648); // Configurate the ecuation values to get LPG concentration
|
||||
float CH4 = MQ9.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
MQ9.setA(4269.6); MQ9.setB(-2.648); // Configure the equation to to calculate LPG concentration
|
||||
float CH4 = MQ9.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
|
||||
MQ9.setA(599.65); MQ9.setB(-2.244); // Configurate the ecuation values to get LPG concentration
|
||||
float CO = MQ9.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
MQ9.setA(599.65); MQ9.setB(-2.244); // Configure the equation to to calculate LPG concentration
|
||||
float CO = MQ9.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
|
||||
Serial.print("| "); Serial.print(LPG);
|
||||
Serial.print(" | "); Serial.print(CH4);
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
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
|
||||
Please make sure arduino A0 pin represents the analog input configured on #define pin
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
@ -25,12 +25,14 @@
|
||||
#include <MQUnifiedsensor.h>
|
||||
/************************Hardware Related Macros************************************/
|
||||
#define Board ("Arduino UNO")
|
||||
#define Pin (A9) //Analog input 4 of your arduino
|
||||
#define Pin (A0) //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
|
||||
#define PreaheatControlPin5 (3) // Preaheat pin to control with 5 volts
|
||||
#define PreaheatControlPin14 (4) // Preaheat pin to control with 1.4 volts
|
||||
/*****************************Globals***********************************************/
|
||||
//Declare Sensor
|
||||
MQUnifiedsensor MQ9(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin, Type);
|
||||
@ -38,10 +40,12 @@ MQUnifiedsensor MQ9(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin, Type);
|
||||
void setup() {
|
||||
//Init the serial port communication - to debug the library
|
||||
Serial.begin(9600); //Init serial port
|
||||
pinMode(PreaheatControlPin5, OUTPUT);
|
||||
pinMode(PreaheatControlPin14, OUTPUT);
|
||||
|
||||
//Set math model to calculate the PPM concentration and the value of constants
|
||||
MQ9.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
MQ9.setA(1000.5); MQ9.setB(-2.186); // Configurate the ecuation values to get LPG concentration
|
||||
MQ9.setA(1000.5); MQ9.setB(-2.186); // Configure the equation to to calculate LPG concentration
|
||||
|
||||
/*
|
||||
Exponential regression:
|
||||
@ -61,31 +65,57 @@ void setup() {
|
||||
*/
|
||||
/***************************** 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
|
||||
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
|
||||
// and on clean air (Calibration conditions), setting up R0 value.
|
||||
// We recomend executing this routine only on setup in laboratory conditions.
|
||||
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
|
||||
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||
// ISSUE 44 - MQ9 needs a low/high temperature cycle like MQ7 #44
|
||||
|
||||
Serial.println("Preheating, please wait 2.5 minutes");
|
||||
digitalWrite(PreaheatControlPin5, HIGH);
|
||||
digitalWrite(PreaheatControlPin14, LOW);
|
||||
delay(60000);
|
||||
digitalWrite(PreaheatControlPin5, LOW);
|
||||
digitalWrite(PreaheatControlPin14, HIGH);
|
||||
delay(90000);
|
||||
digitalWrite(PreaheatControlPin5, HIGH);
|
||||
digitalWrite(PreaheatControlPin14, LOW);
|
||||
delay(60000);
|
||||
digitalWrite(PreaheatControlPin5, LOW);
|
||||
digitalWrite(PreaheatControlPin14, HIGH);
|
||||
delay(90000);
|
||||
digitalWrite(PreaheatControlPin5, HIGH);
|
||||
digitalWrite(PreaheatControlPin14, LOW);
|
||||
|
||||
// End pre-heat cycle
|
||||
|
||||
Serial.print("Calibrating please wait.");
|
||||
float calcR0 = 0;
|
||||
for(int i = 1; i<=10; i ++)
|
||||
{
|
||||
MQ9.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ9.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
calcR0 += MQ9.calibrate(RatioMQ9CleanAir);
|
||||
Serial.print(".");
|
||||
}
|
||||
MQ9.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);}
|
||||
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
|
||||
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
|
||||
/***************************** MQ CAlibration ********************************************/
|
||||
MQ9.serialDebug(true);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
MQ9.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ9.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
digitalWrite(PreaheatControlPin5, LOW);
|
||||
digitalWrite(PreaheatControlPin14, HIGH);
|
||||
delay(90000);
|
||||
digitalWrite(PreaheatControlPin5, HIGH);
|
||||
digitalWrite(PreaheatControlPin14, LOW);
|
||||
|
||||
MQ9.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
MQ9.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
MQ9.serialDebug(); // Will print the table on the serial port
|
||||
delay(500); //Sampling frequency
|
||||
|
||||
}
|
@ -11,7 +11,7 @@
|
||||
|
||||
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
|
||||
Please make sure arduino A0 pin represents the analog input configured on #define pin
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
@ -61,50 +61,50 @@ void setup() {
|
||||
//init the sensor
|
||||
MQ2.init();
|
||||
MQ2.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
MQ2.setA(574.25); MQ2.setB(-2.222); // Configurate the ecuation values to get LPG concentration
|
||||
MQ2.setA(574.25); MQ2.setB(-2.222); // Configure the equation to to calculate LPG concentration
|
||||
MQ2.setR0(9.659574468);
|
||||
|
||||
MQ3.init();
|
||||
MQ3.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
MQ3.setA(0.3934); MQ3.setB(-1.504); // Configurate the ecuation values to get Alcohol concentration
|
||||
MQ3.setA(0.3934); MQ3.setB(-1.504); //Configure the equation to calculate Alcohol concentration value
|
||||
MQ3.setR0(3.86018237);
|
||||
|
||||
MQ4.init();
|
||||
MQ4.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
MQ4.setA(1012.7); MQ4.setB(-2.786); // Configurate the ecuation values to get CH4 concentration
|
||||
MQ4.setA(1012.7); MQ4.setB(-2.786); // Configure the equation to to calculate CH4 concentration
|
||||
MQ4.setR0(3.86018237);
|
||||
|
||||
MQ5.init();
|
||||
MQ5.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
MQ5.setA(97124); MQ5.setB(-4.918); // Configurate the ecuation values to get Alcohol concentration
|
||||
MQ5.setA(97124); MQ5.setB(-4.918); //Configure the equation to calculate Alcohol concentration value
|
||||
MQ5.setR0(71.100304);
|
||||
|
||||
MQ6.init();
|
||||
MQ6.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
MQ6.setA(2127.2); MQ6.setB(-2.526); // Configurate the ecuation values to get CH4 concentration
|
||||
MQ6.setA(2127.2); MQ6.setB(-2.526); // Configure the equation to to calculate CH4 concentration
|
||||
MQ6.setR0(13.4285714);
|
||||
|
||||
MQ7.init();
|
||||
MQ7.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
MQ7.setA(99.042); MQ7.setB(-1.518); // Configurate the ecuation values to get CO concentration
|
||||
MQ7.setA(99.042); MQ7.setB(-1.518); // Configure the equation to calculate CO concentration value
|
||||
MQ7.setR0(4);
|
||||
|
||||
MQ8.init();
|
||||
MQ8.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
MQ8.setA(976.97); MQ8.setB(-0.688); // Configurate the ecuation values to get H2 concentration
|
||||
MQ8.setA(976.97); MQ8.setB(-0.688); // Configure the equation to to calculate H2 concentration
|
||||
MQ8.setR0(1);
|
||||
|
||||
MQ9.init();
|
||||
MQ9.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
MQ9.setA(1000.5); MQ9.setB(-2.186); // Configurate the ecuation values to get LPG concentration
|
||||
MQ9.setA(1000.5); MQ9.setB(-2.186); // Configure the equation to to calculate LPG concentration
|
||||
MQ9.setR0(9.42857143);
|
||||
|
||||
/***************************** MQ CAlibration ********************************************/
|
||||
// Explanation:
|
||||
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
|
||||
// and now is on clean air (Calibration conditions), and it will setup R0 value.
|
||||
// We recomend execute this routine only on setup or on the laboratory and save on the eeprom of your arduino
|
||||
// This routine not need to execute to every restart, you can load your R0 if you know the value
|
||||
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
|
||||
// and on clean air (Calibration conditions), setting up R0 value.
|
||||
// We recomend executing this routine only on setup in laboratory conditions.
|
||||
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
|
||||
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||
Serial.print("Calibrating please wait.");
|
||||
float MQ2calcR0 = 0,
|
||||
@ -117,7 +117,7 @@ void setup() {
|
||||
MQ9calcR0 = 0;
|
||||
for(int i = 1; i<=10; i ++)
|
||||
{
|
||||
//Update the voltage lectures
|
||||
//Update the voltage Values
|
||||
MQ2.update();
|
||||
MQ3.update();
|
||||
MQ4.update();
|
||||
@ -164,7 +164,7 @@ void setup() {
|
||||
|
||||
//Print in serial monitor
|
||||
Serial.println("MQ2 to MQ9 - lecture");
|
||||
Serial.println("*************************** Lectures from MQ-board ***************************");
|
||||
Serial.println("*************************** Values from MQ-board ***************************");
|
||||
Serial.println("| LPG | Alcohol | CH4 | Alcohol | CH4 | CO | H2 | LPG |");
|
||||
Serial.println("| MQ-2 | MQ-3 | MQ-4 | MQ-5 | MQ-6 | MQ-7 | MQ-8 | MQ-9 |");
|
||||
//pinMode(calibration_button, INPUT);
|
||||
@ -192,7 +192,7 @@ void loop() {
|
||||
|
||||
void readAllSensors()
|
||||
{
|
||||
//Update the voltage lectures
|
||||
//Update the voltage Values
|
||||
MQ2.update();
|
||||
MQ3.update();
|
||||
MQ4.update();
|
||||
|
124
examples/MQ135-ADS1115/MQ135-ADS1115.ino
Normal file
124
examples/MQ135-ADS1115/MQ135-ADS1115.ino
Normal file
@ -0,0 +1,124 @@
|
||||
/*
|
||||
MQUnifiedsensor Library - reading an MQ135
|
||||
Demonstrates the use a MQ135 sensor.
|
||||
Library originally added 01 may 2019
|
||||
by Miguel A Califa, Yersson Carrillo, Ghiordy Contreras, Mario Rodriguez
|
||||
|
||||
Added example
|
||||
modified 20 March 2022
|
||||
by Miguel Califa
|
||||
|
||||
Wiring:
|
||||
https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/static/img/MQ_Arduino.PNG
|
||||
Please make sure arduino A0 pin represents the analog input configured on #define pin
|
||||
This example code is in the public domain.
|
||||
|
||||
Library link https://github.com/adafruit/Adafruit_ADS1X15
|
||||
*/
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_ADS1X15.h>
|
||||
//Include the library
|
||||
#include <MQUnifiedsensor.h>
|
||||
//Definitions
|
||||
#define placa "Arduino UNO"
|
||||
#define type "MQ-135" //MQ135
|
||||
#define RatioMQ135CleanAir 3.6//RS / R0 = 3.6 ppm
|
||||
float factorEscala = 0.1875F;
|
||||
//#define calibration_button 13 //Pin to calibrate your sensor
|
||||
//Declare Sensor
|
||||
MQUnifiedsensor MQ135(placa, type);
|
||||
|
||||
|
||||
// Crear objeto de la clase
|
||||
Adafruit_ADS1115 ads;
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
//Init the serial port communication - to debug the library
|
||||
Serial.begin(9600); //Init serial port
|
||||
delay(200);
|
||||
|
||||
//Set math model to calculate the PPM concentration and the value of constants
|
||||
MQ135.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
|
||||
/************************************************************************************/
|
||||
MQ135.init();
|
||||
|
||||
// Iniciar el ADS1115
|
||||
ads.begin();
|
||||
|
||||
|
||||
Serial.print("Calibrating please wait.");
|
||||
float calcR0 = 0;
|
||||
for(int i = 1; i<=10; i ++)
|
||||
{
|
||||
// Obtener datos del A0 del ADS1115
|
||||
short adc0 = ads.readADC_SingleEnded(0);
|
||||
float voltios = (adc0 * factorEscala)/1000.0;
|
||||
MQ135.externalADCUpdate(voltios); // Update data, the arduino will read the voltage from the analog pin
|
||||
calcR0 += MQ135.calibrate(RatioMQ135CleanAir);
|
||||
Serial.print(".");
|
||||
}
|
||||
MQ135.setR0(calcR0/10);
|
||||
Serial.println(" done!.");
|
||||
|
||||
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
|
||||
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
|
||||
/***************************** MQ CAlibration ********************************************/
|
||||
Serial.println("** Values from MQ-135 ****");
|
||||
Serial.println("| CO | Alcohol | CO2 | Toluen | NH4 | Aceton |");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Obtener datos del A0 del ADS1115
|
||||
short adc0 = ads.readADC_SingleEnded(0);
|
||||
float voltios = (adc0 * factorEscala)/1000.0;
|
||||
MQ135.externalADCUpdate(voltios); // Update data, the arduino will read the voltage from the analog pin
|
||||
|
||||
MQ135.setA(605.18); MQ135.setB(-3.937); // Configure the equation to calculate CO concentration value
|
||||
float CO = MQ135.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
|
||||
MQ135.setA(77.255); MQ135.setB(-3.18); //Configure the equation to calculate Alcohol concentration value
|
||||
float Alcohol = MQ135.readSensor(); // SSensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
|
||||
MQ135.setA(110.47); MQ135.setB(-2.862); // Configure the equation to calculate CO2 concentration value
|
||||
float CO2 = MQ135.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
|
||||
MQ135.setA(44.947); MQ135.setB(-3.445); // Configure the equation to calculate Toluen concentration value
|
||||
float Toluen = MQ135.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
|
||||
MQ135.setA(102.2 ); MQ135.setB(-2.473); // Configure the equation to calculate NH4 concentration value
|
||||
float NH4 = MQ135.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
|
||||
MQ135.setA(34.668); MQ135.setB(-3.369); // Configure the equation to calculate Aceton concentration value
|
||||
float Aceton = MQ135.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
Serial.print("| "); Serial.print(CO);
|
||||
Serial.print(" | "); Serial.print(Alcohol);
|
||||
// Note: 200 Offset for CO2 source: https://github.com/miguel5612/MQSensorsLib/issues/29
|
||||
|
||||
|
||||
|
||||
/*
|
||||
Motivation:
|
||||
We have added 200 PPM because when the library is calibrated it assumes the current state of the
|
||||
air as 0 PPM, and it is considered today that the CO2 present in the atmosphere is around 400 PPM.
|
||||
https://www.lavanguardia.com/natural/20190514/462242832581/concentracion-dioxido-cabono-co2-atmosfera-bate-record-historia-humanidad.html
|
||||
*/
|
||||
Serial.print(" | "); Serial.print(CO2 + 400);
|
||||
Serial.print(" | "); Serial.print(Toluen);
|
||||
Serial.print(" | "); Serial.print(NH4);
|
||||
Serial.print(" | "); Serial.print(Aceton);
|
||||
Serial.println(" |");
|
||||
/*
|
||||
Exponential regression:
|
||||
GAS | a | b
|
||||
CO | 605.18 | -3.937
|
||||
Alcohol | 77.255 | -3.18
|
||||
CO2 | 110.47 | -2.862
|
||||
Toluen | 44.947 | -3.445
|
||||
NH4 | 102.2 | -2.473
|
||||
Aceton | 34.668 | -3.369
|
||||
*/
|
||||
|
||||
delay(500); //Sampling frequency
|
||||
}
|
272
examples/UnitTesting/UnitTesting.ino
Normal file
272
examples/UnitTesting/UnitTesting.ino
Normal file
@ -0,0 +1,272 @@
|
||||
/*
|
||||
MQUnifiedsensor Library - testing library
|
||||
|
||||
Library originally added 01 may 2019
|
||||
by Miguel A Califa, Yersson Carrillo, Ghiordy Contreras, Mario Rodriguez
|
||||
|
||||
Added example
|
||||
modified 21 March 2022
|
||||
by Miguel Califa
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
*/
|
||||
|
||||
//Include the library
|
||||
#include <MQUnifiedsensor.h>
|
||||
#line 2 "basic.ino"
|
||||
#include <ArduinoUnit.h>
|
||||
|
||||
/************************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 Pin10 (A10) //Analog input 9 of your arduino
|
||||
#define Pin11 (A11) //Analog input 9 of your arduino
|
||||
#define Pin12 (A12) //Analog input 9 of your arduino
|
||||
#define Pin13 (A13) //Analog input 9 of your arduino
|
||||
#define Pin14 (A14) //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 RatioMQ136CleanAir (3.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(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);
|
||||
MQUnifiedsensor MQ131(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin10, Type); //mq131
|
||||
MQUnifiedsensor MQ135(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin11, Type); //mq135
|
||||
MQUnifiedsensor MQ136(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin12, Type); //mq136
|
||||
MQUnifiedsensor MQ303A(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin13, Type); //mq303
|
||||
MQUnifiedsensor MQ309A(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin14, Type); //mq309
|
||||
|
||||
|
||||
test(adcMaxValue)
|
||||
{
|
||||
int adcVal=1023;
|
||||
int volt = MQ2.getVoltage(false, true, adcVal);
|
||||
int expVolt = 5;
|
||||
assertEqual(volt,expVolt);
|
||||
}
|
||||
|
||||
test(adcMinValue)
|
||||
{
|
||||
int adcVal=0;
|
||||
int volt = MQ2.getVoltage(false, true, adcVal);
|
||||
int expVolt = 0;
|
||||
assertEqual(volt,expVolt);
|
||||
}
|
||||
|
||||
test(adcMidValue)
|
||||
{
|
||||
int adcVal=410;
|
||||
int volt = MQ2.getVoltage(false, true, adcVal);
|
||||
int expVolt = 2;
|
||||
assertEqual(volt,expVolt);
|
||||
}
|
||||
|
||||
test(MQ2_LPG)
|
||||
{
|
||||
MQ2.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
MQ2.setA(574.25); MQ2.setB(-2.222); // Configure the equation to to calculate LPG concentration
|
||||
MQ2.init();
|
||||
MQ2.setR0(10);
|
||||
|
||||
int ppmExp=464;
|
||||
int PPM = MQ2.setRsR0RatioGetPPM(1.1); // Send and Rs/R0 and return PPM (Using datasheet)
|
||||
|
||||
assertEqual(PPM,ppmExp);
|
||||
}
|
||||
|
||||
test(MQ3_Alcohol)
|
||||
{
|
||||
MQ3.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
MQ3.setA(0.3934); MQ3.setB(-1.504); // Configure the equation to to calculate Alcohol concentration
|
||||
MQ3.init();
|
||||
MQ3.setR0(10);
|
||||
|
||||
int ppmExp=4;
|
||||
int PPM = MQ3.setRsR0RatioGetPPM(0.2); // Send and Rs/R0 and return PPM (Using datasheet)
|
||||
|
||||
assertEqual(PPM,ppmExp);
|
||||
}
|
||||
|
||||
|
||||
test(MQ4_Smoke)
|
||||
{
|
||||
MQ4.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
MQ4.setA(30000000); MQ4.setB(-8.31); // Configure the equation to to calculate Smoke concentration
|
||||
MQ4.init();
|
||||
MQ4.setR0(10);
|
||||
|
||||
int ppmExp=297;
|
||||
int PPM = MQ4.setRsR0RatioGetPPM(4); // Send and Rs/R0 and return PPM (Using datasheet)
|
||||
|
||||
assertEqual(PPM,ppmExp);
|
||||
}
|
||||
|
||||
test(MQ5_LPG)
|
||||
{
|
||||
MQ5.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
MQ5.setA(80.897); MQ5.setB(-2.431); // Configure the equation to to calculate LPG concentration
|
||||
MQ5.init();
|
||||
MQ5.setR0(10);
|
||||
|
||||
int ppmExp=192;
|
||||
int PPM = MQ5.setRsR0RatioGetPPM(0.7); // Send and Rs/R0 and return PPM (Using datasheet)
|
||||
|
||||
assertEqual(PPM,ppmExp);
|
||||
}
|
||||
|
||||
test(MQ6_CH4)
|
||||
{
|
||||
MQ6.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
MQ6.setA(2127.2); MQ6.setB(-2.526); // Configure the equation to to calculate CH4 concentration
|
||||
MQ6.init();
|
||||
MQ6.setR0(10);
|
||||
|
||||
int ppmExp=2127;
|
||||
int PPM = MQ6.setRsR0RatioGetPPM(1); // Send and Rs/R0 and return PPM (Using datasheet)
|
||||
|
||||
assertEqual(PPM,ppmExp);
|
||||
}
|
||||
|
||||
test(MQ7_CH4)
|
||||
{
|
||||
MQ7.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
MQ7.setA(99.042); MQ7.setB(-1.518); // Configure the equation to to calculate CH4 concentration
|
||||
MQ7.init();
|
||||
MQ7.setR0(10);
|
||||
|
||||
int ppmExp=1139;
|
||||
int PPM = MQ7.setRsR0RatioGetPPM(0.2); // Send and Rs/R0 and return PPM (Using datasheet)
|
||||
|
||||
assertEqual(PPM,ppmExp);
|
||||
}
|
||||
|
||||
test(MQ8_H2)
|
||||
{
|
||||
MQ8.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
MQ8.setA(976.97); MQ8.setB(-0.688); // Configure the equation to to calculate H2 concentration
|
||||
MQ8.init();
|
||||
MQ8.setR0(10);
|
||||
|
||||
int ppmExp=2956;
|
||||
int PPM = MQ8.setRsR0RatioGetPPM(0.2); // Send and Rs/R0 and return PPM (Using datasheet)
|
||||
|
||||
assertEqual(PPM,ppmExp);
|
||||
}
|
||||
|
||||
|
||||
test(MQ9_CO)
|
||||
{
|
||||
MQ9.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
MQ9.setA(599.65); MQ9.setB(-2.244); // Configure the equation to to calculate CO concentration
|
||||
MQ9.init();
|
||||
MQ9.setR0(10);
|
||||
|
||||
int ppmExp=989;
|
||||
int PPM = MQ9.setRsR0RatioGetPPM(0.8); // Send and Rs/R0 and return PPM (Using datasheet)
|
||||
|
||||
assertEqual(PPM,ppmExp);
|
||||
}
|
||||
|
||||
test(MQ131_O3)
|
||||
{
|
||||
MQ131.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
MQ131.setA(23.943); MQ131.setB(-1.11); // Configure the equation to to calculate O3 concentration
|
||||
MQ131.init();
|
||||
MQ131.setR0(10);
|
||||
|
||||
int ppmExp=11;
|
||||
int PPM = MQ131.setRsR0RatioGetPPM(2); // Send and Rs/R0 and return PPM (Using datasheet)
|
||||
|
||||
assertEqual(PPM,ppmExp);
|
||||
}
|
||||
|
||||
|
||||
test(MQ135_CO2)
|
||||
{
|
||||
MQ135.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
MQ135.setA(110.47); MQ135.setB(-2.862); // Configure the equation to to calculate CO2 concentration
|
||||
MQ135.init();
|
||||
MQ135.setR0(10);
|
||||
|
||||
int ppmExp=110;
|
||||
int PPM = MQ135.setRsR0RatioGetPPM(1); // Send and Rs/R0 and return PPM (Using datasheet)
|
||||
|
||||
assertEqual(PPM,ppmExp);
|
||||
}
|
||||
|
||||
test(MQ136_H2S)
|
||||
{
|
||||
MQ136.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
MQ136.setA(36.737); MQ136.setB(-3.536); // Configure the equation to to calculate H2S concentration
|
||||
MQ136.init();
|
||||
MQ136.setR0(10);
|
||||
|
||||
int ppmExp=223;
|
||||
int PPM = MQ136.setRsR0RatioGetPPM(0.6); // Send and Rs/R0 and return PPM (Using datasheet)
|
||||
|
||||
assertEqual(PPM,ppmExp);
|
||||
}
|
||||
|
||||
test(MQ303A_Ethanol)
|
||||
{
|
||||
MQ303A.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
MQ303A.setA(3.4916); MQ303A.setB(-2.432); // Configure the equation to to calculate Ethanol concentration
|
||||
MQ303A.init();
|
||||
MQ303A.setR0(10);
|
||||
|
||||
int ppmExp=944;
|
||||
int PPM = MQ303A.setRsR0RatioGetPPM(0.1); // Send and Rs/R0 and return PPM (Using datasheet)
|
||||
|
||||
assertEqual(PPM,ppmExp);
|
||||
}
|
||||
|
||||
test(MQ309A_CO)
|
||||
{
|
||||
MQ309A.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
MQ309A.setA(1000000); MQ309A.setB(-4.01); // Configure the equation to to calculate CO concentration
|
||||
MQ309A.init();
|
||||
MQ309A.setR0(10);
|
||||
|
||||
int ppmExp=757;
|
||||
int PPM = MQ309A.setRsR0RatioGetPPM(6); // Send and Rs/R0 and return PPM (Using datasheet)
|
||||
|
||||
assertEqual(PPM,ppmExp);
|
||||
}
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
while(!Serial) {} // Portability for Leonardo/Micro
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Test::run();
|
||||
}
|
@ -15,7 +15,7 @@
|
||||
|
||||
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 - For this example this doesn't matter
|
||||
Please make sure arduino A0 pin represents 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.
|
||||
@ -52,7 +52,7 @@ void setup() {
|
||||
|
||||
//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
|
||||
MQ3.setA(4.8387); MQ3.setB(-2.68); // Configure the equation to to calculate Benzene concentration
|
||||
/*
|
||||
Exponential regression:
|
||||
Gas | a | b
|
||||
@ -72,25 +72,25 @@ void setup() {
|
||||
|
||||
/***************************** 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
|
||||
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
|
||||
// and on clean air (Calibration conditions), setting up R0 value.
|
||||
// We recomend executing this routine only on setup in laboratory conditions.
|
||||
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
|
||||
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||
Serial.print("Calibrating please wait.");
|
||||
float calcR0 = 0;
|
||||
for(int i = 1; i<=10; i ++)
|
||||
{
|
||||
int yourA2DValue = random(0, 1024); // 10-bit emulation
|
||||
MQ3.setADC(yourA2DValue);// Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ3.setADC(yourA2DValue);// Update data, the arduino will read the voltage from 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);}
|
||||
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
|
||||
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
|
||||
/***************************** MQ CAlibration ********************************************/
|
||||
|
||||
MQ3.serialDebug(true);
|
||||
@ -98,8 +98,8 @@ void setup() {
|
||||
|
||||
void loop() {
|
||||
int yourA2DValue = random(0, 1024); // 10-bit emulation
|
||||
MQ3.setADC(yourA2DValue); // 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.setADC(yourA2DValue); // Update data, the arduino will read the voltage from the analog pin
|
||||
MQ3.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
MQ3.serialDebug(); // Will print the table on the serial port
|
||||
delay(500); //Sampling frequency
|
||||
}
|
@ -11,7 +11,7 @@
|
||||
|
||||
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
|
||||
Please make sure arduino A0 pin represents the analog input configured on #define pin
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
@ -37,7 +37,7 @@ void setup() {
|
||||
Serial.begin(115200);
|
||||
//Set math model to calculate the PPM concentration and the value of constants
|
||||
MQ4.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
MQ4.setA(30000000); MQ4.setB(-8.308); // Configurate the ecuation values to get CH4 concentration
|
||||
MQ4.setA(30000000); MQ4.setB(-8.308); // Configure the equation to to calculate CH4 concentration
|
||||
/*
|
||||
Exponential regression:
|
||||
Gas | a | b
|
||||
@ -57,24 +57,24 @@ void setup() {
|
||||
*/
|
||||
/***************************** 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
|
||||
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
|
||||
// and on clean air (Calibration conditions), setting up R0 value.
|
||||
// We recomend executing this routine only on setup in laboratory conditions.
|
||||
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
|
||||
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||
Serial.print("Calibrating please wait.");
|
||||
float calcR0 = 0;
|
||||
for(int i = 1; i<=10; i ++)
|
||||
{
|
||||
MQ4.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ4.update(); // Update data, the arduino will read the voltage from the analog pin
|
||||
calcR0 += MQ4.calibrate(RatioMQ4CleanAir);
|
||||
Serial.print(".");
|
||||
}
|
||||
MQ4.setR0(calcR0/10);
|
||||
Serial.println(" done!.");
|
||||
|
||||
if(isinf(calcR0)) {Serial.println("Warning: Conection issue founded, R0 is infite (Open circuit detected) please check your wiring and supply"); while(1);}
|
||||
if(calcR0 == 0){Serial.println("Warning: Conection issue founded, R0 is zero (Analog pin with short circuit to ground) please check your wiring and supply"); while(1);}
|
||||
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
|
||||
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
|
||||
/***************************** MQ CAlibration ********************************************/
|
||||
MQ4.serialDebug(true);
|
||||
}
|
||||
@ -88,8 +88,8 @@ void setup() {
|
||||
//Read the sensor and print in serial port
|
||||
//Lecture will be saved in lecture variable
|
||||
MQ4.update();
|
||||
float smokePPM = MQ4.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
if(smokePPM > 1000) {Serial.println("Warning: High concentrations of smoke detected")};
|
||||
float smokePPM = MQ4.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
|
||||
if(smokePPM > 1000) {Serial.println("Warning: High concentrations of smoke detected");}
|
||||
MQ4.serialDebug(); // Will print the table on the serial port
|
||||
delay(400);
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
name=MQUnifiedsensor
|
||||
version=2.0.1
|
||||
version=3.0.0
|
||||
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.
|
||||
category= Sensors
|
||||
url=https://github.com/miguel5612/MQSensorsLib
|
||||
architectures=avr
|
||||
architectures=avr,esp8266,esp32
|
||||
license=MIT
|
||||
|
@ -1,14 +1,21 @@
|
||||
#include "MQUnifiedsensor.h"
|
||||
|
||||
#define retries 2
|
||||
#define retry_interval 20
|
||||
|
||||
MQUnifiedsensor::MQUnifiedsensor(String Placa, float Voltage_Resolution, int ADC_Bit_Resolution, int pin, String type) {
|
||||
this->_pin = pin;
|
||||
Placa.toCharArray(this->_placa, 20);
|
||||
type.toCharArray(this->_type, 6);
|
||||
type.toCharArray(this->_type, 7);
|
||||
//this->_type = type; //MQ-2, MQ-3 ... MQ-309A
|
||||
//this->_placa = Placa;
|
||||
this-> _VOLT_RESOLUTION = Voltage_Resolution;
|
||||
this-> _ADC_Bit_Resolution = ADC_Bit_Resolution;
|
||||
}
|
||||
MQUnifiedsensor::MQUnifiedsensor(String Placa, String type) {
|
||||
Placa.toCharArray(this->_placa, 20);
|
||||
type.toCharArray(this->_type, 7);
|
||||
}
|
||||
void MQUnifiedsensor::init()
|
||||
{
|
||||
pinMode(_pin, INPUT);
|
||||
@ -34,6 +41,9 @@ void MQUnifiedsensor::setVoltResolution(float voltage_resolution)
|
||||
{
|
||||
_VOLT_RESOLUTION = voltage_resolution;
|
||||
}
|
||||
void MQUnifiedsensor::setPin(int pin) {
|
||||
this->_pin = pin;
|
||||
}
|
||||
void MQUnifiedsensor::setRegressionMethod(int regressionMethod)
|
||||
{
|
||||
//this->_regressionMethod = regressionMethod;
|
||||
@ -108,6 +118,10 @@ void MQUnifiedsensor::update()
|
||||
{
|
||||
_sensor_volt = this->getVoltage();
|
||||
}
|
||||
void MQUnifiedsensor::externalADCUpdate(float volt)
|
||||
{
|
||||
_sensor_volt = volt;
|
||||
}
|
||||
float MQUnifiedsensor::validateEcuation(float ratioInput)
|
||||
{
|
||||
//Serial.print("Ratio input: "); Serial.println(ratioInput);
|
||||
@ -125,12 +139,16 @@ float MQUnifiedsensor::validateEcuation(float ratioInput)
|
||||
//Serial.println("Result: "); Serial.println(_PPM);
|
||||
return _PPM;
|
||||
}
|
||||
float MQUnifiedsensor::readSensor()
|
||||
float MQUnifiedsensor::readSensor(bool isMQ303A, float correctionFactor, bool injected)
|
||||
{
|
||||
//More explained in: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||
if(isMQ303A) {
|
||||
_VOLT_RESOLUTION = _VOLT_RESOLUTION - 0.45; //Calculations for RS using mq303a sensor look wrong #42
|
||||
}
|
||||
_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 = _RS_Calc / this->_R0; // Get ratio RS_gas/RS_air
|
||||
if(!injected) _ratio = _RS_Calc / this->_R0; // Get ratio RS_gas/RS_air
|
||||
_ratio += correctionFactor;
|
||||
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
|
||||
@ -182,7 +200,7 @@ float MQUnifiedsensor::calibrate(float ratioInCleanAir) {
|
||||
if(R0 < 0) R0 = 0; //No negative values accepted.
|
||||
return R0;
|
||||
}
|
||||
float MQUnifiedsensor::getVoltage(int read) {
|
||||
float MQUnifiedsensor::getVoltage(bool read, bool injected, int value) {
|
||||
float voltage;
|
||||
if(read)
|
||||
{
|
||||
@ -194,13 +212,31 @@ float MQUnifiedsensor::getVoltage(int read) {
|
||||
}
|
||||
voltage = (avg/ retries) * _VOLT_RESOLUTION / ((pow(2, _ADC_Bit_Resolution)) - 1);
|
||||
}
|
||||
else
|
||||
else if(!injected)
|
||||
{
|
||||
voltage = _sensor_volt;
|
||||
}
|
||||
else
|
||||
{
|
||||
voltage = (value) * _VOLT_RESOLUTION / ((pow(2, _ADC_Bit_Resolution)) - 1);
|
||||
_sensor_volt = voltage; //to work on testing
|
||||
}
|
||||
return voltage;
|
||||
}
|
||||
float MQUnifiedsensor:: setRsR0RatioGetPPM(float value)
|
||||
{
|
||||
_ratio = value;
|
||||
return readSensor(false, 0, true);
|
||||
}
|
||||
float MQUnifiedsensor::getRS()
|
||||
{
|
||||
//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.
|
||||
return _RS_Calc;
|
||||
}
|
||||
|
||||
float MQUnifiedsensor::stringTofloat(String & str)
|
||||
{
|
||||
return atof( str.c_str() );
|
||||
}
|
||||
}
|
||||
|
@ -6,30 +6,29 @@
|
||||
|
||||
/***********************Software Related Macros************************************/
|
||||
|
||||
#define ADC_RESOLUTION 10 // for 10bit analog to digital converter.
|
||||
#define retries 2
|
||||
#define retry_interval 20
|
||||
|
||||
class MQUnifiedsensor
|
||||
{
|
||||
public:
|
||||
MQUnifiedsensor(String Placa = "Arduino", float Voltage_Resolution = 5, int ADC_Bit_Resolution = 10, int pin = 1, String type = "CUSTOM MQ");
|
||||
MQUnifiedsensor(String Placa = "Arduino", String type = "CUSTOM MQ");
|
||||
|
||||
//Functions to set values
|
||||
void init();
|
||||
void update();
|
||||
void externalADCUpdate(float volt);
|
||||
void setR0(float R0 = 10);
|
||||
void setRL(float RL = 10);
|
||||
void setA(float a);
|
||||
void setB(float b);
|
||||
void setRegressionMethod(int regressionMethod);
|
||||
void setVoltResolution(float voltage_resolution = 5);
|
||||
void setPin(int pin = 1);
|
||||
void serialDebug(bool onSetup = false); //Show on serial port information about sensor
|
||||
void setADC(int value); //For external ADC Usage
|
||||
|
||||
//user functions
|
||||
float calibrate(float ratioInCleanAir);
|
||||
float readSensor();
|
||||
float readSensor(bool isMQ303A = false, float correctionFactor = 0.0, bool injected=false);
|
||||
float readSensorR0Rs();
|
||||
float validateEcuation(float ratioInput = 0);
|
||||
|
||||
@ -40,23 +39,26 @@ class MQUnifiedsensor
|
||||
float getRL();
|
||||
float getVoltResolution();
|
||||
String getRegressionMethod();
|
||||
float getVoltage(int read = true);
|
||||
|
||||
float stringTofloat(String & str);
|
||||
float getVoltage(bool read = true, bool injected = false, int value = 0);
|
||||
float stringTofloat(String & str);
|
||||
|
||||
// functions for testing
|
||||
float getRS();
|
||||
float setRsR0RatioGetPPM(float value);
|
||||
|
||||
private:
|
||||
/************************Private vars************************************/
|
||||
byte _pin;
|
||||
byte _pin = 1;
|
||||
byte _firstFlag = false;
|
||||
byte _VOLT_RESOLUTION = 5.0; // if 3.3v use 3.3
|
||||
byte _RL = 10; //Value in KiloOhms
|
||||
float _VOLT_RESOLUTION = 5.0; // if 3.3v use 3.3
|
||||
float _RL = 10; //Value in KiloOhms
|
||||
byte _ADC_Bit_Resolution = 10;
|
||||
byte _regressionMethod = 1; // 1 -> Exponential || 2 -> Linear
|
||||
|
||||
float _adc, _a, _b, _sensor_volt;
|
||||
float _R0, RS_air, _ratio, _PPM, _RS_Calc;
|
||||
|
||||
char _type[6];
|
||||
char _type[7];
|
||||
char _placa[20];
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user