Hello,
I'm trying to trigger a servo with a parallax pir sensor
http://www.robotshop.com/ca/content/PDF/pir-sensor-documentation-v1-2-555-28027.pdf. I'm also using the
VarSpeedServo library.
Also, I'm using an Arduino mega 2560.
I modified some code I took from the Make magazine website
http://make-documents.s3.amazonaws.com/fv1fYSLfy6QRgANM.pdfI want the servo to start from a position, rotate to another position, wiggle a little and then come back to it's initial position. This is ok.
Now everything is almost fine.
Here's my problem; I install everything, upload the code and watch as the servo is triggered by the movement of my hands. nice, but then, the sensor seems to stay activated for about 3 seconds before shutting down. And if I keep moving, it just never shuts down, so the sequence is done once and if I keep moving it never gets to be triggered again.
Since the sensor will be in a crowded space, I would like it to be reset as soon as the action is over so it can start again.
I read something about these sensors saying that they work with a resistor that needs to go below a certain value to reset. Is that so? And if so, is there a way around it?
thanks in advance,
I just thought about pull-down resistors, could it solve my problem if I hook the sensor with that? I'll try it. (10 min. later)Well it didn't change the behavior of the setup, though I think it's better practice to kook it up this way.
here's my code
// Uses a PIR sensor to detect movement, buzzes a buzzer
// more info here: makeprojects.com/Project/PIR-Sensor-Arduino-Alarm/72/1
// email me, John Park, at jp@jpixl.net
//based upon:
// PIR sensor tester by Limor Fried of Adafruit
// tone code by michael@thegrebs.com
#include <VarSpeedServo.h>
VarSpeedServo myServo[1];
int ledPin = 13;
int inputPin = 22;
int pirState = LOW;
int val = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(inputPin, INPUT);
myServo[1].attach(10);
Serial.begin(9600);
}
void loop() {
val = digitalRead(inputPin);
if (val == HIGH)
{
digitalWrite(ledPin, HIGH);
myServo[1].slowmove(128, 120);
delay(100);
myServo[1].slowmove(110, 85);
delay(100);
myServo[1].slowmove(128, 85);
delay(100);
myServo[1].slowmove(110, 85);
delay(100);
myServo[1].slowmove(128, 85);
delay(100);
myServo[1].slowmove(47, 85);
if (pirState == LOW) // we have just turned on
{
pirState = HIGH;
}
}
else
{
digitalWrite(ledPin, LOW);
myServo[1].slowmove(47, 85);
if (pirState == HIGH)
{
pirState = LOW;
}
}
}