diff options
author | Steven <steven.vasilogianis@gmail.com> | 2021-09-23 16:50:31 -0400 |
---|---|---|
committer | Steven <steven.vasilogianis@gmail.com> | 2021-09-23 16:50:31 -0400 |
commit | c915e95f7564f2ec9def6f6f6b15e25fe86a6dc1 (patch) | |
tree | 1ca3c5a4d83c11b3c3b8670b725b7309027c3d6f | |
parent | eee4cb3b72aad7032c23a96d86e40be9c1afb4e9 (diff) |
Added code for tempature+humidity sensor which is on hand. arduino ide insists on new directory structure.
-rw-r--r-- | src/main.ino | 31 | ||||
-rw-r--r-- | src/main/main.ino | 85 |
2 files changed, 85 insertions, 31 deletions
diff --git a/src/main.ino b/src/main.ino deleted file mode 100644 index 627be8c..0000000 --- a/src/main.ino +++ /dev/null | |||
@@ -1,31 +0,0 @@ | |||
1 | #define CHECK_FREQUENCY 1000; // check sensors every second | ||
2 | #define HUMIDITY_DESIRED 75; | ||
3 | #define HUMIDITY_VARIATION 3; // ultrasonic turns on at (75 - 3 = 72) and off at (75 + 3 = 78) | ||
4 | |||
5 | int humidity () { ; } | ||
6 | int tempature () { ; } | ||
7 | int co2 () { ; } | ||
8 | bool ultrasonic_start () { ; } | ||
9 | bool ultrasonic_stop () { ; } | ||
10 | bool fan_start () { ; } | ||
11 | bool fan_stop () { ; } | ||
12 | bool log ( int humidity, int temp, int co2 ) { ; } | ||
13 | |||
14 | void loop() { | ||
15 | delay(CHECK_FREQUENCY); | ||
16 | int humidity = humidity(); | ||
17 | int temp = temp(); | ||
18 | int co2 = co2(); | ||
19 | |||
20 | if ( humidity < (HUMIDITY_DESIRED - HUMIDITY_VARIATION) ) { | ||
21 | ultrasonic_start(); | ||
22 | fan_stop(); | ||
23 | } elseif ( humidity > (HUMIDITY_DESIRED + HUMIDITY_VARIATION) ) { | ||
24 | fan_start(); | ||
25 | ultrasonic_stop(); | ||
26 | } else { | ||
27 | ; // keep going | ||
28 | } | ||
29 | |||
30 | log(humidity, temp, co2); | ||
31 | } | ||
diff --git a/src/main/main.ino b/src/main/main.ino new file mode 100644 index 0000000..bdab190 --- /dev/null +++ b/src/main/main.ino | |||
@@ -0,0 +1,85 @@ | |||
1 | #define TEMP_SENSOR_PIN 14 | ||
2 | #define HUMIDITY_SENSOR_PIN 14 | ||
3 | #define FAN_PIN 15 | ||
4 | #define CO2_PIN 16 | ||
5 | #define ULTRASONIC_PIN 17 | ||
6 | |||
7 | #define CHECK_FREQUENCY 1 // check sensors every second | ||
8 | #define HUMIDITY_DESIRED 75 | ||
9 | #define HUMIDITY_VARIATION 3 // ultrasonic turns on at (75 - 3 = 72) and off | ||
10 | // at (75 + 3 = 78) | ||
11 | |||
12 | |||
13 | // Tempature + Humidity Sensor | ||
14 | #include <Adafruit_Sensor.h> | ||
15 | #include <DHT.h> | ||
16 | #include <DHT_U.h> | ||
17 | #define DHTTYPE DHT11 | ||
18 | #define DHTPIN TEMP_SENSOR_PIN | ||
19 | DHT_Unified dht(DHTPIN, DHTTYPE); | ||
20 | |||
21 | int get_humidity () { | ||
22 | // Get temperature event and print its value. | ||
23 | sensors_event_t event; | ||
24 | dht.temperature().getEvent(&event); | ||
25 | if (isnan(event.temperature)) { | ||
26 | Serial.println(F("Error reading temperature!")); | ||
27 | } | ||
28 | else { | ||
29 | return event.temperature; | ||
30 | /* Serial.print(F("Temperature: ")); */ | ||
31 | /* Serial.print(event.temperature); */ | ||
32 | /* Serial.println(F("°C")); */ | ||
33 | } | ||
34 | } | ||
35 | |||
36 | int get_tempature () { | ||
37 | sensors_event_t event; | ||
38 | // Get humidity event and print its value. | ||
39 | dht.humidity().getEvent(&event); | ||
40 | if (isnan(event.relative_humidity)) { | ||
41 | Serial.println(F("Error reading humidity!")); | ||
42 | } | ||
43 | else { | ||
44 | return event.relative_humidity; | ||
45 | /* Serial.print(F("Humidity: ")); */ | ||
46 | /* Serial.print(event.relative_humidity); */ | ||
47 | /* Serial.println(F("%")); */ | ||
48 | } | ||
49 | } | ||
50 | |||
51 | int get_co2 () { ; } | ||
52 | bool start_ultrasonic () { ; } | ||
53 | bool stop_ultrasonic () { ; } | ||
54 | bool start_fan () { ; } | ||
55 | bool stop_fan () { ; } | ||
56 | |||
57 | |||
58 | bool log ( int humidity, int temp, int co2 ) { | ||
59 | Serial.printf("Tempature: %d\tHumidity: %d\tCO2: %d\n", | ||
60 | humidity, temp, co2); | ||
61 | } | ||
62 | |||
63 | void setup () { | ||
64 | Serial.begin(115200); | ||
65 | dht.begin(); /* temp/humidity sensor */ | ||
66 | } | ||
67 | |||
68 | void loop() { | ||
69 | delay(CHECK_FREQUENCY * 1000); | ||
70 | int humidity = get_humidity(); | ||
71 | int temp = get_tempature(); | ||
72 | int co2 = get_co2(); | ||
73 | |||
74 | if ( humidity < (HUMIDITY_DESIRED - HUMIDITY_VARIATION) ) { | ||
75 | start_ultrasonic(); | ||
76 | stop_fan(); | ||
77 | } else if ( humidity > (HUMIDITY_DESIRED + HUMIDITY_VARIATION) ) { | ||
78 | start_fan(); | ||
79 | stop_ultrasonic(); | ||
80 | } else { | ||
81 | ; // keep doing the same | ||
82 | } | ||
83 | |||
84 | log(humidity, temp, co2); | ||
85 | } | ||