# Detecting and counting the number of junctions

So I am making a robot which is to follow a line. The field has both +(junctions) as well(by the intersection of two lights). I am yet to figure out what exactly is the best way to track the number of junctions.

The following is the code I have thought out. However, if there is a better way I would highly appreciate any suggestions.

    while (true){
go_straight();
int sensor_counter=0;
while(sensor_counter<=2){
if (sensor_values==111){
while(sensor_values!=0){
go_straight_before_junction();
}
if (sensor_values==0){
sensor_counter=sensor_counter+1;
}

;}

;}
while(sensor_values!=3){
turn_left_corner();
}
if (sensor_values==3){
direction-=90;
}


sensor_values=5 -robot Too left to the line

sensor_values=4 -robot Slightly left to the line

sensor_values=3 - exactly on the line

sensor_values=2 -robot slightly right of the line

sensor_values=1 -robot Too right of the line

Sensor_values=0 or 111 - robot crossed junction (0 is for the sensor at the back off the centre line and 111 is for the 3 sensors at the front. )

I'm using a light sensor and it reads 1 when in front of a white line and 0 when in front of a black line(rather like white tapes on a black floor ).

• it is not possible to answer the question about detecting the junctions .... we have no idea what kind of a sensor you are using and how it is detecting the lights – jsotola Oct 24 '18 at 5:31
• Im using a light sensor – robotlover Oct 24 '18 at 6:50
• which detects 1 when it is infront of a white line and 0 when infront of a black line – robotlover Oct 24 '18 at 6:50
• there you go ... you asked a question without giving all details ... how do you expect a useful answer .... you question says nothing about any black lines .... it mentions crossing lights (this is unclear) ..... please edit your question so that it includes all the information .... please draw a diagram if you have to – jsotola Oct 24 '18 at 7:00