-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathArduinoTempSwitcherLCD.ino
More file actions
142 lines (99 loc) · 2.48 KB
/
ArduinoTempSwitcherLCD.ino
File metadata and controls
142 lines (99 loc) · 2.48 KB
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
#include <dht.h>
#include <LiquidCrystal.h>
dht DHT;
// acceptable temperatures in Celsius.
// switching occurs when the temp range moves outside these temperatures;
// cooling starts at the degree above TEMP_MAX and stops when TEMP_MIN is reached
#define TEMP_MIN 20
#define TEMP_MAX 22
//digital pin for the temp sensor
#define DHT11_PIN 8
// digital pin for the relay
#define RELAY_PIN 13
//constants for the number of rows and columns in the LCD
const int numRows= 4;
const int numCols= 20;
boolean powerOn = false;
unsigned long startTime;
//initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup(){
Serial.begin(9600);
pinMode(RELAY_PIN, OUTPUT); // sets the pin as output
lcd.begin(numCols, numRows);
lcd.print("Initializing....");
startTime = millis();
delay(1000);
}
void loop()
{
lcd.clear();
int chk = DHT.read11(DHT11_PIN);
lcd.setCursor(0,0);
int tempC = DHT.temperature;
lcd.print(DHT.temperature);
lcd.print((char)223);
lcd.print("C ");
lcd.print(DHT.temperature *180.0/100.0 + 32.0);
lcd.print((char)223);
lcd.print("F ");
lcd.setCursor(0,1);
lcd.print("Humidity: ");
lcd.print(DHT.humidity);
lcd.print("%");
lcd.setCursor(0,2);
lcd.print("min: ");
lcd.print(TEMP_MIN);
lcd.print((char)223);
lcd.print("C");
lcd.setCursor(10,2);
lcd.print("max: ");
lcd.print(TEMP_MAX);
lcd.print((char)223);
lcd.print("C");
if (tempC > TEMP_MAX){
if(! powerOn){
// turn fridge on
powerOn = true;
startTime = millis();
}
}
else if (tempC <= TEMP_MIN){
if(powerOn){
// turn fridge off
powerOn = false;
startTime = millis();
}
}
lcd.setCursor(0,3);
if(powerOn){
lcd.print("Cooling ");
digitalWrite(RELAY_PIN, HIGH);
}else{
lcd.print("Standby "); // power off
digitalWrite(RELAY_PIN, LOW);
}
for(int i=0; i<10; i++){
//update time 10 times (seconds) before taking another reading (so LED screen isn't too blinky)
long int seconds = (millis()-startTime)/1000;
long int minutes = seconds / 60;
seconds = seconds - minutes*60;
lcd.setCursor(8,3);
if(minutes>60){
long int hours = minutes/60;
minutes = minutes - hours*60;
lcd.print(hours);
lcd.print(":");
if(minutes<10){
lcd.print("0");
}
}
lcd.print(minutes);
lcd.print(":");
if(seconds<10){
lcd.print("0");
}
lcd.print(seconds);
delay(1000);
}
}