From cb212fc9912c1bdb92400c304e72b44aad3b7728 Mon Sep 17 00:00:00 2001 From: gregor herrmann Date: Sun, 25 Oct 2020 21:22:28 +0100 Subject: [PATCH] add the 3 LEDs and wire them up with CO2 values --- airingbutler.ino | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/airingbutler.ino b/airingbutler.ino index 94ba188..5e33a80 100644 --- a/airingbutler.ino +++ b/airingbutler.ino @@ -4,6 +4,12 @@ const int rx_pin = 2; // connect to TX on MHZ19 const int tx_pin = 3; // connect to RX on MHZ19 +const int led_green_pin = 4; +const int led_yellow_pin = 5; +const int led_red_pin = 6; + +const int co2_warning_thr = 1000; +const int co2_alarm_thr = 1500; MHZ19 mhz19 = MHZ19(rx_pin,tx_pin); unsigned long time; @@ -14,6 +20,20 @@ void setup() Serial.begin(115200); Serial.println("Time,CO2,Temp"); mhz19.begin(rx_pin, tx_pin); + + // led + pinMode(led_green_pin, OUTPUT); + pinMode(led_yellow_pin, OUTPUT); + pinMode(led_red_pin, OUTPUT); + digitalWrite(led_green_pin, HIGH); + delay(500); + digitalWrite(led_green_pin, LOW); + digitalWrite(led_yellow_pin, HIGH); + delay(500); + digitalWrite(led_yellow_pin, LOW); + digitalWrite(led_red_pin, HIGH); + delay(500); + digitalWrite(led_red_pin, LOW); } @@ -28,6 +48,10 @@ void loop() Serial.print(","); Serial.println(m.temperature); + digitalWrite(led_red_pin, m.co2_ppm >= co2_alarm_thr); + digitalWrite(led_yellow_pin, m.co2_ppm >= co2_warning_thr && m.co2_ppm < co2_alarm_thr); + digitalWrite(led_green_pin, m.co2_ppm < co2_warning_thr); + delay(5000); } -- 2.39.5