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;
15 const int lcd_pin = 7;
16 const int lcd_pin = 8;
17 const int lcd_pin = 9;
18 const int lcd_pin = 10;
19 const int lcd_pin = 11;
20 const int lcd_pin = 12;
23 const int co2_warning_thr = 1000;
24 const int co2_alarm_thr = 1500;
26 MHZ19 mhz19 = MHZ19(rx_pin,tx_pin);
27 LiquidCrystal lcd(7,8,9,10,11,12);
36 Serial.println("Time,CO2,Temp");
37 mhz19.begin(rx_pin, tx_pin);
42 lcd.print("Airing Butler");
44 lcd.print("says hello!");
47 pinMode(led_green_pin, OUTPUT);
48 pinMode(led_yellow_pin, OUTPUT);
49 pinMode(led_red_pin, OUTPUT);
50 pinMode(buzzer_pin, OUTPUT);
51 digitalWrite(led_green_pin, HIGH);
53 digitalWrite(led_green_pin, LOW);
54 digitalWrite(led_yellow_pin, HIGH);
56 digitalWrite(led_yellow_pin, LOW);
57 digitalWrite(led_red_pin, HIGH);
59 digitalWrite(led_red_pin, LOW);
60 digitalWrite(buzzer_pin, HIGH);
62 digitalWrite(buzzer_pin, LOW);
71 measurement_t m = mhz19.getMeasurement();
75 Serial.print(m.co2_ppm);
77 Serial.println(m.temperature);
79 digitalWrite(led_red_pin, m.co2_ppm >= co2_alarm_thr);
80 digitalWrite(led_yellow_pin, m.co2_ppm >= co2_warning_thr && m.co2_ppm < co2_alarm_thr);
81 digitalWrite(led_green_pin, m.co2_ppm < co2_warning_thr);
83 if (m.co2_ppm >= co2_alarm_thr && lastppm < co2_alarm_thr) {
84 digitalWrite(buzzer_pin, HIGH);
86 digitalWrite(buzzer_pin, LOW);
88 digitalWrite(buzzer_pin, HIGH);
90 digitalWrite(buzzer_pin, LOW);
92 digitalWrite(buzzer_pin, HIGH);
94 digitalWrite(buzzer_pin, LOW);
97 if (m.co2_ppm >= co2_warning_thr && lastppm < co2_warning_thr) {
98 digitalWrite(buzzer_pin, HIGH);
100 digitalWrite(buzzer_pin, LOW);
105 lcd.print(m.co2_ppm);