summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven <steven.vasilogianis@gmail.com>2021-10-05 13:46:14 -0400
committerSteven <steven.vasilogianis@gmail.com>2021-10-05 13:46:14 -0400
commit0848a13c38d2f54c91a1e98e114fd49e3f4c8a70 (patch)
treebff29ba867016227b3ae6b66e32dad6c7ec6fb8e
parent00ba5a2c941404642f371d17351b8451b5554654 (diff)
Add photoresistor support
-rw-r--r--src/main/main.ino44
1 files 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 @@
2#define HUMIDITY_SENSOR_PIN 12 2#define HUMIDITY_SENSOR_PIN 12
3#define FAN_PIN 15 3#define FAN_PIN 15
4#define CO2_PIN 16 4#define CO2_PIN 16
5#define ULTRASONIC_PIN 17 5#define ULTRASONIC_PIN 12
6
7#define PHOTORESISTOR 0 // pin 0 is analog
6 8
7#define CHECK_FREQUENCY 2 // check sensors every 2 seconds 9#define CHECK_FREQUENCY 2 // check sensors every 2 seconds
8#define HUMIDITY_DESIRED 75 10#define HUMIDITY_DESIRED 75
@@ -11,30 +13,32 @@
11 13
12#include "ota.h" 14#include "ota.h"
13 15
14// Tempature + Humidity Sensor
15#include <WiFiClient.h> 16#include <WiFiClient.h>
17WiFiClient *wific = 0;
18
19// Tempature + Humidity Sensor
16#include <DHT.h> 20#include <DHT.h>
17#define DHTPIN 12 21#define DHTPIN 12
18#define DHTTYPE DHT11 22#define DHTTYPE DHT11
19DHT dht(DHTPIN, DHTTYPE); 23DHT dht(DHTPIN, DHTTYPE);
20 24
21WiFiClient *wific = 0;
22 25
23void setup () { 26void setup () {
24 setupWifi((char *) hostname);
25 setupOTA((char *) hostname);
26
27 Serial.begin(115200); 27 Serial.begin(115200);
28 Serial.println(F("Mushing...")); 28 Serial.println(F("Mushing..."));
29 29
30 dht.begin(); // temp+humidity sensor 30 setupWifi((char *) hostname);
31 setupOTA((char *) hostname);
32
33 dht.begin(); // temp+humidity sensor
34 pinMode(PHOTORESISTOR, INPUT); // photo resistor
31 wific = new WiFiClient(); 35 wific = new WiFiClient();
32} 36}
33 37
34void log_reading ( float temp_c, float humidity, float heat_index_c ) { 38void log_reading ( float temp_c, float humidity, float heat_index_c, int photons ) {
35 auto fmt = "T: %.2f H: %.2f HI: %.2f\r\n"; 39 auto fmt = "T: %.2f H: %.2f HI: %.2f LIGHT: %d\r\n";
36 char buf[500]; 40 char buf[500];
37 snprintf(buf, sizeof(buf), fmt, temp_c, humidity, heat_index_c); 41 snprintf(buf, sizeof(buf), fmt, temp_c, humidity, heat_index_c, photons);
38 //Serial.printf(fmt, temp_c, humidity, heat_index_c); 42 //Serial.printf(fmt, temp_c, humidity, heat_index_c);
39 Serial.print(buf); 43 Serial.print(buf);
40 if (wific->connected()) { 44 if (wific->connected()) {
@@ -42,6 +46,22 @@ void log_reading ( float temp_c, float humidity, float heat_index_c ) {
42 } 46 }
43} 47}
44 48
49/*
50Global state variables to hold rolling average humidity, temperature, etc sensor values
51Override state variable is set by network command
52
53Need max and min threshhold values for each sensor too
54
55struct SensorState
56{
57 float rolling_average;
58 float threshold_top;
59 float threshold_bottom;
60 void *top_exceeded_callback();
61 float force_value;
62}
63*/
64
45void loop() { 65void loop() {
46 ArduinoOTA.handle(); 66 ArduinoOTA.handle();
47 67
@@ -65,5 +85,7 @@ void loop() {
65 } 85 }
66 float hic = dht.computeHeatIndex(t, h, false); 86 float hic = dht.computeHeatIndex(t, h, false);
67 87
68 log_reading(t, h, hic); 88 int photons = analogRead(PHOTORESISTOR);
89 log_reading(t, h, hic, photons);
69} 90}
91