Modified fctn to get voltage

This commit is contained in:
miguel5612 2019-06-01 18:00:10 -05:00
parent 74e8f045aa
commit 434e454688
3 changed files with 37 additions and 16 deletions

View File

@ -96,7 +96,7 @@ void setup() {
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 - 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
delay(timeDelay/10);
}
@ -113,6 +113,16 @@ void loop() {
float lecture8 = MQ8.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
Serial.print(contador);Serial.print(",");
@ -123,8 +133,18 @@ void loop() {
Serial.print(lecture6);Serial.print(",");
Serial.print(lecture7);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
lcd.clear();
lcd.setCursor(0,0);

View File

@ -527,7 +527,7 @@ int MQUnifiedsensor::readPPM(int m, int b) {
double ppm = pow(10, ppm_log); //Convert ppm value to log scale
return floor(ppm);
}
float MQUnifiedsensor::calibrate(boolean print) {
long MQUnifiedsensor::calibrate(boolean print) {
//More explained in: https://jayconsystems.com/blog/understanding-a-gas-sensor
/*
V = I x R
@ -541,9 +541,8 @@ float MQUnifiedsensor::calibrate(boolean print) {
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
float sensorValue; //Define variable for analog readings
long RS_air; //Define variable for sensor resistance
long 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
@ -560,15 +559,17 @@ float MQUnifiedsensor::calibrate(boolean print) {
}
return R0;
}
double MQUnifiedsensor::getVoltage() {
double avg = 0.0;
for (int i = 0; i < retries; i ++) {
avg += analogRead(this->_pin) / retries;
delay(retry_interval);
double MQUnifiedsensor::getVoltage(int read) {
double voltage = _sensor_volt;
if(read)
{
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;
}
void MQUnifiedsensor::setR0(double R0) {

View File

@ -274,8 +274,8 @@ class MQUnifiedsensor
int readSensor(String nameLectureRequeired = "", bool print = false);
int readPPM(int m, int b);
float calibrate(boolean print = false);
double getVoltage();
long calibrate(boolean print = false);
double getVoltage(int read = true);
double stringToDouble(String & str);
String getnameLecture();