1 // ------------------------------------------------
2 // Controlling HC-SR501 through Particle Cloud
3 // @author Rahmadi Trimananda - UC Irvine
4 // ------------------------------------------------
5 // HC-SR501 Motion Detector
6 // Basically, this simple code detects motion and send the occurrences to the cloud
7 // We use the WKP port (port A7) to wake up the device when there is motion
9 // Based on tutorial: http://henrysbench.capnfatz.com/henrys-bench/arduino-sensors-and-input/arduino-hc-sr501-motion-sensor-tutorial/
16 // Setting up pins for input
19 // Get the MAC address
23 int64_t mac4 = (int64_t) mac[4];
24 int64_t mac5 = (int64_t) mac[5];
25 machineId = (mac4 * 256) + mac5;
30 // Basically delay to give time to send updates to Particle cloud.
31 // If we do less than this then it would fail publishing.
34 sprintf(keyBuffer, "%04x", machineId);
36 sprintf(dataBuffer, "%s -> motion-detected", Time.timeStr().c_str());
37 Particle.publish(keyBuffer, dataBuffer);
41 //String strTime(micros());
42 //Particle.publish("Time motion sensor", strTime.c_str());
45 System.sleep(SLEEP_MODE_DEEP, 0);