Speed is the wild card.
Crossing protection is triggered by TKO (Track Occupancy). Just like Rango says, the metal "shunt" triggers the TKO. It doesn't have to be anything that large, either. It is timed such that when equipment (people use 'train' too much) is on the approach, speed is factored in to the distance of the "bug." It is timed such that it operates automatically for 20 seconds before the crossing is occupied by the equipment moving at track speed.
If 79mph track for example, that bug is way down the line in advance. But something moving at say, 20 mph, takes what seems a long time to actually occupy the crossing. Which it does. It is placed far enough away that a train moving at track speed will trigger it 20seconds before it occupies the crossing.
But, if in 20mph track for example, and a car gets away on a downgrade*, and it gets too far above track speed, it is going to occupy that crossing before the gates are lowered. The bug is timed for 20 seconds at track speed... not mph or time standing alone.
In other circumstance, all bets are off. The protection is not fail-safe. If anyone takes anything away from here, it is the fact that automatic crossing protection of any kind is not fail-safe. A popular and dangerous misconception.
So, the mantra remains the same... Stop, Look, Listen... and this is one of the reasons why it is advisable to do so.
*Happens waaaaaaaaay more than you think. In the US, incidents are not required to be reported to the FRA unless exceeding a specific dollar amount in damages, should any be incurred. And there are not hundreds but thousands of miles of grade territory across North America, not just the US. So those cars and locos that are gettin' loose aren't usually reported when possible to cover it up... Like in the Mafia**... no body, no crime.
** I do NOT mean Bonanno*** or Luchessi**** affiliates... who everyone knows doesn't exist.
***Next week, I swear to God...
**** Wait a minute... you're saying, if I don't pay up, she never comes home?
Lemme think about it... and what's a good pick for the fourth at Aqueduct tomorrow?