I've been trying to set up a body tracking system with an eltec 442-3 pyroelectric sensor mounted to a servo. I sweep the servo over 180 degrees and then calculate the extrema over a sweep. If the difference between the max and min is greater than a benchmark, I count that as a hit.
Problem is, there is a ton of noise on the output which seems to completely overrun the sensor itself. Has anyone else had this problem or been able to get the sensor to work properly? When I run my program, I get lots of false hits, and when I decrease the sensitivity I then lose human tracking capability. I even run the program with the sensor covered, and i still get a large amount of false hits. Is this normal? I checked out the sensor with a multimeter, it seems to function properly. Any help would be much appreciated.
here's my code:
#include <ServoTimer1.h>
#define servo1pin 9
#define pyropin 0
#define servostep 5
#define hitdiff 400
#define servo1delay 20
ServoTimer1 servo1;
int diff = 0;
int pos = 0;
int range = 180;
int center = 90;
int i;
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
servo1.attach(servo1pin); // control the servo on the desired pin
}
void loop() {
diff = 0;
pos = 0;
for(i=0; i < 2; i++){ // perform scan for both directions
scan(180, 90, i);
if(diff >= hitdiff){
Serial.print("Hit at:");
Serial.println(pos);
}
else{
//continue scanning
Serial.println("No hit");
}
}
}
void scan(int range, int center, int dir){
int j;
int pyroout; // holder for pyro sensor output
int maxv = 0; // maximum value
int minv = 1024; // minumum value
int maxp = 0; // position of max value
int minp = 0; // position of min value
int a = center - range/2;
int b = center + range/2;
if(a < 0 || b > 180){
return;
}
if(dir == 0){
for(j = a; j < b; j=j+servostep){
delay(servo1delay);
servo1.write(j);
pyroout = analogRead(pyropin);
if(pyroout > maxv){ //check to see if new max
maxv = pyroout;
maxp = j;
}
else if(pyroout < minv){ //or to see if new min
minv = pyroout;
minp = j;
}
}
}
else if(dir == 1){
for(j = b; j > a; j=j-servostep){
delay(servo1delay);
servo1.write(j);
pyroout = analogRead(pyropin);
if(pyroout > maxv){
maxv = pyroout;
maxp = j;
}
else if(pyroout < minv){
minv = pyroout;
minp = j;
}
}
}
diff = maxv - minv;
pos = (maxp + minp)/2;
}