As I am a complete arduino novice...I need some Help!
I am trying to use a PIR (Essence Security Ltd) sensor to trigger a 180 degree turn of a servo, followed by a 3 minute gap and then the servo turning back 180 degrees to its original position.
I am using it to turn on a film projector, wait for the film to finish and then turn the projector off.
Does anyone know any suitable code for this? or how I can combine the servo code I have written with code for a PIR motion sensor
The Essence website doesn't have much on the PIR.
Do you know how the trigger condition is indicated?
Relay closure?
loop ()
{
if (PIR_TRIGGERED ())
{
myServo.write (180);
for (seconds=0; seconds < 180; ++ seconds) {
delay (1000);
}
myServo.write (0);
// May be a delay here to avoid immediate retriggering
// and damage to the projector bulb
}
}
I have realised that I could do the same thing with a push button or a switch, which is also more in context with the installation I am building.
Could I apply the code you have written to a push button? I am aware that buttons and switches work in terms of HIGH and LOW, but Servos work in 0-180 degrees so how do I deal with this?
Sorry if this is all very obvious! I have tried these instructions:
If you look, I've written the example with a simple "PIR_TRIGGERED ()".
This could be anything - a simple macro, or a function that could read either a hardware pin, serial message, and I2C device, or just a simple table or flag.
The function simply has to return a one or a zero (strictly speaking, all it has to return is zero or non-zero).
If it returns a non-zero value, then the code following the "if" will be executed, so the servo turns to 180, there's a pause of 180 seconds, then the servo returns to zero.
If the function returns zero, then "loop" simply gets executed again, so the function/macro "PIR_TRIGGERED" gets called again.
Sorry, missed the bit about jitter.
This could be a power-supply issue (are you just using the USB to power the whole thing?), or possibly an earth (ground/gnd) problem.
Or an old servo with a dirty pot.