mirror of
https://github.com/miguel5612/MQSensorsLib.git
synced 2025-03-25 10:10:01 +03:00
fixed calibration
This commit is contained in:
parent
1924e21e61
commit
6d1229977e
@ -136,13 +136,26 @@ int MQUnifiedsensor::readPPM(int m, int b) {
|
|||||||
return floor(ppm);
|
return floor(ppm);
|
||||||
}
|
}
|
||||||
double MQUnifiedsensor::calibrate() {
|
double MQUnifiedsensor::calibrate() {
|
||||||
float sensor_volt; //Define variable for sensor voltage
|
//More explained in: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||||
float RS_air; //Define variable for sensor resistance
|
/*
|
||||||
float R0; //Define variable for R0
|
V = I x R
|
||||||
float sensorValue; //Define variable for analog readings
|
VRL = [VC / (RS + RL)] x RL
|
||||||
sensor_volt = this->getVoltage(); //Convert average to voltage
|
VRL = (VC x RL) / (RS + RL)
|
||||||
R0 = sensor_volt / _ratioInCleanAir; //Calculate R0
|
Así que ahora resolvemos para RS:
|
||||||
return R0;
|
VRL x (RS + RL) = VC x RL
|
||||||
|
(VRL x RS) + (VRL x RL) = VC x RL
|
||||||
|
(VRL x RS) = (VC x RL) - (VRL x RL)
|
||||||
|
RS = [(VC x RL) - (VRL x RL)] / VRL
|
||||||
|
RS = [(VC x RL) / VRL] - RL
|
||||||
|
*/
|
||||||
|
float sensor_volt; //Define variable for sensor voltage
|
||||||
|
float RS_air; //Define variable for sensor resistance
|
||||||
|
float R0; //Define variable for R0
|
||||||
|
float sensorValue; //Define variable for analog readings
|
||||||
|
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
|
||||||
|
return R0;
|
||||||
}
|
}
|
||||||
double MQUnifiedsensor::getVoltage() {
|
double MQUnifiedsensor::getVoltage() {
|
||||||
double avg = 0.0;
|
double avg = 0.0;
|
||||||
|
@ -4,9 +4,16 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
//Count of posible lectures
|
//Count of posible lectures
|
||||||
#define lecturesAvailable 19
|
#define lecturesAvailable 19
|
||||||
|
|
||||||
|
/************************Global vars************************************/
|
||||||
|
int VOLT_RESOLUTION = 5.0; // if 3.3v use 3.3
|
||||||
|
int RLValue = 10; //Value in KiloOhms
|
||||||
|
int _ratioInCleanAir, _PPM;
|
||||||
|
double RS_air,_R0, _m, _b, _ratio;
|
||||||
|
|
||||||
/************************Hardware Related Macros************************************/
|
/************************Hardware Related Macros************************************/
|
||||||
|
|
||||||
//Index in the nameLecture vector
|
//Index in the nameLecture vector
|
||||||
@ -82,10 +89,8 @@ class MQUnifiedsensor
|
|||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int _pin, _type, _PPM, _lecturePosInArray, _ratioInCleanAir;
|
int _pin, _type;
|
||||||
double RS_air,_R0 = 11.820, _m, _b, _ratio;
|
|
||||||
String _MQ[19], _nameLectureRequeired;
|
String _MQ[19], _nameLectureRequeired;
|
||||||
int VOLT_RESOLUTION = 5.0; // if 3.3v use 3.3
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //MQUnifiedsensor_H
|
#endif //MQUnifiedsensor_H
|
Loading…
x
Reference in New Issue
Block a user