Photodioda

How to make a smart traffic light with 3 sensors photodiode for 3 lines? I found the problem on its IF function.. Any one help me please...

Please post what you have tried sofar?

I’ve tried to create code as below, but function in the if block is not executed when the photodiode is not directly receive light.

int redPin = 2;
int yellowPin = 3;
int greenPin = 4;

void setup() {
pinMode(redPin, OUTPUT);
pinMode(yellowPin, OUTPUT);
pinMode(greenPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
if (sensorValue >= 600) {
digitalWrite(yellowPin, HIGH);
delay(5000);
digitalWrite(yellowPin, LOW);
digitalWrite(greenPin, HIGH);
delay(10000);
digitalWrite(yellowPin, HIGH);
digitalWrite(greenPin, LOW);
delay(3000);
digitalWrite(redPin, HIGH);
digitalWrite(yellowPin, LOW);
delay(10000);
}
else{
digitalWrite(redPin, HIGH);
digitalWrite(yellowPin, LOW);
digitalWrite(greenPin, LOW);
delay(10000);
digitalWrite(redPin, LOW);
digitalWrite(yellowPin, HIGH);
delay(3000);
digitalWrite(yellowPin, LOW);
digitalWrite(greenPin, HIGH);
delay(10000);
digitalWrite(yellowPin, HIGH);
digitalWrite(greenPin, LOW);
delay(3000);
}
}

you should remove the delay's from the code with the technique described in the blink without delay code.

The current code blocks for 25-30 seconds in delay and then it samples for a millisecond. so there is only a small chance the diode sees some signal, which makes it almost not responsive.

O, i have to remove delay in IF block?