-
Notifications
You must be signed in to change notification settings - Fork 0
/
Temperature based Fan Speed Controller
92 lines (91 loc) · 1.74 KB
/
Temperature based Fan Speed Controller
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
ARDUINO CODE
#include <DHT.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
float temp;
DHT dht(7,DHT22);
#define fan 9
void setup() {
// giving fan current ...... Making fan pin 9 for output:
pinMode(fan,OUTPUT);
//Setting LCD's number of rows and column:
lcd.begin(16,3);
//printing message on the LCD
lcd.setCursor(3,1);
lcd.print("Project");
delay(1000);
lcd.clear();
dht.begin();
}
void loop() {
if(analogRead(A0)>10)
{
lcd.setCursor(3,0);
lcd.print("Recording");
lcd.setCursor(2,1);
lcd.print("Temperature...");
delay(3000);
lcd.clear();
lcd.setCursor(0,2);
temp=dht.readTemperature();
lcd.setCursor(5,1);
lcd.print(temp);
lcd.print(" C");
delay(3000);
lcd.clear();
if(temp<20)
{
analogWrite(9,0);
lcd.setCursor(1,1);
lcd.print("Fan Off");
delay(2000);
lcd.clear();
}
else if(temp>20 && temp<=24)
{
analogWrite(fan, 51);
lcd.setCursor(1,1);
lcd.print("Fan Speed: 20%");
delay(2000);
lcd.clear();
}
else if(temp>=24 && temp<=26)
{
analogWrite(fan, 102);
lcd.setCursor(1,1);
lcd.print("Fan Speed: 40%");
delay(2000);
lcd.clear();
}
else if(temp>=26 && temp<=28)
{
analogWrite(fan, 153);
lcd.setCursor(1,1);
lcd.print("Fan Speed: 60%");
delay(2000);
lcd.clear();
}
else if(temp>=28 && temp<=30)
{
analogWrite(fan, 200);
lcd.setCursor(1,1);
lcd.print("Fan Speed: 80%");
delay(2000);
lcd.clear();
}
else if(temp>=30)
{
analogWrite(fan, 255);
lcd.setCursor(1,1);
lcd.print("Fan Speed: 100%");
delay(2000);
lcd.clear();
}
}
else{
lcd.setCursor(1,1);
lcd.print("No one sitting");
analogWrite(9,0);
delay(3000);
}
}