const int rx_pin = 2; // connect to TX on MHZ19
const int tx_pin = 3; // connect to RX on MHZ19
+const int led_green_pin = 4;
+const int led_yellow_pin = 5;
+const int led_red_pin = 6;
+
+const int co2_warning_thr = 1000;
+const int co2_alarm_thr = 1500;
MHZ19 mhz19 = MHZ19(rx_pin,tx_pin);
unsigned long time;
Serial.begin(115200);
Serial.println("Time,CO2,Temp");
mhz19.begin(rx_pin, tx_pin);
+
+ // led
+ pinMode(led_green_pin, OUTPUT);
+ pinMode(led_yellow_pin, OUTPUT);
+ pinMode(led_red_pin, OUTPUT);
+ digitalWrite(led_green_pin, HIGH);
+ delay(500);
+ digitalWrite(led_green_pin, LOW);
+ digitalWrite(led_yellow_pin, HIGH);
+ delay(500);
+ digitalWrite(led_yellow_pin, LOW);
+ digitalWrite(led_red_pin, HIGH);
+ delay(500);
+ digitalWrite(led_red_pin, LOW);
}
Serial.print(",");
Serial.println(m.temperature);
+ digitalWrite(led_red_pin, m.co2_ppm >= co2_alarm_thr);
+ digitalWrite(led_yellow_pin, m.co2_ppm >= co2_warning_thr && m.co2_ppm < co2_alarm_thr);
+ digitalWrite(led_green_pin, m.co2_ppm < co2_warning_thr);
+
delay(5000);
}