You can automate grade crossing signal lights with block occupancy sensors.
Install a BD4 to detect track occupancy as shown in the figure below.
Other than removing the Op Sw35 commands from the routes used in the related article example, there is no additional programming needed for the DS64.
Sensor operated occupancy detection requires that all rolling stock be equipped with resistor wheels for proper detection or that the detection section is longer on each side of the RR Crossing than the full length of a train since only the locomotive will draw current.
A lighted caboose on the end of a train can also be used to keep the Crossing Lights going after engine exits the detection section.
In this example, the main line only needs to trigger the RR Crossing if the route is set to enter or exit the yard. This can be accomplished easily by using both inputs as sensors for output 4, which is switch address 35. S4 is wired to the sensor output 1 on the of the BD4.
The Yard ladder must be gapped on the same rail for detection after the turnout of each yard track as well as between switch17 and the RR Crossing. Track output 1 of the BD4 must be connected directly to that detection section. The detection section on the main line can not be connected directly to the BD4 because the RR Crossing Signal should only activate if a train enters or exits the yard. Therefore we must route the power to that section through the DPDT input of the turnout machine if it is a tortoise. The other input is undetected power from the same rail while the output is wired to the detecting rail of that section. See the following schematic that explains this setup in detail. (If you use solenoid operated turnouts, you might add a snap relay parallel to the turnout solenoid to handle the switching of the track power.)