Skip to content

Instantly share code, notes, and snippets.

@octplane
Created July 8, 2012 21:22
Show Gist options
  • Save octplane/3072851 to your computer and use it in GitHub Desktop.
Save octplane/3072851 to your computer and use it in GitHub Desktop.
ePIR arduino sample code
#include <SoftwareSerial.h>
// This is the input and output of the ePIR
#define rxPin 3
#define txPin 2
// we will switch on and off the onboard led.
#define onBoardLed 13
// set up a new serial port
SoftwareSerial ePir = SoftwareSerial(rxPin, txPin);
// Reads a character and return it
static char getCh() {
while(!ePir.available())
;
blink();
return ePir.read();
}
int up=0;
void blink() {
if(up%5 ==0 ) {
digitalWrite(onBoardLed, HIGH);
} else {
digitalWrite(onBoardLed, LOW);
}
up = up + 1;
}
void plint(String what) {
ePir.print(what);
blink();
}
void setup() {
// set the data rate for the SoftwareSerial port
Serial.begin(9600);
Serial.println("\n[EPIR]");
// ePIR communicates at 9600. This is important.
ePir.begin(9600);
// Initialize onboard LED
pinMode(onBoardLed, OUTPUT);
}
void loop() {
// Get Proximity detection status
plint("a");
Serial.print(getCh());
// Get proximity value
plint("b");
Serial.println(getCh(), DEC);
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment