-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDoorbell.ino
148 lines (88 loc) · 2.54 KB
/
Doorbell.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_TSL2561_U.h>
int led = D6;
int com = D4;
int com2 =D3;
int light;
int val = 0;
int val2 = 0;
bool InLight = false;
bool OutLight = false;
Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345);
void configureSensor(void)
{
tsl.enableAutoRange(true);
tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS);
}
void readLight()
{
/* Get a new sensor event */
sensors_event_t event;
tsl.getEvent(&event);
/* Display the results (light is measured in lux) */
if (event.light)
{
light = event.light;
val = digitalRead(com);
val2 = digitalRead(com2);
//Particle.publish("ProximityTest", String(val));
//Particle.publish("MotionTest", String(val2));
//Particle.publish("VOltage test", String(com2));
if (val == 1 && val2 == 1)
{
Particle.publish("Proximity", String(val));
Particle.publish("Motion", String(val2));
Particle.publish("Alert", String(val + val2));
}
else if(val == 1 && val2 ==0)
{
Particle.publish("Possible Package",String(val));
}
else if(val == 0 && val2 == 1)
{
Particle.publish("Motion Further Away", String(val2));
}
if (light > 100 && !InLight || val2 == 0)
{
InLight = true;
digitalWrite(led, LOW); // sets the LED to the button's value
Particle.publish("Light", "Bright");
OutLight = false;
}
else if (light < 50 && !OutLight && val2 == 1)
{
OutLight = true;
// read the input pin
digitalWrite(led, HIGH); // sets the LED to the button's value
Particle.publish("Light", "Dim");
InLight = false;
}
}
else
{
/* If event.light = 0 lux the sensor is probably saturated
and no reliable data could be generated! */
Particle.publish("Sensor overload");
}
delay(300000);
val = 0;
val2 = 0;
}
void setup(){
Serial.begin(9600);
Particle.publish("Test");
pinMode(led, OUTPUT);
pinMode(com, INPUT);
pinMode(com2, INPUT);
/* Initialise the sensor */
if(!tsl.begin())
{
/* There was a problem detecting the ADXL345 ... check your connections */
Particle.publish("Ooops, no TSL2561 detected ... Check your wiring or I2C ADDR!");
while(1);
}
configureSensor();
}
void loop(){
readLight();
}