Turn multiple LEDs on when motion is detected?

Hi,

I'm working on a code where the situation is "if motion sensor reads movement, turn one led on'. This has to happen three times. When the motion sensor read 3 times a movement, the third and las led will turn on, which activates the servo motor to move. Right now I'm stuck at some points in the code:

  • How do I write that by the first movement, only the first one will turn on, and keeps it on, until the second movement has bean read, which turns on the second one?
  • How do I count, that when the third led is on, the servo motor will rotate?
  • When the servo motor has rotated enough, how do I stop the motor? (I have to write motor.write(90), but where?

This is how my code is right now:

int sensor = 2;
int beweging = LOW;
int waarde = 0;
int analogInPin = A0;
int sensorValue = 0;
int aantalLED = 0;

#include <Servo.h>

Servo motor;

void setup() {
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
Serial.begin(9600);
motor.attach(9);
}

void loop() {
waarde = digitalRead(sensor);
if (beweging = LOW) {
Serial.println("Motion detected!");
beweging = HIGH;
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}

else if (beweging = HIGH) {
Serial.println("Motion stopped!");
beweging = LOW;
}

else if (beweging = LOW) {
Serial.println("Motion detected!");
beweging = HIGH;
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
}

else if (beweging = HIGH) {
Serial.println("Motion stopped!");
beweging = LOW;
}

else if (beweging = LOW) {
Serial.println("Motion detected!");
beweging = HIGH;
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
}

if (aantalLED > 3) {
motor.write(0);
}

}

}