My Sensor seems to be not working/be slow.

I have been working on a project for my robotics class and I have been writing code and I got the PIR sensor to work and my LED array to correctly work. BUT when I decided to add a servo that is continuously rotating 180 degrees at all times (not connected to the sensor in any way) it seems like the sensor does not set off the LED array anymore after the addition of the servo. I was wondering if someone would be kind enough to check out my code to see if I have missed something. That would be greatly appreciated and I thank you for your time. If anyone would like pictures of my project please let me know. I don’t think it is a problem with my board because I have checked over it a million times.

#include <Servo.h>
Servo myservo;
int pos = 0;
int LEDArray = {3, 5, 6, 9, 10};
int numOfLEDs = 5;
int pirState = LOW;
int pirVal = 0;
int pirPin = 12;

void setup() {

Serial.begin(9600);
pinMode(pirPin, INPUT);
int i;
for(i = 0; i < numOfLEDs; i++) {
pinMode(LEDArray*, OUTPUT);*

  • }*
  • {*
  • myservo.attach(4);*
    }

}
void loop() {

  • pirVal = digitalRead(pirPin);*
  • int i;*
  • if (pirVal == HIGH) {*
  • for (i= 0; i < numOfLEDs; i++) {*
    _ analogWrite(LEDArray*, 255);_
    _
    delay (100);_
    _
    }_
    _
    delay (100);_
    _
    for (i= 0; i < numOfLEDs; i++) {_
    _ analogWrite(LEDArray, 0);
    delay (100);
    }
    if (pirState == LOW) {
    pirState = HIGH;
    }
    }
    //else, set all LED values to zero*
    * else {
    analogWrite(LEDArray[0], 0);
    analogWrite(LEDArray[1], 0);
    analogWrite(LEDArray[2], 0);
    analogWrite(LEDArray[3], 0);
    analogWrite(LEDArray[4], 0);
    if (pirState == HIGH) {
    pirState = LOW;
    }
    for(pos = 0; pos <= 180; pos += 1)
    {
    myservo.write(pos);
    delay(15);
    }
    for(pos = 180; pos>=0; pos-=1)
    {
    myservo.write(pos);
    delay(15);
    }
    }
    }*_

It may take a long time to go around the loop once and read the PIR since its got to spin the servo up and back- what happens if you reduce the servo range from 180 to 2? Does that make the PIR work any better?

You may need to re-write the servo code so you only move the servo one step each time you loop() rather than a complete scan each time. You may also need to revise the structure of the bits that turn the LED's on and off. As a general rule it is unwise to use delay() if you are trying to do more than one thing at a time. See http://playground.arduino.cc/Code/AvoidDelay for example code to eliminate delay()