Notes About Working with Various Arduino & Netduino Microcontroller Boards

Saturday, November 24, 2012

Using an ePIR Motion Detector with an Arduino Due

I got my Arduino Due yesterday from Sparkfun and wanted to do a quick test. I've had a Zilog ePIR motion detector for awhile, but hadn't experimented with it either, so here's a quick sketch that reads the status of the ePIR every half second. The value returned from the sensor isY if motion is detected and N if no motion is detected. This example does not include ambient light compensation or other adjustment in the sensitivity of the detector in the interest of simplicity.

In this example, the ePIR is connected in serial mode (via Serial1 on the Arduino Due).

Connections from the ePIR board to the Arduino Due:

ePIR   -->  Arduino Due   
pin 1       GND
pin 2       3.3V
pin 3       Digital 18 (TX1)
pin 4       Digital 19 (RX1) + 10k pull-up resistor
pin 6       3.3V  (no light level correction)

Here is the code that prints the status of the motion detector to the serial console:

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

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

void setup() {
  // Serial console
  Serial.begin(57600);
  Serial.println("\n[EPIR]");
  // Serial1 connected to ePIR via TX1 & RX1 on Due
  Serial1.begin(9600);
}

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


This is similar to the Arduino Leonardo, which has Serial1 connected to digital pins 0 and 1. The code above works with a Leonardo with appropriate connections (wire from ePIR pin 3 connected to Leonardo digital pin 1 [TX1] & from ePIR pin 4 to digital pin 0 [RX1]).

See also: Zilog ePIR documentation (which includes information on all of the commands used with the detector).

You can't use the RX0 TX0 pins, since Serial used to access the serial console. Serial2 (pins 16 & 17 are TX2 & RX2) and Serial3 (pins 14 & 15 are TX3 & RX3) are also available on the Arduino Due.

On another note, I've had intermittent problems with the Arduino Due programming interface device driver on my Windows 7 machine, so I'm using my Mac Mini to work with the Due until I figure out causes the frequent blue screen of death when uploading sketches to the Due.  

No comments:

Post a Comment