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);
29 Serial.println("Time,CO2,Temp");
32 mhz19.begin(rx_pin, tx_pin);
37 lcd.print("Airing Butler");
39 lcd.print("says hello!");
42 pinMode(led_green_pin, OUTPUT);
43 pinMode(led_yellow_pin, OUTPUT);
44 pinMode(led_red_pin, OUTPUT);
45 pinMode(buzzer_pin, OUTPUT);
46 digitalWrite(led_green_pin, HIGH);
48 digitalWrite(led_green_pin, LOW);
49 digitalWrite(led_yellow_pin, HIGH);
51 digitalWrite(led_yellow_pin, LOW);
52 digitalWrite(led_red_pin, HIGH);
54 digitalWrite(led_red_pin, LOW);
55 digitalWrite(buzzer_pin, HIGH);
57 digitalWrite(buzzer_pin, LOW);
66 measurement_t m = mhz19.getMeasurement();
76 digitalWrite(led_red_pin, co2 >= co2_alarm_thr);
77 digitalWrite(led_yellow_pin, co2 >= co2_warning_thr && co2 < co2_alarm_thr);
78 digitalWrite(led_green_pin, co2 < co2_warning_thr);
80 if (co2 >= co2_alarm_thr && lastppm < co2_alarm_thr) {
81 digitalWrite(buzzer_pin, HIGH);
83 digitalWrite(buzzer_pin, LOW);
85 digitalWrite(buzzer_pin, HIGH);
87 digitalWrite(buzzer_pin, LOW);
89 digitalWrite(buzzer_pin, HIGH);
91 digitalWrite(buzzer_pin, LOW);
94 if (co2 >= co2_warning_thr && lastppm < co2_warning_thr) {
95 digitalWrite(buzzer_pin, HIGH);
97 digitalWrite(buzzer_pin, LOW);