From 0848a13c38d2f54c91a1e98e114fd49e3f4c8a70 Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 5 Oct 2021 13:46:14 -0400 Subject: Add photoresistor support --- src/main/main.ino | 44 +++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/src/main/main.ino b/src/main/main.ino index 1027bed..a435473 100644 --- a/src/main/main.ino +++ b/src/main/main.ino @@ -2,7 +2,9 @@ #define HUMIDITY_SENSOR_PIN 12 #define FAN_PIN 15 #define CO2_PIN 16 -#define ULTRASONIC_PIN 17 +#define ULTRASONIC_PIN 12 + +#define PHOTORESISTOR 0 // pin 0 is analog #define CHECK_FREQUENCY 2 // check sensors every 2 seconds #define HUMIDITY_DESIRED 75 @@ -11,30 +13,32 @@ #include "ota.h" -// Tempature + Humidity Sensor #include +WiFiClient *wific = 0; + +// Tempature + Humidity Sensor #include #define DHTPIN 12 #define DHTTYPE DHT11 DHT dht(DHTPIN, DHTTYPE); -WiFiClient *wific = 0; void setup () { - setupWifi((char *) hostname); - setupOTA((char *) hostname); - Serial.begin(115200); Serial.println(F("Mushing...")); - dht.begin(); // temp+humidity sensor + setupWifi((char *) hostname); + setupOTA((char *) hostname); + + dht.begin(); // temp+humidity sensor + pinMode(PHOTORESISTOR, INPUT); // photo resistor wific = new WiFiClient(); } -void log_reading ( float temp_c, float humidity, float heat_index_c ) { - auto fmt = "T: %.2f H: %.2f HI: %.2f\r\n"; +void log_reading ( float temp_c, float humidity, float heat_index_c, int photons ) { + auto fmt = "T: %.2f H: %.2f HI: %.2f LIGHT: %d\r\n"; char buf[500]; - snprintf(buf, sizeof(buf), fmt, temp_c, humidity, heat_index_c); + snprintf(buf, sizeof(buf), fmt, temp_c, humidity, heat_index_c, photons); //Serial.printf(fmt, temp_c, humidity, heat_index_c); Serial.print(buf); if (wific->connected()) { @@ -42,6 +46,22 @@ void log_reading ( float temp_c, float humidity, float heat_index_c ) { } } +/* +Global state variables to hold rolling average humidity, temperature, etc sensor values +Override state variable is set by network command + +Need max and min threshhold values for each sensor too + +struct SensorState +{ + float rolling_average; + float threshold_top; + float threshold_bottom; + void *top_exceeded_callback(); + float force_value; +} +*/ + void loop() { ArduinoOTA.handle(); @@ -65,5 +85,7 @@ void loop() { } float hic = dht.computeHeatIndex(t, h, false); - log_reading(t, h, hic); + int photons = analogRead(PHOTORESISTOR); + log_reading(t, h, hic, photons); } + -- cgit v1.2.3