Compare commits

..

10 Commits

8 changed files with 164 additions and 18 deletions

49
.github/pull_request_template.md vendored Normal file
View File

@ -0,0 +1,49 @@
# Description
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.
Fixes # (issue)
## Type of change
Please delete options that are not relevant.
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update
# How Has This Been Tested?
Please describe the examples that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
- [ ] MQ-3
- [ ] MQ-4
- [ ] MQ-5
- [ ] MQ-6
- [ ] MQ-7
- [ ] MQ-8
- [ ] MQ-9
- [ ] MQ-131
- [ ] MQ-135
- [ ] MQ-303
- [ ] MQ-309
- [ ] ESP8266
- [ ] ESP-32
**Test Configuration**:
* Board:
* Software (Version of your arduino):
* Result (Good - Medium - Bad):
* Your Comments:
# Checklist:
- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream modules

View File

@ -17,7 +17,7 @@
# MQSensorsLib # 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 -->
## 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) * [Wiring](#Wiring)
* [Sensor](#Sensor) * [Sensor](#Sensor)
* [Arduino](#Arduino) * [Arduino](#Arduino)
* [ESP8266](#ESP8266) * [ESP8266 or ESP-32](#ESP8266-ESP32)
* [User Manual](#usage) * [User Manual](#Manuals)
* [Sensor manufacturers](#Sensor-manufacturers) * [Sensor manufacturers](#Sensor-manufacturers)
* [Contributing](#Contributing) * [Contributing](#Contributing)
* [Authors](#Authors) * [Authors](#Authors)
@ -75,13 +75,16 @@ float ppmCH4 = MQ4.readSensor();
![Graph from datasheet](https://raw.githubusercontent.com/miguel5612/MQSensorsLib_Docs/master/static/img/Graph_Explanation.jpeg) ![Graph from datasheet](https://raw.githubusercontent.com/miguel5612/MQSensorsLib_Docs/master/static/img/Graph_Explanation.jpeg)
### Arduino ### Arduino
![Arduino_Wiring_MQSensor](https://raw.githubusercontent.com/miguel5612/MQSensorsLib_Docs/master/static/img/MQ_Arduino.PNG) ![Arduino_Wiring_MQSensor](https://raw.githubusercontent.com/miguel5612/MQSensorsLib_Docs/master/static/img/MQ_Arduino.PNG)
#### MQ-7 / MQ-309A
### ESP8266 ** 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 .
![MQ-7_MQ-309](https://raw.githubusercontent.com/miguel5612/MQSensorsLib_Docs/master/static/img/MQ-309_MQ-7.PNG)
### ESP8266-ESP32
![ESP8266_Wiring_MQSensor](https://raw.githubusercontent.com/miguel5612/MQSensorsLib_Docs/master/static/img/MQ_ESP8266.PNG) ![ESP8266_Wiring_MQSensor](https://raw.githubusercontent.com/miguel5612/MQSensorsLib_Docs/master/static/img/MQ_ESP8266.PNG)
### User Manual (v1.0) 12.2019 ### Manuals
#### User Manual (v1.0) 12.2019
[Manual](https://drive.google.com/open?id=1BAFInlvqKR7h81zETtjz4_RC2EssvFWX) [Manual](https://drive.google.com/open?id=1BAFInlvqKR7h81zETtjz4_RC2EssvFWX)
### User Manual (v2.0) 04.2020 #### User Manual (v2.0) 04.2020
[Manual](https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/Docs/MQSensorLib_2.0.pdf) [Manual](https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/Docs/MQSensorLib_2.0.pdf)

View File

@ -17,6 +17,8 @@
https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/static/img/MQ_Arduino.PNG 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 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. 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);} 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 ********************************************/ /***************************** MQ CAlibration ********************************************/
MQ131.serialDebug(true); 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() { void loop() {
MQ131.update(); // Update data, the arduino will be read the voltage on the analog pin MQ131.update(); // Update data, the arduino will be read the voltage on the analog pin
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 MQ131.serialDebug(); // Will print the table on the serial port
delay(500); //Sampling frequency delay(500); //Sampling frequency
} }

View File

@ -31,14 +31,16 @@
#define type "MQ-309" //MQ309 #define type "MQ-309" //MQ309
#define ADC_Bit_Resolution 10 // For arduino UNO/MEGA/NANO #define ADC_Bit_Resolution 10 // For arduino UNO/MEGA/NANO
#define RatioMQ309CleanAir 11 //RS / R0 = 11 ppm #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 //Declare Sensor
MQUnifiedsensor MQ309(placa, Voltage_Resolution, ADC_Bit_Resolution, pin, type); MQUnifiedsensor MQ309(placa, Voltage_Resolution, ADC_Bit_Resolution, pin, type);
unsigned long oldTime = 0;
void setup() { void setup() {
//Init the serial port communication - to debug the library //Init the serial port communication - to debug the library
Serial.begin(9600); //Init serial port Serial.begin(9600); //Init serial port
pinMode(PWMPin, OUTPUT);
//Set math model to calculate the PPM concentration and the value of constants //Set math model to calculate the PPM concentration and the value of constants
MQ309.setRegressionMethod(1); //_PPM = a*ratio^b MQ309.setRegressionMethod(1); //_PPM = a*ratio^b
@ -86,8 +88,28 @@ void setup() {
} }
void loop() { void loop() {
MQ309.update(); // Update data, the arduino will be read the voltage on the analog pin // 60s cycle
MQ309.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup oldTime = millis();
MQ309.serialDebug(); // Will print the table on the serial port while(millis() - oldTime <= (30*1000))
delay(500); //Sampling frequency {
// 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.
} }

View File

@ -13,6 +13,10 @@
modified 26 March 2020 modified 26 March 2020
by Miguel Califa by Miguel Califa
Updated example of MQ-7 AND MQ-309A
modified 20 April 2020
by Miguel Califa
Wiring: Wiring:
https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/static/img/MQ_Arduino.PNG 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 take care, arduino A0 pin represent the analog input configured on #define pin
@ -31,14 +35,16 @@
#define type "MQ-7" //MQ7 #define type "MQ-7" //MQ7
#define ADC_Bit_Resolution 10 // For arduino UNO/MEGA/NANO #define ADC_Bit_Resolution 10 // For arduino UNO/MEGA/NANO
#define RatioMQ7CleanAir 27.5 //RS / R0 = 27.5 ppm #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 //Declare Sensor
MQUnifiedsensor MQ7(placa, Voltage_Resolution, ADC_Bit_Resolution, pin, type); MQUnifiedsensor MQ7(placa, Voltage_Resolution, ADC_Bit_Resolution, pin, type);
unsigned long oldTime = 0;
void setup() { void setup() {
//Init the serial port communication - to debug the library //Init the serial port communication - to debug the library
Serial.begin(9600); //Init serial port Serial.begin(9600); //Init serial port
pinMode(PWMPin, OUTPUT);
//Set math model to calculate the PPM concentration and the value of constants //Set math model to calculate the PPM concentration and the value of constants
MQ7.setRegressionMethod(1); //_PPM = a*ratio^b MQ7.setRegressionMethod(1); //_PPM = a*ratio^b
@ -87,8 +93,28 @@ void setup() {
} }
void loop() { void loop() {
MQ7.update(); // Update data, the arduino will be read the voltage on the analog pin // 60s cycle
MQ7.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup oldTime = millis();
MQ7.serialDebug(); // Will print the table on the serial port while(millis() - oldTime <= (60*1000))
delay(500); //Sampling frequency {
// 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.
} }

View File

@ -29,6 +29,7 @@
#define Pin7 (A7) //Analog input 7 of your arduino #define Pin7 (A7) //Analog input 7 of your arduino
#define Pin8 (A8) //Analog input 8 of your arduino #define Pin8 (A8) //Analog input 8 of your arduino
#define Pin9 (A9) //Analog input 9 of your arduino #define Pin9 (A9) //Analog input 9 of your arduino
#define PWMPin (5) // Pin connected to mosfet
/***********************Software Related Macros************************************/ /***********************Software Related Macros************************************/
#define RatioMQ2CleanAir (9.83) //RS / R0 = 9.83 ppm #define RatioMQ2CleanAir (9.83) //RS / R0 = 9.83 ppm
#define RatioMQ3CleanAir (60) //RS / R0 = 60 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 MQ8(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin8, Type);
MQUnifiedsensor MQ9(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin9, Type); MQUnifiedsensor MQ9(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin9, Type);
unsigned long oldTime = 0;
void setup() { void setup() {
//Init serial port //Init serial port
Serial.begin(9600); Serial.begin(9600);
@ -168,6 +171,27 @@ void setup() {
} }
void loop() { 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 //Update the voltage lectures
MQ2.update(); MQ2.update();
MQ3.update(); MQ3.update();

View File

@ -143,6 +143,24 @@ float MQUnifiedsensor::readSensor()
//if(_PPM > 10000) _PPM = 99999999; //No negative values accepted or upper datasheet recomendation. //if(_PPM > 10000) _PPM = 99999999; //No negative values accepted or upper datasheet recomendation.
return _PPM; 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) { float MQUnifiedsensor::calibrate(float ratioInCleanAir) {
//More explained in: https://jayconsystems.com/blog/understanding-a-gas-sensor //More explained in: https://jayconsystems.com/blog/understanding-a-gas-sensor
/* /*

View File

@ -30,6 +30,7 @@ class MQUnifiedsensor
//user functions //user functions
float calibrate(float ratioInCleanAir); float calibrate(float ratioInCleanAir);
float readSensor(); float readSensor();
float readSensorR0Rs();
float validateEcuation(float ratioInput = 0); float validateEcuation(float ratioInput = 0);
//get function for info //get function for info