-
Notifications
You must be signed in to change notification settings - Fork 0
/
arduinoCode
77 lines (66 loc) · 1.47 KB
/
arduinoCode
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
#include "DHT.h"
#define DHTPIN 7
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
#include"SoftwareSerial.h"
bool on = false , on1 = false;
int t_limit = 32;
char input;
#define relay2 12
#define relay1 11
void setup()
{
Serial.begin(9600);
dht.begin();
pinMode(relay1,OUTPUT);
pinMode(relay2,OUTPUT);
Serial.println("DHTxx test!");
digitalWrite(relay1 , HIGH);
digitalWrite(relay2 , HIGH);
}
void loop (){
float humidity = dht.readHumidity();
float t_C = dht.readTemperature();
float t_F = dht.readTemperature(true);
delay(2000);
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %\t");
Serial.print("Temperature: ");
Serial.print(t_C);
Serial.println(" *C and");
Serial.print(t_F);
Serial.println(" *F\t");
while(Serial.available()){
input = Serial.read();
if(input == 'a'){
if(on){
digitalWrite(relay1 , LOW);
on = false;
Serial.println("on1");
}else{
digitalWrite(relay1 , HIGH);
on = true;
Serial.println(input);
Serial.println("off1");
}
}
if(input == 'c'){
if(on1){
digitalWrite(relay2 ,LOW);
on1 = false;
Serial.println("on2");
}else{
digitalWrite(relay2 , HIGH);
on1 = true;
Serial.println("off2");
Serial.println(input);
}
}
}
if(t_C > t_limit){
digitalWrite(relay2 , LOW);
}else{
digitalWrite(relay2 , HIGH);
}
}