Crossing Signals - Part 2 of 4 - The Methodology for Train Detection

  The following sketch illustrates my track plan (not to scale):


The vertical brown strip depicts the road that passes over two level crossings. The Main Line (also referred to as Track 1) and the Branch Line (also referred to as Track 2) connect via the turnouts located to the East of the roadway. There are 6 possible directions of travel of rolling stock (see yellow arrows in the sketch below):

  • West to east on Main Line
  • West to east on Branch Line
  • East to west on Main Line
  • East to west from Main Line Siding and then on Main Line
  • East to west on Branch Line
  • East to west from Branch Line Spur and then on Branch Line



As my track already has electronic occupancy detection to control the signals (see blog post of December 1, 2020) I decided to use photoresistors to detect the presence of rolling stock. Photoresistors are inexpensive little electronic devices that, when exposed to light, create very little resistance to current flow. However, when the light is turned off (or shaded, as when model railroad passes over it) the level of resistance goes up. Photoresistors are non-polar in that they do not need to be hooked up to positive and negative leads in any particular way. They are analog and not digital meaning that the level of resistance varies depending upon how much light shines or does not shine, on them. Finally, as with regular resistors, photoresistors can be wired in series which means that if two are wired in series, shading one will increase the resistance of the whole circuit and shading both will also increase the resistance of the whole circuit. This is what the photoresistors look like (the head is roughly 4 to 5 mm across, depending on the direction measured - note that two sides are flat):



In order to detect rolling stock travelling from each of the six directions above I mounted photoresistors between the rails, flush to the ties, (called OUT sensors) at the locations marked in green below (sensors are not to scale). The photosensors, along with the crossing lights, will be wired to an Arduino Pro Mini microcontroller. The Arduino programming will be described in detail in Part 4 of 4.



Next, I mounted photoresistors between the rails adjacent to each crossing (called "CROSSING" sensors), as depicted by the blue dots below:




Let's follow a train travelling from West to East along the Main Line.



Position 1 (note the red arrow with the red "1" beside it) - the train shades the first OUT sensor. The Arduino will detect the presence of the train and start the crossing lights flashing. At this point the train could do one of three things:
  1. The train stops at position 1, shading the photoresistor. This means that the crossing lights will keep flashing for as long as the train is parked. This is prototypical. On many occasions I have stopped my vehicle at a level crossing at which the lights are flashing red and look down the track to see that the train is not moving. In this circumstance it is allowable to drive across the level crossing as long as you have come to a complete stop and have checked to make sure that the train is stopped and that it is safe to pass (much light a flashing red traffic light). However, it is not permitted to pass if physical crossing arms are in use at the crossing and the arms are in the lowered position.
  2. The train stops at position 1 and then reverses direction. The crossing lights must stop flashing because there is no longer a need for traffic to be stopped.
  3. The train does not stop but continues on its eastward journey. In this case the crossing lights must keep flashing.
Position 2 - the train has continued its journey and has now reached the level crossing. In this case the crossing lights must keep flashing for the entire time that the train occupies the level crossing.


Position 3 - the train passes over the second CROSSING sensor and, when the last car has passed, the lights must stop flashing.


Position 4 - the train passes over another OUT sensor. As the train has already passed over the level crossing it is important that the crossing lights DO NOT start flashing again. The Arduino needs to be able to differentiate between a train crossing an OUT sensor for the first time and another OUT sensor for a second time. However, once the last car of the train has passed over the second OUT sensor if it were to stop and then reverse direction to pass over the level crossing in reverse the Arduino must start the crossing lights flashing again.



The sequence must operate in exactly the same way no matter the direction of travel or the path followed.

Note that my crossing light design does not incorporate the bell sound. I have seen model railroads with this feature and is nice at first. However, after a while the novelty wears off and ringing bell becomes annoying, at least it does to me. It's my model railroad so I get to decide whether or not the crossings have bells! It would be a simple matter to attach a sound shield to the Arduino and, with some minor programming tweaks, incorporate the bell ringing effect.

In Part 3 of 4,  I'll explain how I wired this contraption.