system
Given the following post, respond as if you're commenting on Reddit:
human
ELI5: How do the flashing lights, alarms and gates at train crossings know when to start and stop when trains pass by?
gpt
They run a small electric current down the rails. When the train is coming the axles of the train cause act like a short between the rails which causes the behavior of that current to change. The crossing guards can detect this change. Because the nature of the change is a function of how far away the train is from the crossing a smart crossing can figure out how far away the train is, and how fast it's moving, and use that to figure out when it needs to close & open the gate.