-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGrowBox.ino
161 lines (119 loc) · 3.76 KB
/
GrowBox.ino
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
AUTOMATED GROW BOX FOR MUSHROOMS project
@author: Keivan Amini, github: https://github.com/keivan-amini
@last review: 27-04-2022
@place: Ferrara, Italy
*/
//**************************************************
#include "DHT.h" // library for the humidity-temperature sensor
#include <LiquidCrystal_I2C.h> // library for the LCD Display
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
const float minimum_humidity = 80.00; // (%)
const float minimum_temp = 26; // (°C)
#define DHTPIN 10 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
unsigned long myTime; // for the time management
extern volatile unsigned long timer0_millis;
// ************************************************
void setup() {
Serial.begin(9600);
Serial.println(F("Let's start!"));
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
dht.begin();
lcd.init();
// Print a message to the LCD.
lcd.backlight();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("GROW BOX - PoliPolo");
lcd.setCursor(0,1);
lcd.print("PLAM and Phylor for");
lcd.setCursor(0,2);
lcd.print("LabAperto Ferrara");
lcd.setCursor(0,3);
lcd.print("PopUp 29 APR 2022");
}
// ***************************************************
void loop() {
// Wait a few seconds between measurements
delay(2000);
float humidity = dht.readHumidity();
float temp = dht.readTemperature();
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(humidity) || isnan(temp) || isnan(f)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, humidity);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(temp, humidity, false);
Serial.print(F("Humidity: "));
Serial.print(humidity);
Serial.print(F("% Temperature: "));
Serial.print(temp);
Serial.print(F("°C "));
Serial.print(f);
Serial.print(F("°F Heat index: "));
Serial.print(hic);
Serial.print(F("°C "));
Serial.print(hif);
Serial.println(F("°F"));
// Print measured temperature and humidity on the LCD Display
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Temperatura:");
lcd.setCursor(13,0);
lcd.print(temp);
lcd.setCursor(19,0);
lcd.print("C");
lcd.setCursor(0,1);
lcd.print("Umidita:");
lcd.setCursor(9,1);
lcd.print(humidity);
lcd.setCursor(15,1);
lcd.print("%");
// Set the lights ON for 12 hours, then turn them off
Serial.print("Time: ");
myTime = millis();
Serial.println(myTime); // prints time since program started
digitalWrite(4, LOW);
if (myTime > 43200000) {
digitalWrite(4, HIGH);
}
// when 24h passed, impose the end of the loop
if (myTime > 86400000) {
noInterrupts ();
timer0_millis = 0;
interrupts ();
}
// setting the atomizer and the fan ON if the humidity is under the minimum humidity
if (humidity < minimum_humidity ) {
digitalWrite(6, LOW);
digitalWrite(7,LOW);
lcd.setCursor(0,2);
lcd.print("Umidificatore: ON");
}
else {
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
lcd.setCursor(0,2);
lcd.print("Umidificatore: OFF");
}
// setting the hot resistance ON if the temperature is under the minimum temperature
if (temp < minimum_temp ) {
digitalWrite(5, LOW);
lcd.setCursor(0,3);
lcd.print("Resistenza: ON");
}
else {
digitalWrite(5, HIGH);
lcd.setCursor(0,3);
lcd.print("Resistenza: OFF");
}
}