How train signals work

I learned something last friday, and I learnt it from some juvenile delinquents. I’ve often wondered exactly what signals, so to speak, a train is coming. What is it that enables the boom gates to come down and the light to start flashing? Last friday, I found this out. Some students, a couple from Scotch College, and a couple I take to be from Underdale High School, got off the train at my station, and one of them proceeded to run back towards the nearest level crossing. He squatted down over the state railway line, which seems to be marginally lower gauge than the local system. I was getting relatively close to where this boy was, but I don’t think he’d seen me. He reached his arms out perpendicular to the tracks, and pressed something, I assume a coin, onto each of the tracks. The lights then began to flash, and the gate started to come down. By this time, I had approached to being about two metres away from the boy. He saw that I wasn’t one of his cronies, and jumped up. A car had pulled up at the tracks, and thinking a train was coming, had stopped. The driver had their window down, and the boy said to him that no train was coming. I continued to walk, but as I was about 10 metres past the crossing, I took my phone out, and turned around and very blatantly took a photograph of the group. I very shortly turned around the corner into the street I walk down on the way home, and I think the gang had begun to disperse, perhaps fearing I had called some sort of authorities, as I did hold my phone to my ear. • So, what is it that makes the signals know when a train is coming? I assume that there is some sort of Ohm-meter, that measures the resistance between the two rails of the track. Normally, this would be very large, as they are not connected. It should, in theory, be almost infinite. That is, it should be an open circuit. When a train approaches, it acts as a conductor between the two rails. Since the rails have a resistance of some sort, albeit quite small, it would be measurable over the distance a train needs to be away from the crossing to trigger it. This, and the fixed resistance of the actual train would be a threshold. When this threshold is breached, and whenever the resistance of the system is less than this value, the lights would flash, and the gate would come down. The whole time the train is going past, it would hold the resistance below this value. After it has gone past, and exceeded a certain distance, the resistance would then have gone above the threshold, and the system would revert to the open state.