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/
11 int pirValue; // Place to store read PIR Value
17 // Setting up pins for input
20 // Get the MAC address
24 int64_t mac4 = (int64_t) mac[4];
25 int64_t mac5 = (int64_t) mac[5];
26 machineId = (mac4 * 256) + mac5;
31 // Basically delay to give time to send updates to Particle cloud.
32 // If we do less than this then it would fail publishing.
35 sprintf(keyBuffer, "%04x", machineId);
37 sprintf(dataBuffer, "motion-detected");
38 Particle.publish(keyBuffer, dataBuffer);
41 System.sleep(SLEEP_MODE_DEEP, 0);