Jump to content

Track Detection, Signals and Interlocking


Recommended Posts

This is an actual train/track detection system instead of a timer for signals.

Using hall sensors and arduino, an idea for track detection. Below a pic of the testing unit or prototype:



Magnets are placed under each end of the train and hall sensors are placed under the track (both ends of the track section.

It is not necessary to make holes or damage the track.




Sensors connected to arduino 



For a track section with hall sensors at each end of the track section and a train with magnets at each end of of it.

The logic is as below. So an counter is used in the arduino to "know" that the train is IN the track section.


S1  S2  Counter Track Status   Comment

0      0          0           empty         no train in track section

1      0          1           occupied   first half of train entered to track section

2      0          2           occupied   whole train is in the track section

2     -1          1           occupied   first half of train is leaving the track section

2     -2          0            empty       whole train left the track section



And the serial monitor shows the status of the counter after the train passed the track section





as described before





As a counter is being used, the train can stay as long as I want in the track section and the track detection will not time up.

This idea is based or inspired in the use of Axle Counters for track detection in real train lines.

This project can be modified to control outputs (i.e. signals and others). It can be used in several sections of consecutive tracks. Also, it can be adapted to be bi-directional.




  • Like 6
Link to comment
17 hours ago, Madsing said:

Excellent. A perfect application for an Arduino!


17 hours ago, katoftw said:

I dont understand any of it. Love to see a video of it working though.


16 hours ago, Yavaris Forge said:

I'd love to see a video as well. Very nice program. How many track sections can you control with a single arduino?




This is a work in a progress, the signals are not connected.

A video would show how the counter (i.e. a logic counter inside of the arduino), on the pc screen, goes from 1 to 2 then to 1 while the train is passing the track. Something that is not really exciting to see at the moment but I could make a video anyway.


How many tracks? A good question.


·         For one track: 2 input pins are required, to connect 2 sensors at each end.

·         For a signal: other projects control signals directly from the arduino, so 3 output pins are required. However, I want to use only one output pin per signal.

·         For points or set of points (in the future): I am also aiming to use only one pin.


If more pins are required... a pin extender could be used...


PCF8574 GPIO Extender



This is a port extender which can provide up to 64 pins. That is, you connect 8 of these modules to 8 pins of your Arduino.


Now… if you want to get serious…


You could use the TCA9548A I2C Multiplexer Module (this is a multiplexer).



So you could connect 8 x GPIO Extenders to 1 multiplexer module (TCA9548A I2C). Then replicate the latter up to 8 times. That is: 8 multiplexers with 64 GPIO extenders….


8 (multiplexers) x 64 (GPIO extenders) = 512 pins (input or output)


I think 512 pins would be enough for almost any project.


Note: Btw, I tested these modules. That is, I successfully controlled 1 LED with 1 switch… this was made by connecting 1 LED to 1 GPIO extender which was connected to 1 multiplexer which was also connected to 1 arduino.



Some interesting things of this system are:


·         The track detection does not time out. Even if the train stops and “sits” between two tracks for long time, the system will still recognise that the train is occupying those two tracks until it moves.

·         It is unlikely to fail (unless you unplug the arduino). I have been testing it quite a lot and always “counts” correctly

·         You can have a track section as long as you want. That’s correct… as long as you want… Actually, this is a characteristic of the Axle Counters (the real devices) which are also used in “dark territory” of train lines instead of “token/staff systems”

·         No major modification to trains, only the installation magnets at each of the train.

·         No damage (making holes) to tracks

·         Quite simple and cheap to implement (for few tracks and signals)


For DCC, I know that people usually uses “current” detection which requires physically creating track blocks or sections (i.e. using insulators) and other circuitry. I think this project/idea (not completed yet) could bring a simple solution for DC users (well… also DCC users)


Power Up!


p.s. picture of magnets



  • Like 2
Link to comment
22 hours ago, disturbman said:

Very interesting. Thanks.

What kind of magnets are you using? Neodyms?


Yes, Neodyms are the magnets.


On other topic, I was thinking how most of people (including myself) work/ed with IR sensors to achieve some sort of train detection.




Above, some pictures of old projects. IR sensors are helpful but have some challenges.

Still you can make interesting stuff like the video below.



This is old project which only uses IR sensor and relays (no arduino, no PC) to achieve locking of points, actually the right term will be "approach locking" of points.

This circuit replicates, or tries to, the real interlocking function.


In other words,  the circuit does:

  • Locks the points once the train occupies the track section of the points
  • Releases the points once the train passes that track of the set of points 
  • Release the points if the train stops (for 8 seconds) on the track before the track of the points, this is done to ensure the has stopped or the driver is under control of the train.

In the real world, this is obviously use to prevent the operations of points once a train occupies that track section as the later could generate a derailment.

Even tough in N Scale, the same principle can be used to prevent operating points while a train is passing over points.

So we will not have derailments and/or short circuits.




Edited by NX:
youtube link
  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...