-
Notifications
You must be signed in to change notification settings - Fork 0
/
temp_hum_sens.ino
78 lines (68 loc) · 1.66 KB
/
temp_hum_sens.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
67
68
69
70
71
72
73
74
75
76
77
78
#include "DHT.h"
#define P_RESISTOR A0 // Photoresistor at Arduino analog pin A0
#define KY013 A1 // Analog temp sensor at A1
#define Motor 7
DHT dht;
String incoming = "";
int photo_value;
int analog_temp_value;
float humidity;
float temperature;
int val;
void setup()
{
Serial.begin(9600);
dht.setup(8); // data pin 8
pinMode(P_RESISTOR, INPUT);// Set photo Resistor - A0 pin as an input
pinMode(KY013, INPUT);// Set Analog Temp sensor - A1 pin as an input
pinMode(Motor, OUTPUT);
pinMode(12, OUTPUT);
digitalWrite(Motor, LOW);
// digitalWrite(12, HIGH);
}
void loop()
{
delay(2000);
photo_value = analogRead(P_RESISTOR);
analog_temp_value = analogRead(KY013);
humidity = dht.getHumidity();
temperature = dht.getTemperature();
Serial.print(
String(humidity) + ';' +
String(temperature) + ';' +
String(photo_value) + ';' +
String(analog_temp_value)+ ';' + '\n');
delay(1000); // 1 second for the response
if (Serial.available() > 0) {
incoming = Serial.readString();
if(incoming.substring(0,3) == "TON")
{
digitalWrite(Motor, HIGH);
}
else
{
digitalWrite(Motor, LOW);
}
if(incoming.substring(4,7) == "HON")
{
digitalWrite(12, HIGH);
}
else
{
digitalWrite(12, LOW);
}
if(incoming.substring(8,11) == "LON")
{
//Serial.write("DEBUG LIGHT");
analogWrite(A3, 1023);
analogWrite(A4, 1023);
analogWrite(A5, 1023);
}
else
{
analogWrite(A3, 0);
analogWrite(A4, 0);
analogWrite(A5, 0);
}
}
}