mirror of
https://github.com/Octech2722/arduino-environment-mqtt.git
synced 2025-12-10 00:36:04 -06:00
Create Arduino_TempHumidPresseCO2TVOC_Blynk.ino
This commit is contained in:
commit
bf4ca466d1
666
Arduino_TempHumidPresseCO2TVOC_Blynk.ino
Normal file
666
Arduino_TempHumidPresseCO2TVOC_Blynk.ino
Normal file
@ -0,0 +1,666 @@
|
||||
//Libraries for all the various commands
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_SGP30.h>
|
||||
#include <ArduinoOTA.h>
|
||||
#include <Blynk.h>
|
||||
#include <BlynkSimpleEsp8266.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <LOLIN_HP303B.h>
|
||||
#include <SPI.h>
|
||||
#include <SSD1306Wire.h>
|
||||
#include <WEMOS_SHT3X.h>
|
||||
#include <Wire.h>
|
||||
|
||||
// Your WiFi credentials.
|
||||
// Set password to "" for open networks.
|
||||
char ssid[] = "Unification";
|
||||
char pass[] = "#71YeOGhN2Oi9px";
|
||||
|
||||
//Sensor Designation
|
||||
//String whoAmI = String("Office");
|
||||
//String whoAmI = String("Bedroom");
|
||||
//String whoAmI = String("Kitchen");
|
||||
String whoAmI = String("LivingRoom");
|
||||
|
||||
//Blynk Auth Token
|
||||
//char blynkAuth[] = "rnqCPIclzlV5LIm83brjD4ibEXvoABEC"; //Office
|
||||
//char blynkAuth[] = "faKyKHCqdNq6C91EN7cLg9qO6CVoh2Ne"; //Bedroom
|
||||
//char blynkAuth[] = "xBUN8mo7WLss-N5X-ZcrbnW5ENfJIWgc"; //Kitchen
|
||||
char blynkAuth[] = "IMQNnraVsjCt3fe2ja0kGxACQh94xFoJ"; //Living Room
|
||||
|
||||
//SHT30 address assignment
|
||||
SHT3X sht30(0x45);
|
||||
|
||||
//Global Variables for SHT30 sensor
|
||||
int16_t temperatureAndHumiditySensorReturn;
|
||||
float temperatureFahrenheit;
|
||||
float percentHumidity;
|
||||
|
||||
// HP303B Opject
|
||||
LOLIN_HP303B HP303BPressureSensor;
|
||||
|
||||
//Global Variables for HP303B sensor
|
||||
int16_t pressureSensorReturn;
|
||||
int32_t pressurePascal;
|
||||
float pressureAtmosphere;
|
||||
static int16_t oversampling = 7;
|
||||
float paToATM = 101325;
|
||||
|
||||
//SGP30 Object
|
||||
Adafruit_SGP30 sgp30;
|
||||
|
||||
//Globnal Variables for SGP30 sensor
|
||||
int16_t eco2AndTVOCSensorReturn;
|
||||
int16_t eco2Baseline = 400;
|
||||
int16_t tvocBaseline = 0;
|
||||
float eco2Measurement;
|
||||
float compensatedECO2Measurement;
|
||||
float tvocMeasurement;
|
||||
float compensatedTVOCMeasurement;
|
||||
|
||||
//Global Variables for Battery Charge Level
|
||||
int batteryVoltageRaw = analogRead(A0);
|
||||
float batteryVoltageConverted = (float)batteryVoltageRaw * 0.00486;
|
||||
float batteryChargeLevel;
|
||||
float batteryVoltageMatrix[22][2] = {
|
||||
{4.2, 100},
|
||||
{4.15, 95},
|
||||
{4.11, 90},
|
||||
{4.08, 85},
|
||||
{4.02, 80},
|
||||
{3.98, 75},
|
||||
{3.95, 70},
|
||||
{3.91, 65},
|
||||
{3.87, 60},
|
||||
{3.85, 55},
|
||||
{3.84, 50},
|
||||
{3.82, 45},
|
||||
{3.80, 40},
|
||||
{3.79, 35},
|
||||
{3.77, 30},
|
||||
{3.75, 25},
|
||||
{3.73, 20},
|
||||
{3.71, 15},
|
||||
{3.69, 10},
|
||||
{3.61, 5},
|
||||
{3.27, 0},
|
||||
{0, 0}
|
||||
};
|
||||
|
||||
//Global Variable for Miliseconds
|
||||
uint32_t oneSecondInMicroseconds = 1000000;
|
||||
uint32_t oneMinuteInMicroseconds = 60000000;
|
||||
uint16_t oneSecondInMiliseconds = 1000;
|
||||
uint16_t oneMinuteInMiliseconds = 60000;
|
||||
|
||||
//Blynk Timer
|
||||
BlynkTimer blynkTimer;
|
||||
|
||||
//Blynk Serial Output
|
||||
#define BLYNK_PRINT Serial
|
||||
|
||||
//OLED screen pre-setup tasks
|
||||
#define wemosOLED096 GEOMETRY_128_64
|
||||
SSD1306Wire display(0x3c, D2, D1, wemosOLED096);
|
||||
//#define wemosOLED066 GEOMETRY_64_48
|
||||
//SSD1306Wire display(0x3c, D2, D1, wemosOLED066);
|
||||
//#define wemosOLED049 GEOMETRY_64_32
|
||||
//SSD1306Wire display(0x3c, D2, D1, wemosOLED049);
|
||||
|
||||
#define NUMFLAKES 10
|
||||
#define XPOS 0
|
||||
#define YPOS 1
|
||||
#define DELTAY 2
|
||||
|
||||
void wifiSetup() { //Proceedure for initializing and connecting to a wireless network
|
||||
Serial.println("[*]Starting void wifiSetup...");
|
||||
|
||||
Serial.println("[i]Setting ESP to be a WiFi-Client ONLY(Prevents network issues)...");
|
||||
WiFi.mode(WIFI_STA);
|
||||
Serial.println("[*]ESP set to WiFi-Client ONLY...");
|
||||
|
||||
Serial.println("[i]Starting WiFi Connection...");
|
||||
WiFi.begin(ssid, pass);
|
||||
Serial.print("[i]Connecting");
|
||||
while (WiFi.status() != WL_CONNECTED) { //Print out connection status
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
}
|
||||
|
||||
while (WiFi.waitForConnectResult() != WL_CONNECTED) { //Restart ESP if connection fails
|
||||
Serial.println("Connection Failed! Rebooting...");
|
||||
delay(3000);
|
||||
ESP.restart();
|
||||
}
|
||||
Serial.println("");
|
||||
Serial.println("[i]WiFi Connected!");
|
||||
Serial.print("[i]IPv4 address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
Serial.println("[*]void wifiSetup has completed...");
|
||||
}
|
||||
|
||||
void arduinoOTASetup() { //proceedure for initializing and setting up Arduino OTA update capabilities
|
||||
Serial.println("[*]Starting void arduinoOTASetup...");
|
||||
// Port defaults to 8266
|
||||
// ArduinoOTA.setPort(8266);
|
||||
|
||||
// Hostname defaults to esp8266-[ChipID]
|
||||
// ArduinoOTA.setHostname("myesp8266");
|
||||
|
||||
// No authentication by default
|
||||
// ArduinoOTA.setPassword("admin");
|
||||
|
||||
// Password can be set with it's md5 value as well
|
||||
// MD5(admin) = 21232f297a57a5a743894a0e4a801fc3
|
||||
// ArduinoOTA.setPasswordHash("21232f297a57a5a743894a0e4a801fc3");
|
||||
|
||||
ArduinoOTA.onStart([]() {
|
||||
String type;
|
||||
if (ArduinoOTA.getCommand() == U_FLASH) {
|
||||
type = "sketch";
|
||||
} else { // U_FS
|
||||
type = "filesystem";
|
||||
}
|
||||
// NOTE: if updating FS this would be the place to unmount FS using FS.end()
|
||||
display.clear();
|
||||
display.setFont(ArialMT_Plain_10);
|
||||
display.setTextAlignment(TEXT_ALIGN_CENTER_BOTH);
|
||||
display.drawString(display.getWidth()/2, display.getHeight()/2 - 10, "OTA Update");
|
||||
display.display();
|
||||
Serial.println("[i]Start updating: " + type);
|
||||
});
|
||||
|
||||
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
|
||||
display.drawProgressBar(4, 32, 120, 8, progress / (total / 100) );
|
||||
display.display();
|
||||
});
|
||||
|
||||
ArduinoOTA.onError([](ota_error_t error) {
|
||||
Serial.printf("[!]OTA Error[%u]: ", error);
|
||||
if (error == OTA_AUTH_ERROR) {
|
||||
Serial.println("Auth Failed!");
|
||||
} else if (error == OTA_BEGIN_ERROR) {
|
||||
Serial.println("Begin Failed!");
|
||||
} else if (error == OTA_CONNECT_ERROR) {
|
||||
Serial.println("Connect Failed!");
|
||||
} else if (error == OTA_RECEIVE_ERROR) {
|
||||
Serial.println("Receive Failed!");
|
||||
} else if (error == OTA_END_ERROR) {
|
||||
Serial.println("End Failed!");
|
||||
}
|
||||
});
|
||||
|
||||
ArduinoOTA.onEnd([]() {
|
||||
display.clear();
|
||||
display.setFont(ArialMT_Plain_10);
|
||||
display.setTextAlignment(TEXT_ALIGN_CENTER_BOTH);
|
||||
display.drawString(display.getWidth()/2, display.getHeight()/2, "Restart");
|
||||
display.display();
|
||||
Serial.println("\nOTA Update End");
|
||||
});
|
||||
|
||||
ArduinoOTA.begin();
|
||||
Serial.println("[*]void arduinoOTASetup has completed...");
|
||||
}
|
||||
|
||||
void resetDisplay() { //Clears and sets the default Display Settings
|
||||
Serial.println("[*]Starting void resetDisplay...");
|
||||
|
||||
Serial.println("[i]Clearing Display Buffer...");
|
||||
display.clear();
|
||||
|
||||
Serial.println("[i]Setting Text Font & Size...");
|
||||
display.setFont(ArialMT_Plain_10);
|
||||
|
||||
Serial.println("[i]Setting Text Alignment...");
|
||||
display.setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
|
||||
Serial.println("[*]void resetDisplay has completed...");
|
||||
}
|
||||
|
||||
void blynkTimerEvent() {
|
||||
Serial.println("[*]Starting void blynkTimerEvent...");
|
||||
|
||||
Serial.println("whoAmI = " + whoAmI);
|
||||
|
||||
Serial.println("[i]Pushing current " + whoAmI + " Temperature to Blynk...");
|
||||
Blynk.virtualWrite(V0, temperatureFahrenheit);
|
||||
|
||||
Serial.println("[i]Pushing current " + whoAmI + " Humidity to Blynk...");
|
||||
Blynk.virtualWrite(V1, percentHumidity);
|
||||
|
||||
Serial.println("[i]Pushing current " + whoAmI + " Pressure to Blynk...");
|
||||
Blynk.virtualWrite(V2, pressureAtmosphere);
|
||||
|
||||
Serial.println("[i]Pushing current " + whoAmI + " eCO2 to Blynk...");
|
||||
Blynk.virtualWrite(V3, compensatedECO2Measurement);
|
||||
|
||||
Serial.println("[i]Pushing current " + whoAmI + " TVOC to Blynk...");
|
||||
Blynk.virtualWrite(V4, compensatedTVOCMeasurement);
|
||||
|
||||
Serial.println("[i]Pushing current " + whoAmI + " Battery Voltage to Blynk...");
|
||||
Blynk.virtualWrite(V5, batteryVoltageConverted);
|
||||
|
||||
Serial.println("[i]Pushing current " + whoAmI + " Battery Charge Level to Blynk...");
|
||||
Blynk.virtualWrite(V6, batteryChargeLevel);
|
||||
}
|
||||
|
||||
void blynkSetup() {
|
||||
Serial.println("[*]Starting void blynkSetup...");
|
||||
|
||||
Serial.println("[i]Starting the Blynk service...");
|
||||
|
||||
Blynk.config(blynkAuth);
|
||||
Serial.println("[*]Blynk service started...");
|
||||
|
||||
Serial.println("[i]Setting timer interval for blynkTimer...");
|
||||
blynkTimer.setInterval(1000L, blynkTimerEvent);
|
||||
Serial.println("[*]Timer interval for blynkTimer set...");
|
||||
|
||||
Serial.println("[*]void blynkSetup has completed...");
|
||||
}
|
||||
|
||||
void pressureSetup() {
|
||||
Serial.println("[*]Starting void pressureSetup...");
|
||||
|
||||
Serial.println("[*]Starting HP303B Pressure Sensor...");
|
||||
HP303BPressureSensor.begin();
|
||||
Serial.println("[*]HP303B Pressure Sensor started...");
|
||||
|
||||
Serial.println("[*]Starting single test of HP303B Pressure Sensor...");
|
||||
int32_t temperature;
|
||||
int32_t pressure;
|
||||
int16_t oversampling = 7;
|
||||
int16_t ret;
|
||||
|
||||
//lets the HP303B perform a Single temperature measurement with the last (or standard) configuration
|
||||
//The result will be written to the paramerter temperature
|
||||
//ret = HP303BPressureSensor.measureTempOnce(temperature);
|
||||
//the commented line below does exactly the same as the one above, but you can also config the precision
|
||||
//oversampling can be a value from 0 to 7
|
||||
//the HP303B will perform 2^oversampling internal temperature measurements and combine them to one result with higher precision
|
||||
//measurements with higher precision take more time, consult datasheet for more information
|
||||
ret = HP303BPressureSensor.measureTempOnce(temperature, oversampling);
|
||||
|
||||
if (ret != 0)
|
||||
{
|
||||
//Something went wrong.
|
||||
//Look at the library code for more information about return codes
|
||||
Serial.print("[!]Error! Pressure HP303B returned ret = ");
|
||||
Serial.println(ret);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.print("[i]HP303B Temperature: ");
|
||||
Serial.print(temperature);
|
||||
Serial.println(" degrees Celsius");
|
||||
}
|
||||
|
||||
//Pressure measurement behaves like temperature measurement
|
||||
//ret = HP303BPressureSensor.measurePressureOnce(pressure);
|
||||
ret = HP303BPressureSensor.measurePressureOnce(pressure, oversampling);
|
||||
if (ret != 0)
|
||||
{
|
||||
//Something went wrong.
|
||||
//Look at the library code for more information about return codes
|
||||
Serial.print("[!]Error! Pressure HP303B returned ret = ");
|
||||
Serial.println(ret);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.print("[i]HP303B Pressure: ");
|
||||
Serial.print(pressure);
|
||||
Serial.println(" Pascal");
|
||||
}
|
||||
delay(500);
|
||||
Serial.println("[i]Quick Test of the HP303B sensor complete...");
|
||||
|
||||
Serial.println("[*]void pressureSetup has completed...");
|
||||
}
|
||||
|
||||
void airQualitySetup() {
|
||||
Serial.println("[*]Starting void airQualitySetup...");
|
||||
|
||||
Serial.println("[*]Starting SGP30 Sensor...");
|
||||
if (sgp30.begin())
|
||||
{
|
||||
Serial.println("[*]SGP30 Sensor started...");
|
||||
Serial.println("[i]Setting Calibration Values for SGP30 Sensor(Per LOLIN Documentation)...");
|
||||
sgp30.setIAQBaseline(eco2Baseline, tvocBaseline);
|
||||
Serial.println("[*]Calibration Values for SGP30 Sensor set...");
|
||||
}
|
||||
else {
|
||||
Serial.println("[!]ERROR: SGP Sensor could not start!");
|
||||
}
|
||||
Serial.println("[*]void airQualitySetup has completed...");
|
||||
|
||||
}
|
||||
|
||||
void updateTemperature() {
|
||||
Serial.println("[*]Starting void updateTemperature...");
|
||||
Serial.println("[?]Starting SHT3X Sensor...");
|
||||
|
||||
int16_t updatedTemperatureAndHumiditySensorReturn;
|
||||
|
||||
Serial.println("[?]Updating status of SHT3X Sensor...");
|
||||
updatedTemperatureAndHumiditySensorReturn = sht30.get();
|
||||
temperatureAndHumiditySensorReturn = updatedTemperatureAndHumiditySensorReturn;
|
||||
Serial.println("[i]SHT3X Sensor Status updated...");
|
||||
|
||||
if (temperatureAndHumiditySensorReturn == 0) {
|
||||
Serial.println("[i]SHT3X Sensor Started...");
|
||||
Serial.println("[*]Updating Temperature...");
|
||||
Serial.println("[i]Temperature was: " + String(temperatureFahrenheit) + "°F");
|
||||
temperatureFahrenheit = sht30.fTemp;
|
||||
Serial.println("[i]Temperature is now: " + String(temperatureFahrenheit) + "°F");
|
||||
}
|
||||
else if (temperatureAndHumiditySensorReturn == 2) {
|
||||
display.println("SHT3x Busy!");
|
||||
Serial.println("[!]Error! Wire Busy! Wire.available() != 0...");
|
||||
}
|
||||
else {
|
||||
display.println("SHT3x No Data!");
|
||||
Serial.println("[!]Error! No information recieved from the SHT3x Sensor!");
|
||||
}
|
||||
Serial.println("[*]void updateTemperature has completed...");
|
||||
}
|
||||
|
||||
void updateHumidity() {
|
||||
Serial.println("[*]Starting void updateHumidity...");
|
||||
Serial.println("[?]Starting SHT3X Sensor...");
|
||||
|
||||
int16_t updatedTemperatureAndHumiditySensorReturn;
|
||||
|
||||
Serial.println("[?]Updating status of SHT3X Sensor...");
|
||||
updatedTemperatureAndHumiditySensorReturn = sht30.get();
|
||||
temperatureAndHumiditySensorReturn = updatedTemperatureAndHumiditySensorReturn;
|
||||
Serial.println("[i]SHT3X Sensor Status updated...");
|
||||
|
||||
if (temperatureAndHumiditySensorReturn == 0) {
|
||||
Serial.println("[i]SHT3X Sensor Started...");
|
||||
Serial.println("[*]Updating Humidity...");
|
||||
Serial.println("[i]Humidity was: " + String(percentHumidity) + "%");
|
||||
percentHumidity = sht30.humidity;
|
||||
Serial.println("[i]Humidity is now: " + String(percentHumidity) + "%");
|
||||
}
|
||||
else if (temperatureAndHumiditySensorReturn == 2) {
|
||||
display.println("SHT3x Busy!");
|
||||
Serial.println("[!]Error! Wire Busy! Wire.available() != 0...");
|
||||
}
|
||||
else
|
||||
{
|
||||
display.println("SHT3x No Data!");
|
||||
Serial.println("[!]Error! No information recieved from the SHT3x Sensor!");
|
||||
}
|
||||
Serial.println("[*]void updateHumidity has completed...");
|
||||
}
|
||||
|
||||
void updatePressure() {
|
||||
Serial.println("[*]Starting void updatePressure...");
|
||||
Serial.println("[?]Starting HP303B Sensor...");
|
||||
|
||||
int32_t updatedPressurePascal;
|
||||
int16_t updatedPressureSensorReturn;
|
||||
|
||||
Serial.println("[?]Updating status of HP303B Sensor...");
|
||||
updatedPressureSensorReturn = HP303BPressureSensor.measurePressureOnce(pressurePascal, oversampling);
|
||||
pressureSensorReturn = updatedPressureSensorReturn;
|
||||
Serial.println("[i]HP303B Sensor Status updated...");
|
||||
|
||||
if (pressureSensorReturn == 0) { //HP303B__SUCCEEDED
|
||||
Serial.println("[*]Updating Pressure...");
|
||||
Serial.println("[i]Pressure was: " + String(pressureAtmosphere) + " Atmospheres");
|
||||
pressureAtmosphere = (pressurePascal / paToATM);
|
||||
Serial.println("[i]Pressure is now: " + String(pressureAtmosphere) + " Atmospheres");
|
||||
}
|
||||
else if (pressureSensorReturn == -1) { //HP303B__FAIL_UNKNOWN
|
||||
display.println("HP303B -1!");
|
||||
Serial.println("[!]ERROR! HP303B Sensor returned with an unknown failure! pressureSensorReturn = -1, HP303B__FAIL_UNKNOWN...");
|
||||
}
|
||||
else if (pressureSensorReturn == -2) { //HP303B__FAIL_INIT_FAILED
|
||||
display.println("HP303B -2!");
|
||||
Serial.println("[!]ERROR! HP303B Sensor returned with an initialization failure! pressureSensorReturn = -2, HP303B__FAIL_INIT_FAILED...");
|
||||
}
|
||||
else if (pressureSensorReturn == -3) { //HP303B__FAIL_TOOBUSY
|
||||
display.println("HP303B -3!");
|
||||
Serial.println("[!]ERROR! HP303B Sensor returned with a busy response! pressureSensorReturn = -3, HP303B__FAIL_TOOBUSY...");
|
||||
}
|
||||
else if (pressureSensorReturn == -4) { //HP303B__FAIL_UNFINISHED
|
||||
display.println("HP303B -4!");
|
||||
Serial.println("[!]ERROR! HP303B Sensor returned with an unfinisehd response! pressureSensorReturn = -4, HP303B__FAIL_UNFINISHED...");
|
||||
}
|
||||
else {
|
||||
display.println("HP303B No Data!");
|
||||
Serial.println("[!]Error! HP303B Sensor returned an unknown response!");
|
||||
}
|
||||
Serial.println("[*]void updatePressure has completed...");
|
||||
}
|
||||
|
||||
void updateECO2Measurement() {
|
||||
Serial.println("[*]Starting void updateECO2Measurement...");
|
||||
//CO2: 400 ppm TVOC: 0 ppb
|
||||
Serial.println("[?]Updating status of SGP30 Sensor...");
|
||||
Serial.println("[i]SGP30 Sensor return was: " + String(eco2AndTVOCSensorReturn));
|
||||
eco2AndTVOCSensorReturn = sgp30.IAQmeasure();
|
||||
Serial.println("[i]SGP30 Sensor return is now: " + String(eco2AndTVOCSensorReturn));
|
||||
|
||||
if (eco2AndTVOCSensorReturn == 1) { //Successfully talked to sensor
|
||||
Serial.println("[*]Updating eCO2...");
|
||||
Serial.println("[i]eCO2 was: " + String(compensatedECO2Measurement) + " ppm");
|
||||
eco2Measurement = sgp30.eCO2;
|
||||
compensatedECO2Measurement = eco2Measurement - eco2Baseline;
|
||||
Serial.println("[i]eCO2 is now: " + String(compensatedECO2Measurement) + " ppm");
|
||||
}
|
||||
else { //Failed to talk to sensor
|
||||
display.println("SGP30 retunred 0!");
|
||||
Serial.println("[!]ERROR! No information recieved from the SGP30 Sensor!");
|
||||
}
|
||||
}
|
||||
|
||||
void updateTVOCMeasurement() {
|
||||
Serial.println("[*]Starting void updateTVOCMeasurement...");
|
||||
//CO2: 400 ppm TVOC: 0 ppb
|
||||
Serial.println("[?]Updating status of SGP30 Sensor...");
|
||||
Serial.println("[i]SGP30 Sensor return was: " + String(eco2AndTVOCSensorReturn));
|
||||
eco2AndTVOCSensorReturn = sgp30.IAQmeasure();
|
||||
Serial.println("[i]SGP30 Sensor return is now: " + String(eco2AndTVOCSensorReturn));
|
||||
|
||||
if (eco2AndTVOCSensorReturn == 1) { //Successfully talked to sensor
|
||||
Serial.println("[*]Updating TVOC...");
|
||||
Serial.println("[i]TVOC was: " + String(compensatedTVOCMeasurement) + " ppb");
|
||||
tvocMeasurement = sgp30.TVOC;
|
||||
compensatedTVOCMeasurement = tvocMeasurement - tvocBaseline;
|
||||
Serial.println("[i]TVOC is now: " + String(compensatedTVOCMeasurement) + " ppb");
|
||||
}
|
||||
else { //Failed to talk to sensor
|
||||
display.println("SGP30 returned 0!");
|
||||
Serial.println("[!]ERROR! Something went wrong with the SGP30 Sensor!");
|
||||
}
|
||||
}
|
||||
|
||||
void updateBatteryStatus() {
|
||||
Serial.println("[*]Starting void updateBatteryStatus...");
|
||||
|
||||
Serial.println("[?]Updating status of the Battery...");
|
||||
Serial.println("[i]Battery Voltage was: " + String(batteryVoltageConverted));
|
||||
Serial.println("[i]Battery Charge Level was: " + String(batteryChargeLevel));
|
||||
batteryVoltageRaw = analogRead(A0);
|
||||
batteryVoltageConverted = (float)batteryVoltageRaw * 0.00486;
|
||||
for(int i = 20; i>=0; i--) {
|
||||
if(batteryVoltageMatrix[i][0] >= batteryVoltageConverted) {
|
||||
batteryChargeLevel = batteryVoltageMatrix[i + 1][1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
Serial.println("[i]Battery Voltage is now: " + String(batteryVoltageConverted));
|
||||
Serial.println("[i]Battery Charge Level is now: " + String(batteryChargeLevel));
|
||||
}
|
||||
|
||||
void blynkLoop() {
|
||||
Serial.println("[*]Starting void blynkLoop...");
|
||||
Serial.println("[...]Running Blynk Service...");
|
||||
Blynk.run();
|
||||
Serial.println("[...]Running Blynk Timer...");
|
||||
blynkTimer.run();
|
||||
Serial.println("[*]void blynkLoop has completed...");
|
||||
}
|
||||
|
||||
void displayLoop() {
|
||||
Serial.println("[*]Starting void displayLoop...");
|
||||
|
||||
Serial.println("[*]Setting Display Properties...");
|
||||
display.resetDisplay();
|
||||
Serial.println("[i]Display Properties Set");
|
||||
|
||||
Serial.println("[*}Building Display Output...");
|
||||
|
||||
if (temperatureAndHumiditySensorReturn == 0) {
|
||||
Serial.println("[*]Building the Temperature(*F) Display Output...");
|
||||
display.print("Temp:");
|
||||
Serial.println("Temperature:");
|
||||
display.println(String(temperatureFahrenheit, 2) + "F");
|
||||
Serial.println(String(temperatureFahrenheit, 2) + "F");
|
||||
|
||||
Serial.println("[*]Building the Humidity(%) Display Output...");
|
||||
display.print("Humid:");
|
||||
Serial.println("Relative Humidity:");
|
||||
display.println(String(percentHumidity, 2) + "%");
|
||||
Serial.println(String(percentHumidity, 2) + "%");
|
||||
}
|
||||
else {
|
||||
display.print("Temp:");
|
||||
display.println("[!]");
|
||||
|
||||
display.print("Humid:");
|
||||
display.println("[!]");
|
||||
|
||||
Serial.println("[!]ERROR! No data recieved from SHT30!");
|
||||
}
|
||||
|
||||
if (pressureSensorReturn == 0) {
|
||||
Serial.println("[*]Building the Pressure(atm) Display Output...");
|
||||
display.print("Press:");
|
||||
Serial.println("Pressure:");
|
||||
display.println(String(pressureAtmosphere, 2) + "atm");
|
||||
Serial.println(String(pressureAtmosphere, 2) + "atm");
|
||||
}
|
||||
else {
|
||||
display.print("Press:");
|
||||
display.println("[!]");
|
||||
|
||||
Serial.println("[!]ERROR! No data recieved from HP303B!");
|
||||
}
|
||||
|
||||
if (eco2AndTVOCSensorReturn == 0) {
|
||||
Serial.println("[*]Building the eCO2 Display Output...");
|
||||
display.print("eCO2:");
|
||||
Serial.println("eCO2:");
|
||||
display.println(String(eco2Measurement, 2) + "ppm");
|
||||
Serial.println(String(eco2Measurement, 2) + "ppm");
|
||||
|
||||
Serial.println("[*]Building the TVOC Display Output...");
|
||||
display.print("TVOC:");
|
||||
Serial.println("TVOC:");
|
||||
display.println(String(tvocMeasurement, 2) + "ppb");
|
||||
Serial.println(String(tvocMeasurement, 2) + "ppb");
|
||||
}
|
||||
else {
|
||||
display.print("eCO2:");
|
||||
display.println("[!]");
|
||||
|
||||
display.print("TVOC:");
|
||||
display.println("[!]");
|
||||
|
||||
Serial.println("[!]ERROR! No data recieved from SGP30!");
|
||||
}
|
||||
|
||||
if (batteryVoltageConverted != 0) {
|
||||
Serial.println("[*]Building the Battery Level/Voltage Display Output...");
|
||||
display.print("Battery:");
|
||||
Serial.println("Battery:");
|
||||
display.println(String(batteryChargeLevel, 2) + "% " + String(batteryVoltageConverted, 2) + "V");
|
||||
Serial.println(String(batteryChargeLevel, 2) + "% " + String(batteryVoltageConverted, 2) + "V");
|
||||
}
|
||||
else {
|
||||
display.print("Battery:");
|
||||
display.println("[!]");
|
||||
Serial.println("[!]ERROR! Battery at 0V! It may be completely dead or disconnected!");
|
||||
}
|
||||
|
||||
Serial.println("[i]Display Output Built. Displaying now...");
|
||||
display.display();
|
||||
Serial.println("[i]Displaying for 10 seconds...");
|
||||
delay(10 * oneSecondInMiliseconds);
|
||||
|
||||
Serial.println("[i]Display Output Displayed. Clearing Display Output...");
|
||||
display.resetDisplay();
|
||||
Serial.println("[i]Display Output Cleared...");
|
||||
|
||||
Serial.println("[*]void displayLoop has completed...");
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
Serial.println("[!]Booting...");
|
||||
|
||||
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
|
||||
Serial.println("[*]Initializing Display I2C...");
|
||||
display.init();
|
||||
Serial.println("[i]Display I2C Initialization Complete...");
|
||||
|
||||
// Show image buffer on the display hardware.
|
||||
// Since the buffer is intialized with an Adafruit splashscreen
|
||||
// internally, this will display the splashscreen.
|
||||
Serial.println("[*]Displaying Adafruit Splashscreen...");
|
||||
display.display();
|
||||
delay(2 * oneSecondInMiliseconds);
|
||||
|
||||
// Clear the buffer.
|
||||
Serial.println("[*]Clearing the Display Buffer...");
|
||||
display.resetDisplay();
|
||||
Serial.println("[i]Display Buffer cleared...");
|
||||
|
||||
//Start WIFI connection
|
||||
Serial.println("[*]Starting WIFI...");
|
||||
wifiSetup();
|
||||
Serial.println("[*]WIFI Start Complete...");
|
||||
|
||||
//Run Arduino OTA Setup
|
||||
Serial.println("[*]Starting Arduino OTA...");
|
||||
arduinoOTASetup();
|
||||
Serial.println("[*]Arduino OTA Start Complete...");
|
||||
|
||||
//Run Pressure Sensor Startup
|
||||
Serial.println("[*]Starting Pressure Sensor...");
|
||||
pressureSetup();
|
||||
Serial.println("[*]Pressure Sensor Start Complete...");
|
||||
|
||||
//Run Air Quality Sensor Startup
|
||||
Serial.println("[*]Starting Air Quality Sensor...");
|
||||
airQualitySetup();
|
||||
Serial.println("[*]Air Quality Sensor Start Complete...");
|
||||
|
||||
//Run Blynk Setup
|
||||
Serial.println("[*]Starting Blynk...");
|
||||
blynkSetup();
|
||||
Serial.println("[*}Blynk Start Complete...");
|
||||
|
||||
//Handle Android OTA
|
||||
ArduinoOTA.handle();
|
||||
|
||||
Serial.println("[i]All Start Jobs Complete[i]");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
ArduinoOTA.handle();
|
||||
updateTemperature();
|
||||
updateHumidity();
|
||||
updatePressure();
|
||||
updateECO2Measurement();
|
||||
updateTVOCMeasurement();
|
||||
updateBatteryStatus();
|
||||
blynkLoop();
|
||||
displayLoop();
|
||||
delay(1000);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user