-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathnode-xbee-code.ino
More file actions
71 lines (53 loc) · 1.81 KB
/
node-xbee-code.ino
File metadata and controls
71 lines (53 loc) · 1.81 KB
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
#include <dht.h> //Library for DHT11 Humidity
#define dht_dpin A0 // DTH11 Data pin connected to AO of arduino
#define led 2 // Led connected to Pin D2
#define ldr A1 // LDR connected to Pin A1
dht DHT; // Creating DHT function
void setup() {
// initialize serial:
Serial.begin(2400); // Initiliaze Hardware serial for xbee
pinMode(2, OUTPUT); // Pin direction of LED to Output as it sends current
}
void loop() { // Continous loop
// if there's any serial available, read it:
DHT.read11(dht_dpin); // Reading DHT11 using the library
int lig = analogRead(ldr); // Reading analog values from LDR
int ligp = map(lig, 0, 1023, 0, 100); // Mapping the 10bit resolution ADC to 0 to 100
int h = DHT.humidity; // Humidity value
int t = DHT.temperature; // Temperature value
while (Serial.available() > 0) { // Checking for any data on Xbee
int red = Serial.parseInt(); // look for the next valid integer in the incoming serial stream
if (Serial.read() == '!') // Check if the next Serial data is '!'
{
if(red == 1) // if the recieved data is 1!
{
Serial.print(h,DEC); // Send humidity value with '!'
Serial.print("!");
}
else
if(red == 2) // if the recieved data is 2!
{
Serial.print(t,DEC); // Send Temperature value with '!'
Serial.print("!");
}
else
if(red == 3) // if the recieved data is 3!
{
Serial.print(ligp,DEC); // Send Light value with '!'
Serial.print("!");
}
else
if(red == 4) // if the recieved data is 4!
{
digitalWrite(2, HIGH); // Turn ON the LED
delay(100);
}
else if(red == 5) // if the recieved data is 5!
{
digitalWrite(2, LOW); //Turn OFF the LEd
delay(100);
Serial.print("!attify!"); // Send the AES key
}
}
}
}