-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.cpp
67 lines (56 loc) · 1.33 KB
/
code.cpp
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
#include <Adafruit_Sensor.h>
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
int moisturePin = A0;
int smokePin = A1;
int ldrPin = A2;
int smokeThreshold = 500;
int moistureThreshold = 500;
int ldrThreshold = 500;
int smokeLedPin = 3;
int moistureLedPin = 4;
int ldrLedPin = 5;
int tempLedPin = 6;
void setup() {
Serial.begin(9600);
pinMode(smokePin, INPUT);
pinMode(moisturePin, INPUT);
pinMode(ldrPin, INPUT);
pinMode(smokeLedPin, OUTPUT);
pinMode(moistureLedPin, OUTPUT);
pinMode(ldrLedPin, OUTPUT);
pinMode(tempLedPin, OUTPUT);
dht.begin();
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
int smokeValue = analogRead(smokePin);
int moistureValue = analogRead(moisturePin);
int ldrValue = analogRead(ldrPin);
if (smokeValue > smokeThreshold) {
digitalWrite(smokeLedPin, HIGH);
} else {
digitalWrite(smokeLedPin, LOW);
}
if (moistureValue > moistureThreshold) {
digitalWrite(moistureLedPin, HIGH);
} else {
digitalWrite(moistureLedPin, LOW);
}
if (ldrValue > ldrThreshold) {
digitalWrite(ldrLedPin, HIGH);
} else {
digitalWrite(ldrLedPin, LOW);
}
if (!isnan(h) && !isnan(t)) {
if (t > 25.0) {
digitalWrite(tempLedPin, HIGH);
} else {
digitalWrite(tempLedPin, LOW);
}
}
delay(1000);
}