1 #include <SoftwareSerial.h>
4 const int rx_pin = 2; // connect to TX on MHZ19
5 const int tx_pin = 3; // connect to RX on MHZ19
7 const int led_green_pin = 4;
8 const int led_yellow_pin = 5;
9 const int led_red_pin = 6;
11 const int co2_warning_thr = 1000;
12 const int co2_alarm_thr = 1500;
14 MHZ19 mhz19 = MHZ19(rx_pin,tx_pin);
21 Serial.println("Time,CO2,Temp");
22 mhz19.begin(rx_pin, tx_pin);
25 pinMode(led_green_pin, OUTPUT);
26 pinMode(led_yellow_pin, OUTPUT);
27 pinMode(led_red_pin, OUTPUT);
28 digitalWrite(led_green_pin, HIGH);
30 digitalWrite(led_green_pin, LOW);
31 digitalWrite(led_yellow_pin, HIGH);
33 digitalWrite(led_yellow_pin, LOW);
34 digitalWrite(led_red_pin, HIGH);
36 digitalWrite(led_red_pin, LOW);
43 measurement_t m = mhz19.getMeasurement();
47 Serial.print(m.co2_ppm);
49 Serial.println(m.temperature);
51 digitalWrite(led_red_pin, m.co2_ppm >= co2_alarm_thr);
52 digitalWrite(led_yellow_pin, m.co2_ppm >= co2_warning_thr && m.co2_ppm < co2_alarm_thr);
53 digitalWrite(led_green_pin, m.co2_ppm < co2_warning_thr);