Having looked at the code, it opens the gate as soon as the second sensor sees a train, this is fine for the closing stage but means that a long train will trigger the opening as the front leaves the crossing while the coaches are still over the road,RudyB wrote: ↑Sun Mar 10, 2019 11:24 am We have seen the separate ingredients for a level crossing in the previous three videos: blinking LEDs, servo to operate the gate, sensors to detect the train ... it is time to put it all together now into one piece of software. We'll use the State Transition Diagram as our starting point and build up the software in 5 easy to follow steps.
Fun with Arduino 20 Railway Crossing Putting it all Together
Railway Crossing UK version
As a solution the second sensor needs to either see the train but not release the barrier until it looses the signal again, or have the opening signal combined from both sensors sensor one low sensor 2 high to low transition and give a short time delay