mirror of
https://github.com/miguel5612/MQSensorsLib.git
synced 2025-03-25 10:10:01 +03:00
Modified fctn to get voltage
This commit is contained in:
parent
74e8f045aa
commit
434e454688
@ -96,7 +96,7 @@ void setup() {
|
|||||||
Serial.println("MQ2 to MQ9 - Calibracion");
|
Serial.println("MQ2 to MQ9 - Calibracion");
|
||||||
Serial.println("Note - Make sure you are in a clean room and the sensor has pre-heated almost 4 hours");
|
Serial.println("Note - Make sure you are in a clean room and the sensor has pre-heated almost 4 hours");
|
||||||
Serial.println("Note - All values are in KOhms");
|
Serial.println("Note - All values are in KOhms");
|
||||||
Serial.println("Autonumeric, MQ2(R0), MQ3(R0), MQ4(R0), MQ5(R0), MQ6(R0), MQ7(R0)");
|
Serial.println("Autonumeric, MQ2(R0), MQ3(R0), MQ4(R0), MQ5(R0), MQ6(R0), MQ7(R0), MQ8(R0), MQ9(R0), v2(VDC), v3(VDC), v4(VDC), v5(VDC), v6(VDC), v7(VDC), v8(VDC), v9(VDC)");
|
||||||
//Wait one second to continue
|
//Wait one second to continue
|
||||||
delay(timeDelay/10);
|
delay(timeDelay/10);
|
||||||
}
|
}
|
||||||
@ -113,6 +113,16 @@ void loop() {
|
|||||||
float lecture8 = MQ8.calibrate();
|
float lecture8 = MQ8.calibrate();
|
||||||
float lecture9 = MQ9.calibrate();
|
float lecture9 = MQ9.calibrate();
|
||||||
|
|
||||||
|
//Read voltage the sensor
|
||||||
|
float v2 = MQ2.getVoltage(false);
|
||||||
|
float v3 = MQ3.getVoltage(false);
|
||||||
|
float v4 = MQ4.getVoltage(false);
|
||||||
|
float v5 = MQ5.getVoltage(false);
|
||||||
|
float v6 = MQ6.getVoltage(false);
|
||||||
|
float v7 = MQ7.getVoltage(false);
|
||||||
|
float v8 = MQ8.getVoltage(false);
|
||||||
|
float v9 = MQ9.getVoltage(false);
|
||||||
|
|
||||||
|
|
||||||
//Print in serial monitor
|
//Print in serial monitor
|
||||||
Serial.print(contador);Serial.print(",");
|
Serial.print(contador);Serial.print(",");
|
||||||
@ -123,8 +133,18 @@ void loop() {
|
|||||||
Serial.print(lecture6);Serial.print(",");
|
Serial.print(lecture6);Serial.print(",");
|
||||||
Serial.print(lecture7);Serial.print(",");
|
Serial.print(lecture7);Serial.print(",");
|
||||||
Serial.print(lecture8);Serial.print(",");
|
Serial.print(lecture8);Serial.print(",");
|
||||||
Serial.println(lecture9);
|
Serial.println(lecture9);Serial.print(",");
|
||||||
|
//Print voltages
|
||||||
|
Serial.print(v2);Serial.print(",");
|
||||||
|
Serial.print(v3);Serial.print(",");
|
||||||
|
Serial.print(v4);Serial.print(",");
|
||||||
|
Serial.print(v5);Serial.print(",");
|
||||||
|
Serial.print(v6);Serial.print(",");
|
||||||
|
Serial.print(v7);Serial.print(",");
|
||||||
|
Serial.print(v8);Serial.print(",");
|
||||||
|
Serial.println(v9);Serial.print(",");
|
||||||
|
|
||||||
|
|
||||||
//Print in LCD
|
//Print in LCD
|
||||||
lcd.clear();
|
lcd.clear();
|
||||||
lcd.setCursor(0,0);
|
lcd.setCursor(0,0);
|
||||||
|
@ -527,7 +527,7 @@ int MQUnifiedsensor::readPPM(int m, int b) {
|
|||||||
double ppm = pow(10, ppm_log); //Convert ppm value to log scale
|
double ppm = pow(10, ppm_log); //Convert ppm value to log scale
|
||||||
return floor(ppm);
|
return floor(ppm);
|
||||||
}
|
}
|
||||||
float 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
|
||||||
/*
|
/*
|
||||||
V = I x R
|
V = I x R
|
||||||
@ -541,9 +541,8 @@ float MQUnifiedsensor::calibrate(boolean print) {
|
|||||||
RS = [(VC x RL) / VRL] - RL
|
RS = [(VC x RL) / VRL] - RL
|
||||||
*/
|
*/
|
||||||
_sensor_volt; //Define variable for sensor voltage
|
_sensor_volt; //Define variable for sensor voltage
|
||||||
float RS_air; //Define variable for sensor resistance
|
long RS_air; //Define variable for sensor resistance
|
||||||
float R0; //Define variable for R0
|
long R0; //Define variable for R0
|
||||||
float sensorValue; //Define variable for analog readings
|
|
||||||
_sensor_volt = this->getVoltage(); //Convert average to voltage
|
_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
|
||||||
@ -560,15 +559,17 @@ float MQUnifiedsensor::calibrate(boolean print) {
|
|||||||
}
|
}
|
||||||
return R0;
|
return R0;
|
||||||
}
|
}
|
||||||
double MQUnifiedsensor::getVoltage() {
|
double MQUnifiedsensor::getVoltage(int read) {
|
||||||
double avg = 0.0;
|
double voltage = _sensor_volt;
|
||||||
for (int i = 0; i < retries; i ++) {
|
if(read)
|
||||||
avg += analogRead(this->_pin) / retries;
|
{
|
||||||
delay(retry_interval);
|
double avg = 0.0;
|
||||||
|
for (int i = 0; i < retries; i ++) {
|
||||||
|
avg += analogRead(this->_pin) / retries;
|
||||||
|
delay(retry_interval);
|
||||||
|
}
|
||||||
|
voltage = avg * _VOLT_RESOLUTION / (pow(2, ADC_RESOLUTION) - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
double voltage = avg * _VOLT_RESOLUTION / (pow(2, ADC_RESOLUTION) - 1);
|
|
||||||
|
|
||||||
return voltage;
|
return voltage;
|
||||||
}
|
}
|
||||||
void MQUnifiedsensor::setR0(double R0) {
|
void MQUnifiedsensor::setR0(double R0) {
|
||||||
|
@ -274,8 +274,8 @@ class MQUnifiedsensor
|
|||||||
int readSensor(String nameLectureRequeired = "", bool print = false);
|
int readSensor(String nameLectureRequeired = "", bool print = false);
|
||||||
int readPPM(int m, int b);
|
int readPPM(int m, int b);
|
||||||
|
|
||||||
float calibrate(boolean print = false);
|
long calibrate(boolean print = false);
|
||||||
double getVoltage();
|
double getVoltage(int read = true);
|
||||||
double stringToDouble(String & str);
|
double stringToDouble(String & str);
|
||||||
|
|
||||||
String getnameLecture();
|
String getnameLecture();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user