Tracking one axis direction of a model train

Hey all,

I am trying to develop some way of tracking the position of a model train on the x axis in my layout.

It's a very small layout and has a few sensors that tell the arduino the general area of the train but I need to find the exact location of the train relative to the left wall so that I can:

A. stop the train before it hits a wall or pushes carriages into a wall
B. automate the layout (it is not a loop layout, so I can't just having it running in the same direction)

I've been looking at accelerometers but I'm not sure how I would power such a thing - I can't connect the locomotives to wires, and the track needs 12V 1A power source to move the locomotive. I also don't want to attach sensors to stick out and ruin the aesthetic of the layout.

Any ideas would be appreciated!

Well, there are some really old tried and true methods, one is the back-and-forth or traverser circuit. That can even be done just with diodes and a relay, along with gaps in the track, and a timer. Check the wayback machine website for Rob Paisley's pages.

If you apply 12V to a locomotive, it will really be like "back to the future" fast. So you need some kind of throttle to limit it.

I bought one module for that, it was an update with microprocessor on board, but it needed another board to do track occupancy. The most reliable form of track occupancy detection is track current measurement. As with the old methods, the detection limits are set by gaps in the track.

Of course, to use an Arduino for this is just perfect, and I'm sure more advice will follow. To control the track power, you would typically use something like an H-bridge drive module.