-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdehydrator.ino
87 lines (72 loc) · 1.73 KB
/
dehydrator.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
#include <dht.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define DHTTYPE DHT22
#define DHTPIN 3
#define HEATPIN 2
DHT dht(DHTPIN, DHTTYPE);
long tempSetpoint = 32; // Ìàêñèìàëüíàÿ òåìïåðàòóðà
long tempDiff = 2; // íà ñêîëüêî ðàçðåøåíî ñíèæàòü òåìïåðàòóðó äî ïîâòîðíîãî âêëþ÷åíèÿ îáîãðåâàòåëÿ
int power = 0; //OFF
int errorCountSensor = 0;
void setup() {
Serial.begin(9600);
Serial.println("Dehydrator automator started");
// initialize digital pin 13 as an output.
pinMode(HEATPIN, OUTPUT); // Èñïîëüçóåì ïèí äëÿ âêëþ÷åíèÿ íàãðåâàòåëÿ
lcd.begin();
lcd.setCursor(0, 1);
lcd.print("Level:");
lcd.print(tempSetpoint);
lcd.setCursor(8, 1);
lcd.print("+-");
lcd.setCursor(10, 1);
lcd.print(tempDiff);
}
// the loop function runs over and over again forever
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t) || isnan(h)) {
Serial.println("Failed to read from DHT");
errorCountSensor++;
} else {
lcd.setCursor(0, 0); // 1 ñòðîêà
lcd.print("T:");
lcd.setCursor(2, 0);
lcd.print(t);
lcd.setCursor(8, 0);
lcd.print("E:");
lcd.setCursor(10, 0);
lcd.print(errorCountSensor);
if(power==1){
// âêëþ÷åíî. Ïðîâåðÿåì
if(t>tempSetpoint){
power = 0;
}
}else{
// Âûêëþ÷åí ïîäîãðåâ. Íóæíî âêëþ÷èòü?
if(t<tempSetpoint-tempDiff){
power=1;
}
}
}
if(power==1){
print_heat_status(1);
digitalWrite(HEATPIN, HIGH);
}else{
print_heat_status(0);
digitalWrite(HEATPIN, LOW);
}
delay(3000);
}
void print_heat_status(int flag){
lcd.setCursor(13, 1);
if(flag==1){
lcd.print("ON ");
}else{
lcd.print("OFF");
}
}