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 const unsigned long warmuptime = 60000; // 1 min.
18 const unsigned long cooldowntime = 60000; // 1 min.
20 MHZ19 mhz19 = MHZ19(rx_pin,tx_pin);
21 LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
24 unsigned long lastwarntime = 0;
29 void buzz(unsigned long pause, int count) {
30 for (int i = 0; i <= count; i++) {
31 digitalWrite(buzzer_pin, HIGH);
33 digitalWrite(buzzer_pin, LOW);
34 if (i < count - 1) delay(pause);
41 Serial.println("Time,CO2,Temp");
44 mhz19.begin(rx_pin, tx_pin);
49 lcd.print("Airing Butler");
51 lcd.print("says hello!");
54 pinMode(led_green_pin, OUTPUT);
55 pinMode(led_yellow_pin, OUTPUT);
56 pinMode(led_red_pin, OUTPUT);
57 digitalWrite(led_green_pin, HIGH);
59 digitalWrite(led_green_pin, LOW);
60 digitalWrite(led_yellow_pin, HIGH);
62 digitalWrite(led_yellow_pin, LOW);
63 digitalWrite(led_red_pin, HIGH);
65 digitalWrite(led_red_pin, LOW);
68 pinMode(buzzer_pin, OUTPUT);
78 measurement_t m = mhz19.getMeasurement();
88 digitalWrite(led_red_pin, co2 >= co2_alarm_thr);
89 digitalWrite(led_yellow_pin, co2 >= co2_warning_thr && co2 < co2_alarm_thr);
90 digitalWrite(led_green_pin, co2 < co2_warning_thr);
92 if (co2 >= co2_alarm_thr && lastppm < co2_alarm_thr && time - lastwarntime > cooldowntime) {
97 if (co2 >= co2_warning_thr && lastppm < co2_warning_thr && time - lastwarntime > cooldowntime) {
105 if (time < warmuptime && (co2 == -1 || co2 == 410)) {
112 lcd.print(" C +/- ");