-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.ino
43 lines (38 loc) · 1.23 KB
/
code.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
#include <DFRobot_DHT20.h> //set pin no of ardinuo to which led is connected
DFRobot_DHT20 dht20;
#define pwm 9
float t=0;
const int ledPin = 8; //redled
const int ledPin2 = 7;//blueled
void setup() {
Serial.begin(115200);
pinMode(ledPin, OUTPUT);//Change to output my pins
pinMode(ledPin2, OUTPUT);
while(dht20.begin()){
Serial.println("Initialize sensor failed");
delay(1000);
}
digitalWrite(ledPin2,LOW);//Turn off LED
digitalWrite(ledPin,LOW);//Turn off LED
}
void loop() {
t = dht20.getTemperature();//temperature value centigrades
if(t>=25)//if temperature above of specified degrees
{
digitalWrite(ledPin,HIGH);//red led activated
digitalWrite(ledPin2,LOW);
Serial.print("Red led activated ");
analogWrite(pwm,255);//fan speed is increased
}
else if(t<25)//if temperature is under specified degrees
{
digitalWrite(ledPin2,HIGH);
digitalWrite(ledPin,LOW);//blue led activated
Serial.print("Blue led activated ");
analogWrite(pwm,51);//fan operates on normal rpm
}
//Get ambient temperature
Serial.print("temperature:"); Serial.print(dht20.getTemperature());Serial.print("C ");
Serial.println(analogRead(A0));
delay(1500);
}