blob: bdab1906fff8ca77fa65a6099df332fb8b4fcf4b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
#define TEMP_SENSOR_PIN 14
#define HUMIDITY_SENSOR_PIN 14
#define FAN_PIN 15
#define CO2_PIN 16
#define ULTRASONIC_PIN 17
#define CHECK_FREQUENCY 1 // check sensors every second
#define HUMIDITY_DESIRED 75
#define HUMIDITY_VARIATION 3 // ultrasonic turns on at (75 - 3 = 72) and off
// at (75 + 3 = 78)
// Tempature + Humidity Sensor
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#define DHTTYPE DHT11
#define DHTPIN TEMP_SENSOR_PIN
DHT_Unified dht(DHTPIN, DHTTYPE);
int get_humidity () {
// Get temperature event and print its value.
sensors_event_t event;
dht.temperature().getEvent(&event);
if (isnan(event.temperature)) {
Serial.println(F("Error reading temperature!"));
}
else {
return event.temperature;
/* Serial.print(F("Temperature: ")); */
/* Serial.print(event.temperature); */
/* Serial.println(F("°C")); */
}
}
int get_tempature () {
sensors_event_t event;
// Get humidity event and print its value.
dht.humidity().getEvent(&event);
if (isnan(event.relative_humidity)) {
Serial.println(F("Error reading humidity!"));
}
else {
return event.relative_humidity;
/* Serial.print(F("Humidity: ")); */
/* Serial.print(event.relative_humidity); */
/* Serial.println(F("%")); */
}
}
int get_co2 () { ; }
bool start_ultrasonic () { ; }
bool stop_ultrasonic () { ; }
bool start_fan () { ; }
bool stop_fan () { ; }
bool log ( int humidity, int temp, int co2 ) {
Serial.printf("Tempature: %d\tHumidity: %d\tCO2: %d\n",
humidity, temp, co2);
}
void setup () {
Serial.begin(115200);
dht.begin(); /* temp/humidity sensor */
}
void loop() {
delay(CHECK_FREQUENCY * 1000);
int humidity = get_humidity();
int temp = get_tempature();
int co2 = get_co2();
if ( humidity < (HUMIDITY_DESIRED - HUMIDITY_VARIATION) ) {
start_ultrasonic();
stop_fan();
} else if ( humidity > (HUMIDITY_DESIRED + HUMIDITY_VARIATION) ) {
start_fan();
stop_ultrasonic();
} else {
; // keep doing the same
}
log(humidity, temp, co2);
}
|