First work of getting PIR to work
This commit is contained in:
parent
a1ca1f589f
commit
19c530a054
|
|
@ -0,0 +1,50 @@
|
||||||
|
|
||||||
|
#define MY_NODE_ID 143
|
||||||
|
// Enable debug prints
|
||||||
|
#define MY_DEBUG
|
||||||
|
|
||||||
|
// Enable and select radio type attached
|
||||||
|
//#define MY_RADIO_RF24
|
||||||
|
#define MY_RADIO_NRF5_ESB
|
||||||
|
//#define MY_RADIO_RFM69
|
||||||
|
//#define MY_RADIO_RFM95
|
||||||
|
|
||||||
|
#include <MySensors.h>
|
||||||
|
|
||||||
|
uint32_t SLEEP_TIME = 5000; // Sleep time between reports (in milliseconds)
|
||||||
|
#define DIGITAL_INPUT_SENSOR 6 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!)
|
||||||
|
#define LED 10
|
||||||
|
#define CHILD_ID 1 // Id of the sensor child
|
||||||
|
|
||||||
|
// Initialize motion message
|
||||||
|
MyMessage msg(CHILD_ID, V_TRIPPED);
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
pinMode(DIGITAL_INPUT_SENSOR, INPUT); // sets the motion sensor digital pin as input
|
||||||
|
hwPinMode(LED,OUTPUT_D0H1);
|
||||||
|
pinMode(LED,OUTPUT);
|
||||||
|
digitalWrite(ledPin, HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
|
void presentation()
|
||||||
|
{
|
||||||
|
// Send the sketch version information to the gateway and Controller
|
||||||
|
sendSketchInfo("Motion Sensor", "1.0");
|
||||||
|
|
||||||
|
// Register all sensors to gw (they will be created as child devices)
|
||||||
|
present(CHILD_ID, S_MOTION);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
// Read digital motion value
|
||||||
|
bool tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;
|
||||||
|
|
||||||
|
Serial.println(tripped);
|
||||||
|
send(msg.set(tripped?"1":"0")); // Send tripped value to gw
|
||||||
|
|
||||||
|
// Sleep until interrupt comes in on motion sensor. Send update every two minute.
|
||||||
|
sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME);
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Reference in New Issue