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;
|
//_MQ = MQ309;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void MQUnifiedsensor::update()
|
||||||
|
{
|
||||||
|
_sensor_volt = this->getVoltage();
|
||||||
|
}
|
||||||
void MQUnifiedsensor::setVoltResolution(float voltaje)
|
void MQUnifiedsensor::setVoltResolution(float voltaje)
|
||||||
{
|
{
|
||||||
_VOLT_RESOLUTION = voltaje;
|
_VOLT_RESOLUTION = voltaje;
|
||||||
@ -100,18 +104,19 @@ void MQUnifiedsensor::inicializar()
|
|||||||
}
|
}
|
||||||
int MQUnifiedsensor::readSensor(String nameLectureRequeired, bool print)
|
int MQUnifiedsensor::readSensor(String nameLectureRequeired, bool print)
|
||||||
{
|
{
|
||||||
setSensorCharacteristics(nameLectureRequeired, print);
|
setSensorCharacteristics(nameLectureRequeired, print); //In this function update _a and _b
|
||||||
_PPM =readPPM(_m, _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)
|
if(print)
|
||||||
{
|
{
|
||||||
String nameLecture = getnameLecture();
|
String nameLecture = getnameLecture();
|
||||||
Serial.println("**********************");
|
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("* 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("* Vcc: " + String(_VOLT_RESOLUTION) + ", RS: " + String(_RS_Calc));
|
||||||
Serial.println("* RS/R0 = " + String(_ratio) + " ,Voltaje leido(ADC): " + String(_sensor_volt));
|
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("* Lectura(" + nameLecture + ")=" + String(_PPM) + " PPM");
|
||||||
Serial.println("**********************");
|
Serial.println("**********************");
|
||||||
}
|
}
|
||||||
@ -515,19 +520,6 @@ void MQUnifiedsensor::setSensorCharacteristics(String nameLectureRequeired, bool
|
|||||||
}
|
}
|
||||||
//Serial debugging
|
//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) {
|
long MQUnifiedsensor::calibrate(boolean print) {
|
||||||
//More explained in: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
//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 x RL)] / VRL
|
||||||
RS = [(VC x RL) / VRL] - RL
|
RS = [(VC x RL) / VRL] - RL
|
||||||
*/
|
*/
|
||||||
_sensor_volt; //Define variable for sensor voltage
|
|
||||||
float RS_air; //Define variable for sensor resistance
|
float RS_air; //Define variable for sensor resistance
|
||||||
float R0; //Define variable for R0
|
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
|
RS_air = ((_VOLT_RESOLUTION*_RLValue)/_sensor_volt)-_RLValue; //Calculate RS in fresh air
|
||||||
R0 = RS_air/_ratioInCleanAir; //Calculate R0
|
R0 = RS_air/_ratioInCleanAir; //Calculate R0
|
||||||
if(print)
|
if(print)
|
||||||
{
|
{
|
||||||
Serial.println("*******Calibrating*********");
|
Serial.println("*******Calibrating*********");
|
||||||
Serial.println("* Vcc: " + String(_VOLT_RESOLUTION) + "*");
|
|
||||||
Serial.println("* Sensor: MQ-" + String(_type) + "*");
|
Serial.println("* Sensor: MQ-" + String(_type) + "*");
|
||||||
|
Serial.println("* Vcc: " + String(_VOLT_RESOLUTION) + "*");
|
||||||
Serial.println("* _sensor_volt: " + String(_sensor_volt) + "*");
|
Serial.println("* _sensor_volt: " + String(_sensor_volt) + "*");
|
||||||
Serial.println("* _RLValue: " + String(_RLValue) + "*");
|
Serial.println("* _RLValue: " + String(_RLValue) + "*");
|
||||||
Serial.println("* _ratioInCleanAir: " + String(_ratioInCleanAir) + "*");
|
Serial.println("* _ratioInCleanAir: " + String(_ratioInCleanAir) + "*");
|
||||||
@ -561,7 +551,7 @@ long MQUnifiedsensor::calibrate(boolean print) {
|
|||||||
return R0;
|
return R0;
|
||||||
}
|
}
|
||||||
double MQUnifiedsensor::getVoltage(int read) {
|
double MQUnifiedsensor::getVoltage(int read) {
|
||||||
double voltage = _sensor_volt;
|
double voltage = 0;
|
||||||
if(read)
|
if(read)
|
||||||
{
|
{
|
||||||
double avg = 0.0;
|
double avg = 0.0;
|
||||||
|
@ -83,23 +83,23 @@
|
|||||||
#define MQ2_Benzene_b 2.7901
|
#define MQ2_Benzene_b 2.7901
|
||||||
/********************** MQ3 ******************************************************/
|
/********************** MQ3 ******************************************************/
|
||||||
|
|
||||||
#define MQ3_LPG_a -3.1851
|
#define MQ3_LPG_a 44771
|
||||||
#define MQ3_LPG_b 4.7048
|
#define MQ3_LPG_b -3.245
|
||||||
|
|
||||||
#define MQ3_CH4_a -17.531
|
#define MQ3_CH4_a 2*10^31
|
||||||
#define MQ3_CH4_b 28.785
|
#define MQ3_CH4_b 19.01
|
||||||
|
|
||||||
#define MQ3_CO_a -4.339
|
#define MQ3_CO_a 521853
|
||||||
#define MQ3_CO_b 6.4432
|
#define MQ3_CO_b -3.821
|
||||||
|
|
||||||
#define MQ3_Alcohol_a -1.435
|
#define MQ3_Alcohol_a 0.3934
|
||||||
#define MQ3_Alcohol_b 0.4103
|
#define MQ3_Alcohol_b -1.504
|
||||||
|
|
||||||
#define MQ3_Benzene_a -2.7009
|
#define MQ3_Benzene_a 1.8006
|
||||||
#define MQ3_Benzene_b 0.632
|
#define MQ3_Benzene_b -0.373
|
||||||
|
|
||||||
#define MQ3_Hexane_a -2.7268
|
#define MQ3_Hexane_a 22.996
|
||||||
#define MQ3_Hexane_b 3.6299
|
#define MQ3_Hexane_b -0.351
|
||||||
/********************** MQ4 ******************************************************/
|
/********************** MQ4 ******************************************************/
|
||||||
|
|
||||||
#define MQ4_LPG_a -2.5818
|
#define MQ4_LPG_a -2.5818
|
||||||
@ -267,20 +267,24 @@ class MQUnifiedsensor
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MQUnifiedsensor(int pin, int type);
|
MQUnifiedsensor(int pin, int type);
|
||||||
|
|
||||||
|
//Functions to set values
|
||||||
void inicializar();
|
void inicializar();
|
||||||
|
void update();
|
||||||
void setR0(double R0);
|
void setR0(double R0);
|
||||||
void setVoltResolution(float voltaje);
|
void setVoltResolution(float voltaje);
|
||||||
void setSensorCharacteristics(String nameLectureReqeuired, bool print);
|
void setSensorCharacteristics(String nameLectureReqeuired, bool print);
|
||||||
void setDefaultGas();
|
void setDefaultGas();
|
||||||
|
|
||||||
|
//user functions
|
||||||
|
long calibrate(boolean print = false);
|
||||||
int readSensor(String nameLectureRequeired = "", bool print = false);
|
int readSensor(String nameLectureRequeired = "", bool print = false);
|
||||||
|
|
||||||
long calibrate(boolean print = false);
|
//get function for info
|
||||||
double getVoltage(int read = true);
|
|
||||||
double stringToDouble(String & str);
|
|
||||||
double getR0();
|
double getR0();
|
||||||
float readPPM(int m, int b);
|
float readPPM(int m, int b);
|
||||||
|
double getVoltage(int read = true);
|
||||||
|
double stringToDouble(String & str);
|
||||||
String getnameLecture();
|
String getnameLecture();
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user