Last active
April 11, 2021 21:13
-
-
Save ptesei/93fee37e802089c47637120da66b8125 to your computer and use it in GitHub Desktop.
Arduino Co2 detector MH-Z19b connected to Blynk via ESP8266
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #define BLYNK_PRINT Serial | |
| #include <SoftwareSerial.h> | |
| #include <ESP8266WiFi.h> | |
| #include <BlynkSimpleEsp8266.h> | |
| #include <MHZ19PWM.h> | |
| MHZ19PWM mhz(D5, MHZ_DELAYED_MODE); | |
| char auth[] = "dM-aERE2i1ZZd-aauogHCQXcGloNdNSi"; | |
| char ssid[] = "Mosne_2G"; | |
| char pass[] = "18031982"; | |
| BlynkTimer timerData; | |
| void timerDataEvent() | |
| { | |
| float ppm = mhz.getCO2(); | |
| Serial.print(F("CO2: ")); | |
| Serial.println(ppm); | |
| Blynk.virtualWrite(V5, ppm ); | |
| if (ppm <= 400 || ppm > 4900) { | |
| Serial.println("Error: no data yet"); | |
| } else { | |
| if (ppm < 450) { | |
| Serial.println("Very good"); | |
| } | |
| else if (ppm < 600) { | |
| Serial.println("Good"); | |
| } | |
| else if (ppm < 1000) { | |
| Serial.println("Acceptable"); | |
| } | |
| else if (ppm < 2500) { | |
| Serial.println("Bad, notification sent"); | |
| Blynk.notify(String("Open the window! ") + String(ppm) + String("ppm!") ); | |
| Serial.println(String("Open the window! ") + String(ppm) + String("ppm!")); | |
| } | |
| else { | |
| Serial.println("Health risk"); | |
| } | |
| } | |
| } | |
| void setup() | |
| { | |
| // Debug console | |
| Serial.begin(115200); | |
| Serial.println(F("Starting...")); | |
| Blynk.begin(auth, ssid, pass); | |
| delay(2000); | |
| mhz.useLimit(2830); // 5000>708 | |
| timerData.setInterval(10000L, timerDataEvent); | |
| } | |
| void loop() | |
| { | |
| Blynk.run(); | |
| timerData.run(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment