Hello everyone, just got my first PIR and having fun but I cannot figure out why it does not work consistently. I can shake my hand in front of it and will register the movement however, there is a good chance that it will also not see me.
Is there a refresh rate on these that is slow to pick up moving objects?
I have attached my code and pictures of my hardware for reference.
/*
* MotorKnob
*
* A stepper motor follows the turns of a potentiometer
* (or other sensor) on analog input 0.
*
* http://www.arduino.cc/en/Reference/Stepper
* This example code is in the public domain.
*/
#include <Stepper.h>
// change this to the number of steps on your motor
#define STEPS 200
// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
Stepper stepper1(STEPS, 8, 9, 10, 11);
Stepper stepper2(STEPS, 4, 5, 6, 7);
// the previous reading from the analog input
int val = 50;
int previous = 1000;
int delta = 0;
const int leftSensorPin = A1;
const int rightSensorPin = A2;
int leftSensorValue = 0;
int rightSensorValue = 0;
const int PIRpin = A0;
int PIRvalue = 0;
void setup() {
stepper1.setSpeed(200); // set the speed of the motor to 200 RPMs
stepper2.setSpeed(200); // set the speed of the motor to 200 RPMs
Serial.begin(9600); //Open serial communication
Serial.println("Everyone ready? Here we go!");
Serial.println("Left \t Right \t Delta");
}
void loop() {
// get the sensor value
// sensor reading
PIRvalue = analogRead(PIRpin);
leftSensorValue = analogRead(leftSensorPin);
delay(5);
rightSensorValue = analogRead(rightSensorPin);
delay(5);
Serial.print(PIRvalue);
Serial.print("\t ");
Serial.print(leftSensorValue);
Serial.print("\t ");
Serial.print(rightSensorValue);
Serial.print("\t ");
delta = (leftSensorValue - rightSensorValue);
Serial.println(delta);
if(PIRvalue < 30) { //If something moves attack
for (int x=0; x < 1000; x++){
stepper1.step(1);
stepper2.step(1);
}
}
else{ //If no movement, track sun
if(delta > 10){
stepper2.step(delta);
}
else if(delta < -10){
stepper1.step(delta);
}
}
delay(1000); //1000ms = 1s
}

