diff options
Diffstat (limited to 'src/main/main.ino')
-rw-r--r-- | src/main/main.ino | 85 |
1 files changed, 85 insertions, 0 deletions
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 | } | ||