1 #include <SoftwareSerial.h>
2 #include <LiquidCrystal.h>
5 const int rx_pin = 2; // connect to TX on MHZ19
6 const int tx_pin = 3; // connect to RX on MHZ19
8 const int led_green_pin = 4;
9 const int led_yellow_pin = 5;
10 const int led_red_pin = 6;
12 const int buzzer_pin = 13;
14 const int co2_warning_thr = 1000;
15 const int co2_alarm_thr = 1500;
17 MHZ19 mhz19 = MHZ19(rx_pin,tx_pin);
18 LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
27 Serial.println("Time,CO2,Temp");
30 mhz19.begin(rx_pin, tx_pin);
35 lcd.print("Airing Butler");
37 lcd.print("says hello!");
40 pinMode(led_green_pin, OUTPUT);
41 pinMode(led_yellow_pin, OUTPUT);
42 pinMode(led_red_pin, OUTPUT);
43 pinMode(buzzer_pin, OUTPUT);
44 digitalWrite(led_green_pin, HIGH);
46 digitalWrite(led_green_pin, LOW);
47 digitalWrite(led_yellow_pin, HIGH);
49 digitalWrite(led_yellow_pin, LOW);
50 digitalWrite(led_red_pin, HIGH);
52 digitalWrite(led_red_pin, LOW);
53 digitalWrite(buzzer_pin, HIGH);
55 digitalWrite(buzzer_pin, LOW);
64 measurement_t m = mhz19.getMeasurement();
68 Serial.print(m.co2_ppm);
70 Serial.println(m.temperature);
72 digitalWrite(led_red_pin, m.co2_ppm >= co2_alarm_thr);
73 digitalWrite(led_yellow_pin, m.co2_ppm >= co2_warning_thr && m.co2_ppm < co2_alarm_thr);
74 digitalWrite(led_green_pin, m.co2_ppm < co2_warning_thr);
76 if (m.co2_ppm >= co2_alarm_thr && lastppm < co2_alarm_thr) {
77 digitalWrite(buzzer_pin, HIGH);
79 digitalWrite(buzzer_pin, LOW);
81 digitalWrite(buzzer_pin, HIGH);
83 digitalWrite(buzzer_pin, LOW);
85 digitalWrite(buzzer_pin, HIGH);
87 digitalWrite(buzzer_pin, LOW);
90 if (m.co2_ppm >= co2_warning_thr && lastppm < co2_warning_thr) {
91 digitalWrite(buzzer_pin, HIGH);
93 digitalWrite(buzzer_pin, LOW);