Friday, March 15, 2013

Using an ePIR Motion Detector with a Maple Mini

The Zilog ePIR module is an easy-to-use motion detector. Using the the serial communication mode, the controller polls the deice at regular intervals by sending a single command character. The ePIR responds with one character: Y if motion has been detected and N if no motion has been detected.


Connections


Pin 1 on the ePIR is marked '1'.

ePIR    Maple Mini
1       GND
2       VCC
3       TX1 (26) - Serial1
4       RX1 (25) - Serial1 (with 10k pull-up resistor)
6       GND


Code


The following code checks for motion once per second and, for this example, prints the status to the SerialUSB monitor.

static const char STATUS_CMD = 'a';
static const int DELAY = 1000;

static char getch() {
  // Wait if ePIR not avail. or busy
  while (!Serial1.available())
    ;
  return Serial1.read();
}

void setup() {
  Serial1.begin(9600);
}

void loop() {
  Serial1.print(STATUS_CMD);
  SerialUSB.println(getch()); 
  delay(DELAY);




No comments:

Post a Comment