// DHT object for humidity sensor
DHT dht;
+
+#define CO2_PIN A1
#define DHT_PIN 4
#define GAS_PIN A0
#define START_DELAY 20000
byte HasBaro;
+#define READ_SAMPLE_INTERVAL 50
+#define READ_SAMPLE_TIMES 5
+
+#define MQ135_RES 1000
+
+float MQRead(int mq_pin)
+{
+
+ int i;
+ float rs=0;
+ float rr;
+
+ for (i=0;i<READ_SAMPLE_TIMES;i++) {
+ rr = analogRead(mq_pin);
+ rs += rr;
+ delay(READ_SAMPLE_INTERVAL);
+ }
+
+ rs = rs/READ_SAMPLE_TIMES;
+ return rs;
+
+}
+
+/// Parameters to model temperature and humidity dependence
+
+#define CORA 0.00035
+#define CORB 0.02718
+#define CORC 1.39538
+#define CORD 0.0018
+
+float getMQ135CorrectionFactor(float t, float h) {
+ return CORA * t * t - CORB * t + CORC - (h-33.)*CORD;
+}
+
+#define RZERO 25300
+#define PARA 116.6020682
+#define PARB 2.769034857
+
+float getMQ135ppm(float Resistance) {
+ return PARA * pow((Resistance/RZERO), -PARB);
+}
+
void setup()
{
delay(START_DELAY);
dht.setup(DHT_PIN);
+ pinMode(GAS_PIN,INPUT);
+ pinMode(CO2_PIN,INPUT);
+
+ digitalWrite(GAS_PIN, LOW);
+ digitalWrite(CO2_PIN, LOW);
}
void loop()
Serial1.print(",HUMIDITY=");
Serial1.println(DHT_H);
} else {
- Serial1.println("ERROR:TYPE=DHT22,MESSAGE=MEASURING ERROR\n");
+ Serial1.print("ERROR:TYPE=DHT22,MESSAGE=");
+ Serial1.println(dht.getStatusString());
}
- Gas = analogRead(GAS_PIN);
+ Gas = MQRead(GAS_PIN);
Serial1.print("SENSOR:TYPE=MQ4,VALUE=");
Serial1.println(Gas);
+
+ float MQ135_Resistance;
+ float CO2_raw;
+ float CO2_ppm;
+
+ float CO2_resistance;
+
+ CO2_raw = MQRead(CO2_PIN);
+ Serial1.print("DEBUG:RAW=");
+ Serial1.println(CO2_raw);
+
+ MQ135_Resistance=MQ135_RES*(1023./CO2_raw-1);
+
+ Serial1.print("DEBUG:RESISTANCE=");
+ Serial1.println(MQ135_Resistance);
+
+ MQ135_Resistance=MQ135_Resistance/getMQ135CorrectionFactor(DHT_T,DHT_H);
+ Serial1.print("DEBUG:CORR_RESISTANCE=");
+ Serial1.println(MQ135_Resistance);
+
+ CO2_ppm = getMQ135ppm(MQ135_Resistance);
+
+ Serial1.print("SENSOR:TYPE=MQ135,VALUE=");
+ Serial1.println(CO2_ppm);
delay(DELAY); // Pause for 50 seconds.
}
+