mirror of
https://github.com/miguel5612/MQSensorsLib.git
synced 2026-08-15 04:21:36 +08:00
Compare commits
17
Commits
v2.0.1
...
874be50106
@@ -0,0 +1,49 @@
|
||||
# Description
|
||||
|
||||
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.
|
||||
|
||||
Fixes # (issue)
|
||||
|
||||
## Type of change
|
||||
|
||||
Please delete options that are not relevant.
|
||||
|
||||
- [ ] Bug fix (non-breaking change which fixes an issue)
|
||||
- [ ] New feature (non-breaking change which adds functionality)
|
||||
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
|
||||
- [ ] This change requires a documentation update
|
||||
|
||||
# How Has This Been Tested?
|
||||
|
||||
Please describe the examples that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
|
||||
|
||||
- [ ] MQ-3
|
||||
- [ ] MQ-4
|
||||
- [ ] MQ-5
|
||||
- [ ] MQ-6
|
||||
- [ ] MQ-7
|
||||
- [ ] MQ-8
|
||||
- [ ] MQ-9
|
||||
- [ ] MQ-131
|
||||
- [ ] MQ-135
|
||||
- [ ] MQ-303
|
||||
- [ ] MQ-309
|
||||
- [ ] ESP8266
|
||||
- [ ] ESP-32
|
||||
|
||||
**Test Configuration**:
|
||||
* Board:
|
||||
* Software (Version of your arduino):
|
||||
* Result (Good - Medium - Bad):
|
||||
* Your Comments:
|
||||
|
||||
# Checklist:
|
||||
|
||||
- [ ] My code follows the style guidelines of this project
|
||||
- [ ] I have performed a self-review of my own code
|
||||
- [ ] I have commented my code, particularly in hard-to-understand areas
|
||||
- [ ] I have made corresponding changes to the documentation
|
||||
- [ ] My changes generate no new warnings
|
||||
- [ ] I have added tests that prove my fix is effective or that my feature works
|
||||
- [ ] New and existing unit tests pass locally with my changes
|
||||
- [ ] Any dependent changes have been merged and published in downstream modules
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
# MQSensorsLib
|
||||
|
||||
This is a unified library to use sensors MQ: 2, 3, 4, 5, 6, 7, 8, 9, 131, 135, 303A and 309A.
|
||||
We present a unified library for MQ sensors, this library allows to read MQ signals easily from Arduino, Genuino, ESP8266, ESP-32 boards whose references are MQ2, MQ3, MQ4, MQ5, MQ6, MQ7, MQ8, MQ9, MQ131, MQ135, MQ303A, MQ309A.
|
||||
|
||||
<!-- TABLE OF CONTENTS -->
|
||||
## Table of Contents
|
||||
@@ -26,8 +26,8 @@ This is a unified library to use sensors MQ: 2, 3, 4, 5, 6, 7, 8, 9, 131, 135, 3
|
||||
* [Wiring](#Wiring)
|
||||
* [Sensor](#Sensor)
|
||||
* [Arduino](#Arduino)
|
||||
* [ESP8266](#ESP8266)
|
||||
* [User Manual](#usage)
|
||||
* [ESP8266 or ESP-32](#ESP8266-ESP32)
|
||||
* [User Manual](#Manuals)
|
||||
* [Sensor manufacturers](#Sensor-manufacturers)
|
||||
* [Contributing](#Contributing)
|
||||
* [Authors](#Authors)
|
||||
@@ -75,15 +75,20 @@ float ppmCH4 = MQ4.readSensor();
|
||||

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

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

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

|
||||
|
||||
### User Manual (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)
|
||||
### 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):
|
||||
@@ -170,6 +175,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)
|
||||
|
||||
@@ -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); // Configurate the ecuation values to get 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 supposing before was pre-heated
|
||||
// and now is on clean air (Calibration conditions), and it will setup R0 value.
|
||||
// We recomend execute this routine only on setup or on the laboratory and save on the eeprom of your arduino
|
||||
// This routine not need to execute to every restart, you can load your R0 if you know the value
|
||||
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||
Serial.print("Calibrating please wait.");
|
||||
float calcR0 = 0;
|
||||
for(int i = 1; i<=10; i ++)
|
||||
{
|
||||
MQ2.update(); // Update data, the arduino will be read the voltage on 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);}
|
||||
/***************************** 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 be read the voltage on 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 and a and b values setted before or in the setup
|
||||
Serial.println(" PPM");
|
||||
delay(500); //Sampling frequency
|
||||
}
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 32 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 484 KiB |
@@ -17,6 +17,8 @@
|
||||
https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/static/img/MQ_Arduino.PNG
|
||||
Please take care, arduino A0 pin represent the analog input configured on #define pin
|
||||
|
||||
Note: high concentration MQ-131 sensor.
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
*/
|
||||
@@ -83,11 +85,12 @@ void setup() {
|
||||
if(calcR0 == 0){Serial.println("Warning: Conection issue founded, R0 is zero (Analog pin with short circuit to ground) please check your wiring and supply"); while(1);}
|
||||
/***************************** MQ CAlibration ********************************************/
|
||||
MQ131.serialDebug(true);
|
||||
Serial.println("Ignore Ratio = RS/R0, for this example we will use readSensorR0Rs, the ratio calculated will be R0/Rs. Thanks :)");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
MQ131.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ131.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
MQ131.readSensorR0Rs(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
MQ131.serialDebug(); // Will print the table on the serial port
|
||||
delay(500); //Sampling frequency
|
||||
}
|
||||
@@ -98,8 +98,15 @@ void loop() {
|
||||
float Acetona = MQ135.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
|
||||
Serial.print("| "); Serial.print(CO);
|
||||
Serial.print(" | "); Serial.print(Alcohol);
|
||||
Serial.print(" | "); Serial.print(CO2);
|
||||
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(Tolueno);
|
||||
Serial.print(" | "); Serial.print(NH4);
|
||||
Serial.print(" | "); Serial.print(Acetona);
|
||||
|
||||
@@ -31,14 +31,16 @@
|
||||
#define type "MQ-309" //MQ309
|
||||
#define ADC_Bit_Resolution 10 // For arduino UNO/MEGA/NANO
|
||||
#define RatioMQ309CleanAir 11 //RS / R0 = 11 ppm
|
||||
//#define calibration_button 13 //Pin to calibrate your sensor
|
||||
#define PWMPin 5 // Pin connected to mosfet
|
||||
|
||||
//Declare Sensor
|
||||
MQUnifiedsensor MQ309(placa, Voltage_Resolution, ADC_Bit_Resolution, pin, type);
|
||||
unsigned long oldTime = 0;
|
||||
|
||||
void setup() {
|
||||
//Init the serial port communication - to debug the library
|
||||
Serial.begin(9600); //Init serial port
|
||||
pinMode(PWMPin, OUTPUT);
|
||||
|
||||
//Set math model to calculate the PPM concentration and the value of constants
|
||||
MQ309.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
@@ -86,8 +88,28 @@ void setup() {
|
||||
}
|
||||
|
||||
void loop() {
|
||||
MQ309.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ309.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
MQ309.serialDebug(); // Will print the table on the serial port
|
||||
delay(500); //Sampling frequency
|
||||
// 60s cycle
|
||||
oldTime = millis();
|
||||
while(millis() - oldTime <= (30*1000))
|
||||
{
|
||||
// VH 0.9 Volts
|
||||
analogWrite(5, 2); // 255 is 100%, 2.295 is aprox 0.9% of Duty cycle for 60s
|
||||
MQ309.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ309.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
MQ309.serialDebug(); // Will print the table on the serial port
|
||||
delay(500); //Sampling frequency
|
||||
}
|
||||
|
||||
// 90s cycle
|
||||
oldTime = millis();
|
||||
while(millis() - oldTime <= (120*1000))
|
||||
{
|
||||
// VL 0.2 Volts
|
||||
analogWrite(5, 1); // 255 is 100%, 0.51 is aprox 0.2% of Duty cycle for 120s
|
||||
MQ309.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ309.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
MQ309.serialDebug(); // Will print the table on the serial port
|
||||
delay(500); //Sampling frequency
|
||||
}
|
||||
// Total: 30 + 120s = 2.5 minutes.
|
||||
}
|
||||
+31
-5
@@ -13,6 +13,10 @@
|
||||
modified 26 March 2020
|
||||
by Miguel Califa
|
||||
|
||||
Updated example of MQ-7 AND MQ-309A
|
||||
modified 20 April 2020
|
||||
by Miguel Califa
|
||||
|
||||
Wiring:
|
||||
https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/static/img/MQ_Arduino.PNG
|
||||
Please take care, arduino A0 pin represent the analog input configured on #define pin
|
||||
@@ -31,14 +35,16 @@
|
||||
#define type "MQ-7" //MQ7
|
||||
#define ADC_Bit_Resolution 10 // For arduino UNO/MEGA/NANO
|
||||
#define RatioMQ7CleanAir 27.5 //RS / R0 = 27.5 ppm
|
||||
//#define calibration_button 13 //Pin to calibrate your sensor
|
||||
#define PWMPin 5 // Pin connected to mosfet
|
||||
|
||||
//Declare Sensor
|
||||
MQUnifiedsensor MQ7(placa, Voltage_Resolution, ADC_Bit_Resolution, pin, type);
|
||||
unsigned long oldTime = 0;
|
||||
|
||||
void setup() {
|
||||
//Init the serial port communication - to debug the library
|
||||
Serial.begin(9600); //Init serial port
|
||||
pinMode(PWMPin, OUTPUT);
|
||||
|
||||
//Set math model to calculate the PPM concentration and the value of constants
|
||||
MQ7.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||
@@ -87,8 +93,28 @@ void setup() {
|
||||
}
|
||||
|
||||
void loop() {
|
||||
MQ7.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ7.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
MQ7.serialDebug(); // Will print the table on the serial port
|
||||
delay(500); //Sampling frequency
|
||||
// 60s cycle
|
||||
oldTime = millis();
|
||||
while(millis() - oldTime <= (60*1000))
|
||||
{
|
||||
// VH 5 Volts
|
||||
analogWrite(5, 255); // 255 is DC 5V output
|
||||
MQ7.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ7.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
MQ7.serialDebug(); // Will print the table on the serial port
|
||||
delay(500); //Sampling frequency
|
||||
}
|
||||
|
||||
// 90s cycle
|
||||
oldTime = millis();
|
||||
while(millis() - oldTime <= (90*1000))
|
||||
{
|
||||
// VH 1.4 Volts
|
||||
analogWrite(5, 20); // 255 is 100%, 20.4 is aprox 8% of Duty cycle for 90s
|
||||
MQ7.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||
MQ7.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||
MQ7.serialDebug(); // Will print the table on the serial port
|
||||
delay(500); //Sampling frequency
|
||||
}
|
||||
// Total: 60 + 90s = 2.5 minutes.
|
||||
}
|
||||
@@ -29,6 +29,7 @@
|
||||
#define Pin7 (A7) //Analog input 7 of your arduino
|
||||
#define Pin8 (A8) //Analog input 8 of your arduino
|
||||
#define Pin9 (A9) //Analog input 9 of your arduino
|
||||
#define PWMPin (5) // Pin connected to mosfet
|
||||
/***********************Software Related Macros************************************/
|
||||
#define RatioMQ2CleanAir (9.83) //RS / R0 = 9.83 ppm
|
||||
#define RatioMQ3CleanAir (60) //RS / R0 = 60 ppm
|
||||
@@ -52,6 +53,8 @@ MQUnifiedsensor MQ7(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin7, Type);
|
||||
MQUnifiedsensor MQ8(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin8, Type);
|
||||
MQUnifiedsensor MQ9(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin9, Type);
|
||||
|
||||
unsigned long oldTime = 0;
|
||||
|
||||
void setup() {
|
||||
//Init serial port
|
||||
Serial.begin(9600);
|
||||
@@ -168,6 +171,27 @@ void setup() {
|
||||
}
|
||||
|
||||
void loop() {
|
||||
oldTime = millis();
|
||||
while(millis() - oldTime <= (60*1000))
|
||||
{
|
||||
// VH 5 Volts
|
||||
analogWrite(5, 255); // 255 is DC 5V output
|
||||
readAllSensors();
|
||||
delay(500);
|
||||
}
|
||||
// 90s cycle
|
||||
oldTime = millis();
|
||||
while(millis() - oldTime <= (90*1000))
|
||||
{
|
||||
// VH 1.4 Volts
|
||||
analogWrite(5, 20); // 255 is 100%, 20.4 is aprox 8% of Duty cycle for 90s
|
||||
readAllSensors();
|
||||
delay(500);
|
||||
}
|
||||
}
|
||||
|
||||
void readAllSensors()
|
||||
{
|
||||
//Update the voltage lectures
|
||||
MQ2.update();
|
||||
MQ3.update();
|
||||
|
||||
+1
-1
@@ -6,5 +6,5 @@ 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
|
||||
|
||||
@@ -143,6 +143,24 @@ float MQUnifiedsensor::readSensor()
|
||||
//if(_PPM > 10000) _PPM = 99999999; //No negative values accepted or upper datasheet recomendation.
|
||||
return _PPM;
|
||||
}
|
||||
float MQUnifiedsensor::readSensorR0Rs()
|
||||
{
|
||||
//More explained in: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||
_RS_Calc = ((_VOLT_RESOLUTION*_RL)/_sensor_volt)-_RL; //Get value of RS in a gas
|
||||
if(_RS_Calc < 0) _RS_Calc = 0; //No negative values accepted.
|
||||
_ratio = this->_R0/_RS_Calc; // Get ratio RS_air/RS_gas <- INVERTED for MQ-131 issue 28 https://github.com/miguel5612/MQSensorsLib/issues/28
|
||||
if(_ratio <= 0) _ratio = 0; //No negative values accepted or upper datasheet recomendation.
|
||||
if(_regressionMethod == 1) _PPM= _a*pow(_ratio, _b); // <- Source excel analisis https://github.com/miguel5612/MQSensorsLib_Docs/tree/master/Internal_design_documents
|
||||
else
|
||||
{
|
||||
// https://jayconsystems.com/blog/understanding-a-gas-sensor <- Source of linear ecuation
|
||||
double ppm_log = (log10(_ratio)-_b)/_a; //Get ppm value in linear scale according to the the ratio value
|
||||
_PPM = pow(10, ppm_log); //Convert ppm value to log scale
|
||||
}
|
||||
if(_PPM < 0) _PPM = 0; //No negative values accepted or upper datasheet recomendation.
|
||||
//if(_PPM > 10000) _PPM = 99999999; //No negative values accepted or upper datasheet recomendation.
|
||||
return _PPM;
|
||||
}
|
||||
float MQUnifiedsensor::calibrate(float ratioInCleanAir) {
|
||||
//More explained in: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||
/*
|
||||
|
||||
@@ -30,6 +30,7 @@ class MQUnifiedsensor
|
||||
//user functions
|
||||
float calibrate(float ratioInCleanAir);
|
||||
float readSensor();
|
||||
float readSensorR0Rs();
|
||||
float validateEcuation(float ratioInput = 0);
|
||||
|
||||
//get function for info
|
||||
|
||||
Reference in New Issue
Block a user