mirror of
https://github.com/miguel5612/MQSensorsLib.git
synced 2025-03-15 05:17:30 +03:00
Updated constants
This commit is contained in:
parent
4c0c92f8a7
commit
8a929cff7f
Binary file not shown.
@ -90,6 +90,10 @@
|
||||
//_MQ = MQ309;
|
||||
}
|
||||
}
|
||||
void MQUnifiedsensor::update()
|
||||
{
|
||||
_sensor_volt = this->getVoltage();
|
||||
}
|
||||
void MQUnifiedsensor::setVoltResolution(float voltaje)
|
||||
{
|
||||
_VOLT_RESOLUTION = voltaje;
|
||||
@ -100,18 +104,19 @@ void MQUnifiedsensor::inicializar()
|
||||
}
|
||||
int MQUnifiedsensor::readSensor(String nameLectureRequeired, bool print)
|
||||
{
|
||||
setSensorCharacteristics(nameLectureRequeired, print);
|
||||
_PPM =readPPM(_m, _b);
|
||||
setSensorCharacteristics(nameLectureRequeired, print); //In this function update _a and _b
|
||||
_RS_Calc = ((_VOLT_RESOLUTION*_RLValue)/_sensor_volt)-_RLValue; //Get value of RS in a gas
|
||||
_ratio = _RS_Calc / this->_R0; // Get ratio RS_gas/RS_air
|
||||
_PPM= a*pow(_ratio, b);
|
||||
|
||||
if(print)
|
||||
{
|
||||
String nameLecture = getnameLecture();
|
||||
Serial.println("**********************");
|
||||
Serial.println("* PPM_log = (log10(Rs/R0) - b)/m");
|
||||
Serial.println("* PPM = pow(10, PPM_Log)");
|
||||
Serial.println("* Sensor: MQ-" + String(_type));
|
||||
Serial.println("* m =" + String(_m) + " ,b =" + String(_b) + ", R0 = " + _R0);
|
||||
Serial.println("* Vcc: " + String(_VOLT_RESOLUTION) + ", RS: " + String(_RS_Calc));
|
||||
Serial.println("* RS/R0 = " + String(_ratio) + " ,Voltaje leido(ADC): " + String(_sensor_volt));
|
||||
Serial.println("* PPM = " + _a + "pow(Rs/R0, +" + _b + ")");
|
||||
Serial.println("* Lectura(" + nameLecture + ")=" + String(_PPM) + " PPM");
|
||||
Serial.println("**********************");
|
||||
}
|
||||
@ -515,19 +520,6 @@ void MQUnifiedsensor::setSensorCharacteristics(String nameLectureRequeired, bool
|
||||
}
|
||||
//Serial debugging
|
||||
}
|
||||
float MQUnifiedsensor::readPPM(int m, int b) {
|
||||
/**
|
||||
* Returns the PPM concentration
|
||||
*/
|
||||
//More explained in: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||
_sensor_volt = this->getVoltage();
|
||||
//_RS_Calc; //Define variable for sensor resistance
|
||||
_RS_Calc = ((_VOLT_RESOLUTION*_RLValue)/_sensor_volt)-_RLValue; //Get value of RS in a gas
|
||||
_ratio = _RS_Calc / this->_R0; // Get ratio RS_gas/RS_air
|
||||
float ppm = a*pow(_ratio, b);
|
||||
|
||||
return floor(ppm);
|
||||
}
|
||||
long MQUnifiedsensor::calibrate(boolean print) {
|
||||
//More explained in: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||
/*
|
||||
@ -541,17 +533,15 @@ long MQUnifiedsensor::calibrate(boolean print) {
|
||||
RS = [(VC x RL) - (VRL x RL)] / VRL
|
||||
RS = [(VC x RL) / VRL] - RL
|
||||
*/
|
||||
_sensor_volt; //Define variable for sensor voltage
|
||||
float RS_air; //Define variable for sensor resistance
|
||||
float R0; //Define variable for R0
|
||||
_sensor_volt = this->getVoltage(); //Convert average to voltage
|
||||
RS_air = ((_VOLT_RESOLUTION*_RLValue)/_sensor_volt)-_RLValue; //Calculate RS in fresh air
|
||||
R0 = RS_air/_ratioInCleanAir; //Calculate R0
|
||||
if(print)
|
||||
{
|
||||
Serial.println("*******Calibrating*********");
|
||||
Serial.println("* Vcc: " + String(_VOLT_RESOLUTION) + "*");
|
||||
Serial.println("* Sensor: MQ-" + String(_type) + "*");
|
||||
Serial.println("* Vcc: " + String(_VOLT_RESOLUTION) + "*");
|
||||
Serial.println("* _sensor_volt: " + String(_sensor_volt) + "*");
|
||||
Serial.println("* _RLValue: " + String(_RLValue) + "*");
|
||||
Serial.println("* _ratioInCleanAir: " + String(_ratioInCleanAir) + "*");
|
||||
@ -561,7 +551,7 @@ long MQUnifiedsensor::calibrate(boolean print) {
|
||||
return R0;
|
||||
}
|
||||
double MQUnifiedsensor::getVoltage(int read) {
|
||||
double voltage = _sensor_volt;
|
||||
double voltage = 0;
|
||||
if(read)
|
||||
{
|
||||
double avg = 0.0;
|
||||
|
@ -83,23 +83,23 @@
|
||||
#define MQ2_Benzene_b 2.7901
|
||||
/********************** MQ3 ******************************************************/
|
||||
|
||||
#define MQ3_LPG_a -3.1851
|
||||
#define MQ3_LPG_b 4.7048
|
||||
#define MQ3_LPG_a 44771
|
||||
#define MQ3_LPG_b -3.245
|
||||
|
||||
#define MQ3_CH4_a -17.531
|
||||
#define MQ3_CH4_b 28.785
|
||||
#define MQ3_CH4_a 2*10^31
|
||||
#define MQ3_CH4_b 19.01
|
||||
|
||||
#define MQ3_CO_a -4.339
|
||||
#define MQ3_CO_b 6.4432
|
||||
#define MQ3_CO_a 521853
|
||||
#define MQ3_CO_b -3.821
|
||||
|
||||
#define MQ3_Alcohol_a -1.435
|
||||
#define MQ3_Alcohol_b 0.4103
|
||||
#define MQ3_Alcohol_a 0.3934
|
||||
#define MQ3_Alcohol_b -1.504
|
||||
|
||||
#define MQ3_Benzene_a -2.7009
|
||||
#define MQ3_Benzene_b 0.632
|
||||
#define MQ3_Benzene_a 1.8006
|
||||
#define MQ3_Benzene_b -0.373
|
||||
|
||||
#define MQ3_Hexane_a -2.7268
|
||||
#define MQ3_Hexane_b 3.6299
|
||||
#define MQ3_Hexane_a 22.996
|
||||
#define MQ3_Hexane_b -0.351
|
||||
/********************** MQ4 ******************************************************/
|
||||
|
||||
#define MQ4_LPG_a -2.5818
|
||||
@ -267,20 +267,24 @@ class MQUnifiedsensor
|
||||
{
|
||||
public:
|
||||
MQUnifiedsensor(int pin, int type);
|
||||
|
||||
//Functions to set values
|
||||
void inicializar();
|
||||
void update();
|
||||
void setR0(double R0);
|
||||
void setVoltResolution(float voltaje);
|
||||
void setSensorCharacteristics(String nameLectureReqeuired, bool print);
|
||||
void setDefaultGas();
|
||||
|
||||
//user functions
|
||||
long calibrate(boolean print = false);
|
||||
int readSensor(String nameLectureRequeired = "", bool print = false);
|
||||
|
||||
long calibrate(boolean print = false);
|
||||
double getVoltage(int read = true);
|
||||
double stringToDouble(String & str);
|
||||
//get function for info
|
||||
double getR0();
|
||||
float readPPM(int m, int b);
|
||||
|
||||
double getVoltage(int read = true);
|
||||
double stringToDouble(String & str);
|
||||
String getnameLecture();
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user