Arduino 5560 Led + servomotor

Hello,

I am trying to make a construction where the servo motor is spinning and led lights turn on as they pass. So far so good but the servo needs to stop at random and turn that light on. This is where the trouble starts. Instead of it being random it will always activate the same light.

This is the code in circuits.io and in attachments are serval pictures of our construction :

This is the code:
#include <Servo.h> //Servo library

Servo servom; //initialize a servo object for the connected servo

int angle = 0;

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int rood = 7;
int groen = 6;
int geel = 5;
int blauw = 4;

// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(rood, OUTPUT);
pinMode(groen, OUTPUT);
pinMode(geel, OUTPUT);
pinMode(blauw, OUTPUT);
servom.attach(3);
}

// the loop routine runs over and over again forever:
void loop() {

// turn the LED on (HIGH is the voltage level)

for(angle = 180; angle>=1; angle-=1) // command to move from 0 degrees to 180 degrees
{
servom.write(angle); //command to rotate the servo to the specified angle
delay(8);
if(angle < 45){
digitalWrite(rood, HIGH);
digitalWrite(groen, LOW);
digitalWrite(geel, LOW);
digitalWrite(blauw, LOW);
}
if((angle > 45)&&(angle < 90)){
digitalWrite(rood, LOW);
digitalWrite(groen, HIGH);
digitalWrite(geel, LOW);
digitalWrite(blauw, LOW);
}
if((angle > 90)&&(angle < 135)){
digitalWrite(rood, LOW);
digitalWrite(groen, LOW);
digitalWrite(geel, HIGH);
digitalWrite(blauw, LOW);
}
if((angle > 135)&&(angle < 180)){
digitalWrite(rood, LOW);
digitalWrite(groen, LOW);
digitalWrite(geel, LOW);
digitalWrite(blauw, HIGH);
}
}
for(angle = 0; angle < 180; angle += 1) // command to move from 0 degrees to 180 degrees
{
servom.write(angle); //command to rotate the servo to the specified angle
delay(8);
if(angle < 45){
digitalWrite(rood, HIGH);
digitalWrite(groen, LOW);
digitalWrite(geel, LOW);
digitalWrite(blauw, LOW);
}
if((angle > 45)&&(angle < 90)){
digitalWrite(rood, LOW);
digitalWrite(groen, HIGH);
digitalWrite(geel, LOW);
digitalWrite(blauw, LOW);
}
if((angle > 90)&&(angle < 135)){
digitalWrite(rood, LOW);
digitalWrite(groen, LOW);
digitalWrite(geel, HIGH);
digitalWrite(blauw, LOW);
}
if((angle > 135)&&(angle < 180)){
digitalWrite(rood, LOW);
digitalWrite(groen, LOW);
digitalWrite(geel, LOW);
digitalWrite(blauw, HIGH);
}
}

delay(1000);
angle = random(180);

servom.write(angle);

if(angle < 45){
digitalWrite(rood, HIGH);
digitalWrite(groen, LOW);
digitalWrite(geel, LOW);
digitalWrite(blauw, LOW);
}
if((angle > 45)&&(angle < 90)){
digitalWrite(rood, LOW);
digitalWrite(groen, HIGH);
digitalWrite(geel, LOW);
digitalWrite(blauw, LOW);
}
if((angle > 90)&&(angle < 135)){
digitalWrite(rood, LOW);
digitalWrite(groen, LOW);
digitalWrite(geel, HIGH);
digitalWrite(blauw, LOW);
}
if((angle > 135)&&(angle < 180)){
digitalWrite(rood, LOW);
digitalWrite(groen, LOW);
digitalWrite(geel, LOW);
digitalWrite(blauw, HIGH);
}
delay(3000);
exit(0);

}

18425026_121466958418888_2888211778145132805_n.jpg

18516000_120332000794263918_692477614_n.jpg

  for(angle = 180; angle>=1; angle-=1)    // command to move from 0 degrees to 180 degrees

That code is absolute nonsense, if the comment is accurate. The comment is absolute nonsense if the code is correct.

You don't call randomSeed(), so random() will always return the same value.

Do you realise that random() will produce the same sequence of (non)random numbers unless it is seeded using the randomSeed() function. One way to seed the random number generator is to use the value returned from analogRead() from a pin not connected to anything.