Noob project - motion tracker

I'm not quite sure if the Arduino will work well with an external interrupt, I once tried and realized that the Arduino is kinda limited in this aspect.

Therefore, I would suggest something along the lines of, while the servo is going left to right, you would test the values (with an analogRead) read by the IR sensor. When (and if) this value would go over a certain threshold (defined by you), the Arduino would stop the panning and flash the leds, as you said.

It would then resume the panning and detecting... I would just give it a certain minimum amount of time (let's say 10seconds) between each time it would actuate the leds, because otherwise it would just be constantly detecting the same person and lighting up the leds.

Here's some code of my suggestion:

int IRthreshold = 300;
const int pinIN = 0;
const int pinLED = 13;
const int pinSERVO = 6;

void setup()
{
  pinMode(pinLED, OUTPUT);
  pinMode(pinSERVO, OUTPUT);
}

void loop()
{
  moveServo()
  {
    // This function makes the servo go left to right [u]one step at a time[/u];
    // It cannot be stuck inside just going left to right;
  }

  if(analogRead(pinIN) >= IRthreshold)  // Detects someone
  {
    digitalWrite(pinLED, HIGH);
    delay(2000);  //  Led turned on for 2 seconds
    digitalWrite(pinLED, LOW);
  }
}

Now, this might not be the best way to do what you wanted, but it works :slight_smile: And, because of the delay(), it will not move the servo until the led is turned off.

To secure the fact that it won't detect another person for, let's say, 10 seconds, you need to use the Time.h library. But first see if this code makes sense...