Hi all
I am trying to get my Photon to sleep so it can save powerbank/battery energy
However, I tried the following code and it does not seem to get my Photon to wake up or it triggers the notifications at a time interval.
void setup() {
pinMode(D0, INPUT);
}
void loop() {
if (digitalRead(D0) == HIGH) {
Spark.publish("office-motion", "OFFICE", 60, PRIVATE);
delay(15000);
while (digitalRead(D0) == HIGH); // hang tight here until motion stops
System.sleep(digitalRead(D0),RISING);
}
}
Interestingly, I am able to get this to work instead which is quite weird.
void setup() {
pinMode(D0, INPUT);
}
void loop() {
if (digitalRead(D0) == HIGH) {
Spark.publish("office-motion", "OFFICE", 60, PRIVATE);
delay(15000);
while (digitalRead(D0) == HIGH); // hang tight here until motion stops
System.sleep(digitalRead(D0),CHANGE);
}
}
I understand that when the PIR sensor detect something so it will be ‘HIGH’ then it will send a notification. With this, I assume that it will change the state from ‘LOW’ to HIGH’.
So by using this code, ‘System.sleep(digitalRead(D0),RISING);’. It should be correct but it does not seem to work.
Am I missing something or I just have a bad PIR motion sensor?
Any comments on this issue will be great!
Thank guys.
Source: [Webhooks] Super Simple Motion Activated Push Notifications
