Knowing where a model train is on the tracks...

I have a few dcc trains on a track and i want to know where they are so I can have them control themselves and not hit each other. I'm trying to think of a way to do this, any thoughts? I was thinking maybe ir sensors around the track that send off a different signal and the Arduino on board could read this. I was also thinking of using a RGB sensor to read "signs" on the side of the track but I'm not sure if this would work. RFID might work but if the train is moving fast it might miss it.

That wont tell the train where it's at...

listen to the track

That wont tell the train where it's at...

Really ? Could it have been a joke ?

raschemmel:
Really ? Could it have been a joke ?

If anything it's a waste of time.

Or use reed switches or Hall effect sensors under the track to detect a small magnet under the loco as it passes over it.
It’s not necessary for the train to know where it is, as long as the Arduino knows where it is. The Arduino can then send the correct DCC message to the track.
Your idea of an Arduino in every train won’t work. Even if a train knows where it is, it won’t know where every other train is. Use one central Arduino to control the lot.

If anything it's a waste of time.

Really ?

How do you know ? You are asking us so we can assume you don't know. What if you put accelerometers
on the track to measure vibration ? Isn't that a form of "listening to the track " ? You could put optical
reflective sensors everywhere with beams crossing the track but that would only tell you if the train has
passed a particular sensor. Assuming the train is only going one direction and cannot suddenly jump off the track and jump onto some other track it is reasonable to assume that once it passes one sensor you know
what the next sensor is that it will pass. If you use leds on track layout board and setup the leds to go on
for 2 to 3 seconds for each sensor you can follow the trains progress. Using vibration , you have to measure the vibration from each sensor and see which ones are increasing in amplitude and which ones are decreasing. Once you have detected two consecutive sensors, with one INCREASING and the other one DECREASING, it is reasonable to assume the train is somewhere in between is it not ?

[EDIT]
The caveat is that you need to figure out what resolution of measurement you want/need (how far apart to place the sensors)
Before you say something is a waste of time maybe you should spend a little time thinking about it.
@Greensprings,
It was a joke wasn't it ?

Reed switches and magnets sounds like the least expensive method. Same principle. Once you detect one sensor the next one is a given. The main difference between this method and "listening to the track" is that listening to the track gives you speed information based on how fast the amplitude is increasing /decreasing. Opto sensors and reed switches will give you that by measuring milliseconds between sensor
trips but require two sensor trips to compute it. Vibration will tell you where it is and how fast it is going
regardless of where it is or if it is currently passing a sensor location.

Why not putting ir transmitters on trin sending a unique code for each train facing the riail where receivers are placed at certain locations. That way you you can identify where each train is

IR FOF (Friend or Foe transponders). That could work.

Hi, the problem is that you can easily detect a train on the track, but you also need a method of identifying that train.

Tom..... :slight_smile:

Try to find out how full-size trains do it. It is a very interesting subject with a lot of history. Find out how trains were given permission to use a piece of track by carrying a physical key and how that evolved into the modern systems that use GPS and transponders. I would think that fully working signals at the side of the model track will be a great addition to any layout.

Putting Light Dependent Resistors between the sleepers is another option. They are very small and don’t require anything attached to the trains. Obviously they can’t distinguish one train from another but the computer system should be able to infer which is which.

With any system the trick is to think carefully about where the detectors should be placed to give the most useful info to the Computer.

In the free DVD with the January 2015 issue of Railway Modeller one of the films suggests using the computer to sample the performance of each train so that it knows what commands to use to achieve a specific speed. Then it can infer fairly accurately where the train is relative to the most recent detector. This should allow fewer detectors to be used.

…R

Another idea to identify trains (and maybe speed as well): Put a barcode on the underside of the trains and a reader between the sleepers

I’d be inclined to add a third rail for communication purposes. If this rail were issolated at various points, the various sections could be polled.

If you simply want to know if a train is within a specific area, then the train could simply have a brush that shorts the third rail.

If you want to know WHICH train is present on any part of the track, you could put some intelligence into the trains themselves acknowledge a “ping”.

mile markers and signposts.
each train could have sensor to read where it is
have an arduino on each train and wirelessly send a signal of where they are. last marker passed or some such

bar code the locomotive underneath..

a sesnor every so often. a train is on one track and only 1 train, when that sensor senses something, it has to be that train. since you know the only train that could be on that track, you would know it is that train.

the ldr sesnors could detect number of cars. so you could count cars on a train. unlikely you would have two trains on the same track with the same number of cars.

I've pondered this myself over the years. I've not implemented anything (haven't built a pike in many years) but I would probably approach it from a current sensing point of view.

Break the railroad into a series of blocks and put a current sensor on each block. This would basically be a small current sense resistor in line with the block's power feed, and an opamp to measure the voltage on the resistor. The trick is going to be reliably detecting the signal which is bound to be noisy. How many blocks you want to use depends on the resolution and separation distance you want to achieve. DCC compatible current sensing occupancy detectors are commercially available if you don't want to build your own.

Now, this sounds like a throwback to the old block control systems with banks of toggle switches, but it's still applicable to DCC. Even with DCC you don't really want the entire track to be one "power district" because of the voltage loss over a long length of track, and because you don't want a short in one section to bring down the whole layout. Even with DCC a good electrical plan involves breaking the track into several sections and having a separate power feed for each.

With enough blocks, you will know where a train is, and knowing the track plan you can follow an individual train and track it as it moves from block to block. With this plan, only locomotives and current consuming cars (passenger cars with lighting?) will be detected. If you want to be able to detect individual cars, a resistor can be added to one axle per car to connect the otherwise insulated wheels together.

If you need to know which train is which, that can be done manually by assigning a train number to each detected position, and then having the system track the movement from then on. Or it could be automated by putting RFID tags on key (or all) rolling stock, and putting a reader at a known slow choke point, like the exit from a staging yard. As the train leaves the yard for the mainline, it is detected and identified, then the system tracks it from then on as it moves from block to block. While it's necessary to have an occupancy detector (current detector) on each block, with the right tracking software it's not necessary to have a tag reader at each block. Besides knowing where each train is, a system like this will also need to know the positions of all turnouts in order to be able to properly follow a train blip from block to block and be able to know which train that is.

This is all theoretical, but if I ever get out of my armchair and actually build another pike, this is the approach I would probably use.

When you get this going, will you post a youtube video of the final product?

I've always liked trains, and am curious to see how this pans out.

All these different methods of train detection will work, some better than others and some easier than others, but the OP appears to want the train to know where it is. This won't help him to avoid crashes, as the train won't know where any other trains are. The only way that can be achieved is to take the 'intelligence' out of the train and put it in a 'signal box/cabin' that knows where ALL the trains are, as is done in real life. An Arduino is ideal for that job.

ShapeShifter:
I've pondered this myself over the years. I've not implemented anything (haven't built a pike in many years) but I would probably approach it from a current sensing point of view.

How could that differentiate between a block that's occupied by a stationary train (no current being drawn) and an empty block (also no current being drawn)?

KenF:
I'd be inclined to add a third rail for communication purposes.

Fine if you're modelling London Underground or Southern Region, but how do you hide the third rail if you're modelling the Scottish Highlands line?