add buzzer + LCD
authorgregor herrmann <gregor@toastfreeware.priv.at>
Sun, 25 Oct 2020 22:26:55 +0000 (23:26 +0100)
committergregor herrmann <gregor@toastfreeware.priv.at>
Sun, 25 Oct 2020 22:36:28 +0000 (23:36 +0100)
airingbutler.ino

index 5e33a802de0d8974a251825de1f6810b3b5b2e97..c05a73738fce381080623ea4ee39d85a0ff4d4d8 100644 (file)
@@ -1,4 +1,5 @@
 #include <SoftwareSerial.h>
+#include <LiquidCrystal.h>
 #include "MHZ19.h"
 
 const int rx_pin = 2; // connect to TX on MHZ19
@@ -8,11 +9,25 @@ const int led_green_pin  = 4;
 const int led_yellow_pin = 5;
 const int led_red_pin    = 6;
 
+const int buzzer_pin = 13;
+
+/*
+const int lcd_pin = 7;
+const int lcd_pin = 8;
+const int lcd_pin = 9;
+const int lcd_pin = 10;
+const int lcd_pin = 11;
+const int lcd_pin = 12;
+*/
+
 const int co2_warning_thr = 1000;
 const int co2_alarm_thr   = 1500;
 
 MHZ19 mhz19 = MHZ19(rx_pin,tx_pin);
+LiquidCrystal lcd(7,8,9,10,11,12);
+
 unsigned long time;
+int lastppm = 0;
 
 
 void setup()
@@ -21,10 +36,18 @@ void setup()
     Serial.println("Time,CO2,Temp");
     mhz19.begin(rx_pin, tx_pin);
 
-       // led
+       // LCD
+       lcd.begin(16,2);
+       lcd.setCursor(0,0);
+       lcd.print("Airing Butler");
+       lcd.setCursor(0,1);
+       lcd.print("says hello!");
+
+       // led+buzzer
        pinMode(led_green_pin, OUTPUT);
        pinMode(led_yellow_pin, OUTPUT);
        pinMode(led_red_pin, OUTPUT);
+       pinMode(buzzer_pin, OUTPUT);
        digitalWrite(led_green_pin, HIGH);
        delay(500);
        digitalWrite(led_green_pin, LOW);
@@ -34,6 +57,11 @@ void setup()
        digitalWrite(led_red_pin, HIGH);
        delay(500);
        digitalWrite(led_red_pin, LOW);
+       digitalWrite(buzzer_pin, HIGH);
+       delay(200);
+       digitalWrite(buzzer_pin, LOW);
+       
+       lcd.clear();
 }
 
 
@@ -52,6 +80,31 @@ void loop()
        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);
 
+       if (m.co2_ppm >= co2_alarm_thr && lastppm < co2_alarm_thr) {
+               digitalWrite(buzzer_pin, HIGH);
+               delay(100);
+               digitalWrite(buzzer_pin, LOW);
+               delay(100);
+               digitalWrite(buzzer_pin, HIGH);
+               delay(100);
+               digitalWrite(buzzer_pin, LOW);
+               delay(100);
+               digitalWrite(buzzer_pin, HIGH);
+               delay(100);
+               digitalWrite(buzzer_pin, LOW);
+       }
+
+       if (m.co2_ppm >= co2_warning_thr && lastppm < co2_warning_thr) {
+               digitalWrite(buzzer_pin, HIGH);
+               delay(500);
+               digitalWrite(buzzer_pin, LOW);
+       }
+
+       lcd.setCursor(0,0);
+       lcd.print("CO2: ");
+       lcd.print(m.co2_ppm);
+       lcd.print(" ppm         ");
+
+    lastppm = m.co2_ppm;
     delay(5000);
 }
-