pan/tilt with motion detector ?

i’ve tried to setup a pan tilt servo and a pir alarm. but the servos are interrupted by pir alarm.
is there a way to run both or stop pir after a set time?
i dont remember where but i thought i saw that you could have camera respond to motion area?

this is pan tilt code…

#include <Servo.h>  

int ServoHorizontalPin = 3;   
int ServoVerticalPin =  4;   
int HorizontalPotPin = A0;  
int VerticalPotPin = A1;  
int ServoH_Min = 50;  
int ServoH_Max = 180; 
int ServoV_Min = 0; 
int ServoV_Max = 180; 

Servo HorizontalServo;  
Servo VerticalServo;    

int HorizontalPotValue;         
int HorizontalServoPosition;    
int VerticalPotValue;         
int VerticalServoPosition;    

void setup()   

void loop()  
  HorizontalPotValue  = analogRead(HorizontalPotPin); 
  VerticalPotValue  = analogRead(VerticalPotPin);  
  HorizontalServoPosition  = map(HorizontalPotValue, 0, 1023, ServoH_Min , ServoH_Max); 
  VerticalServoPosition  = map(VerticalPotValue, 0, 1023, ServoV_Min , ServoV_Max);   

All I see if some code that will move two servos based on the values of two potentiometers. How does a PIR figure into this?

where or how would i put it in so it doesnt stall servo?

looking at : "Demonstration code for several things at the same time" post,should i be putting pir code in its own {} in loop ?

Use a write statement before you use attach. This will keep the servos from moving past their limits when the servo starts.


IMO, you're much better off using microseconds to set servo position than pretending you're setting the position with degrees.

I posted some joystick/servo code here which you might find useful. Reply #23 has links to videos of the code in action.

The code is non-blocking so you should be able to add code to check the PIR sensors. It will take a bit of work to use the sensor data to produce meaningful servo position targets but once you have a target position figured out, the algorithms in the code will move the servos to these targets smoothly.

all i see is "it didnt work" in replies and i dont get how they got it to work. then when i compiled it saved it and i lost my code anyway. changed that setting. thanks anyway. i'll go with sweep,eliminate joystick and try to figure out a manual rest on pir.