Compare commits
No commits in common. 'master' and 'v1.9.9' have entirely different histories.
@ -1,51 +0,0 @@
|
|||||||
# 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
|
|
||||||
- [ ] 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?
|
|
||||||
|
|
||||||
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
|
|
@ -1,136 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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
|
|
||||||
}
|
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 32 KiB |
Binary file not shown.
Before Width: | Height: | Size: 484 KiB |
@ -1,93 +0,0 @@
|
|||||||
// This is an example of implementation using ESP8266
|
|
||||||
// Never connect the sensor direct to the ESP8266, sensor high level is 5V
|
|
||||||
// ADC of ESP8266 high level is 3.3
|
|
||||||
// To connect use a voltage divisor, where 5V will 3v3 on the middle point like
|
|
||||||
// this {{URL}}
|
|
||||||
|
|
||||||
/*
|
|
||||||
MQUnifiedsensor Library - reading an MQSensor using ESP8266 board
|
|
||||||
|
|
||||||
For this example wi will demonstrates the use a MQ3 sensor.
|
|
||||||
Library originally added 01 may 2019
|
|
||||||
by Miguel A Califa, Yersson Carrillo, Ghiordy Contreras, Mario Rodriguez
|
|
||||||
|
|
||||||
Added ESP8266 example
|
|
||||||
29.03.2020
|
|
||||||
Wiring:
|
|
||||||
https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/static/img/MQ_ESP8266.PNG
|
|
||||||
|
|
||||||
This example code is in the public domain.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
//Include the library
|
|
||||||
#include <MQUnifiedsensor.h>
|
|
||||||
/************************Hardware Related Macros************************************/
|
|
||||||
#define Board ("ESP-32") // Wemos ESP-32 or other board, whatever have ESP32 core.
|
|
||||||
#define Pin (25) //IO25 for your ESP32 WeMos Board, pinout here: https://i.pinimg.com/originals/66/9a/61/669a618d9435c702f4b67e12c40a11b8.jpg
|
|
||||||
/***********************Software Related Macros************************************/
|
|
||||||
#define Type ("MQ-3") //MQ3 or other MQ Sensor, if change this verify your a and b values.
|
|
||||||
#define Voltage_Resolution (3.3) // 3V3 <- IMPORTANT. Source: https://randomnerdtutorials.com/esp32-adc-analog-read-arduino-ide/
|
|
||||||
#define ADC_Bit_Resolution (12) // ESP-32 bit resolution. Source: https://randomnerdtutorials.com/esp32-adc-analog-read-arduino-ide/
|
|
||||||
#define RatioMQ3CleanAir (60) // Ratio of your sensor, for this example an MQ-3
|
|
||||||
/*****************************Globals***********************************************/
|
|
||||||
MQUnifiedsensor MQ3(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin, Type);
|
|
||||||
/*****************************Globals***********************************************/
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
//Init the serial port communication - to debug the library
|
|
||||||
Serial.begin(9600); //Init serial port
|
|
||||||
|
|
||||||
//Set math model to calculate the PPM concentration and the value of constants
|
|
||||||
MQ3.setRegressionMethod(1); //_PPM = a*ratio^b
|
|
||||||
MQ3.setA(4.8387); MQ3.setB(-2.68); // Configure the equation to to calculate Benzene concentration
|
|
||||||
/*
|
|
||||||
Exponential regression:
|
|
||||||
Gas | a | b
|
|
||||||
LPG | 44771 | -3.245
|
|
||||||
CH4 | 2*10^31| 19.01
|
|
||||||
CO | 521853 | -3.821
|
|
||||||
Alcohol| 0.3934 | -1.504
|
|
||||||
Benzene| 4.8387 | -2.68
|
|
||||||
Hexane | 7585.3 | -2.849
|
|
||||||
*/
|
|
||||||
|
|
||||||
/***************************** MQ Init ********************************************/
|
|
||||||
//Remarks: Configure the pin of arduino as input.
|
|
||||||
/************************************************************************************/
|
|
||||||
MQ3.init();
|
|
||||||
|
|
||||||
/*
|
|
||||||
//If the RL value is different from 10K please assign your RL value with the following method:
|
|
||||||
MQ3.setRL(10);
|
|
||||||
*/
|
|
||||||
/***************************** MQ CAlibration ********************************************/
|
|
||||||
// Explanation:
|
|
||||||
// In this routine the sensor will measure the resistance of the sensor 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 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, 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 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
|
|
||||||
}
|
|
@ -1,183 +0,0 @@
|
|||||||
/*
|
|
||||||
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);
|
|
||||||
}
|
|
@ -1,88 +0,0 @@
|
|||||||
/*
|
|
||||||
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
|
|
||||||
}
|
|
@ -1,124 +0,0 @@
|
|||||||
/*
|
|
||||||
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
|
|
||||||
}
|
|
@ -1,272 +0,0 @@
|
|||||||
/*
|
|
||||||
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();
|
|
||||||
}
|
|
@ -1,10 +1,10 @@
|
|||||||
name=MQUnifiedsensor
|
name=MQUnifiedsensor
|
||||||
version=3.0.0
|
version=1.0.4
|
||||||
author= Miguel Califa <miguelangel5612@gmail.com>, Yersson Carrillo<miguelangel5612@gmail.com>, Ghiordy Contreras<miguelangel5612@gmail.com>
|
author= Miguel Califa <miguelangel5612@gmail.com>, Yersson Carrillo <miguelangel5612@gmail.com>, Ghiordy Contreras <miguelangel5612@gmail.com>
|
||||||
maintainer= Miguel Califa <miguelangel5612@gmail.com>
|
maintainer= Miguel Califa <miguelangel5612@gmail.com>
|
||||||
sentence= This library allows you to read the MQ sensors very easily.
|
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.
|
paragraph= This library allows an Arduino/Genuino board to read MQ Sensors (AIr quality meter) references: MQ2, MQ3, MQ4, MQ5, MQ6, MQ7, MQ8, MQ9, MQ131, MQ135, MQ303A, MQ309A.
|
||||||
category= Sensors
|
category= Sensors
|
||||||
url=https://github.com/miguel5612/MQSensorsLib
|
url=https://github.com/miguel5612/MQSensorsLib
|
||||||
architectures=avr,esp8266,esp32
|
architectures=avr
|
||||||
license=MIT
|
license=MIT
|
||||||
|
Loading…
Reference in New Issue