-
Notifications
You must be signed in to change notification settings - Fork 0
/
fan_button.ino
66 lines (50 loc) · 1.15 KB
/
fan_button.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
#include <dht.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define DHT11_PIN 7
LiquidCrystal_I2C lcd(0x27, 2,1,0,4,5,6,7,3,POSITIVE);
dht DHT;
int relay1 = 11;
int but1 = 13;
int butState = 0;
int relayS = 0;
int pushed = 0;
void setup(){
pinMode(relay1, OUTPUT);
Serial.begin(9600);
lcd.begin(16,2);
lcd.clear();
lcd.print("Temp is C");
lcd.setCursor ( 0, 1 );
lcd.print("Fan status ~");
pinMode(but1,INPUT);
pinMode(relay1,OUTPUT);
}
void loop(){
butState = digitalRead(but1);
if(butState == LOW && relayS == LOW){
pushed = 1-pushed;
delay(100);
}
relayS = butState;
if(pushed==LOW){
Serial.println("on");
digitalWrite(relay1,LOW);
int chk = DHT.read11(DHT11_PIN);
lcd.setCursor ( 9, 0 );
lcd.print(DHT.temperature);
lcd.setCursor ( 13, 1 );
delay(5000);
if(DHT.temperature > 20){
digitalWrite(relay1, LOW);
lcd.print("ON ");}
else{
digitalWrite(relay1, HIGH);
lcd.print("OFF");}
}
else{
Serial.println("off");
digitalWrite(relay1,HIGH);
}
delay(150);
}