Detector rails and crossing rails are the tools for making junctions that react to a cart instead of needing you to flip a lever every time. Detector rails output a redstone signal when a cart passes over them, which you can wire into whatever you want to trigger.
Wiring a Simple Crossing
Lay your main line and branch line so they meet at a crossing rail. Place a detector rail a few blocks before the junction on the main line, then run redstone from it to the crossing rail. When a cart rolls over the detector, the crossing switches the branch into alignment, letting the cart turn. Put a second detector on the branch side if you want the crossing to reset automatically after the cart has passed.
Timing and Troubleshooting
Redstone dust has a short delay, so if the crossing flips too late, move the detector rail further back from the junction. If it flips too early and resets before the cart arrives, add a redstone repeater set to a longer delay. Keep your wiring on a separate block layer from the track so carts do not accidentally trigger anything. Test with a slow-moving cart first; high-speed arrivals are much less forgiving of bad timing.
