So I'm currently building an arduino controlled electric train. I'd like to program "stop locations" for the train -- various locations along the track where I can command the train to stop. I plan on sending specific stop instructions to an arduino on the train, but just how the train will then sense its arrival at this location has eluded me thus far.

I've considered a barcode scanner attached to the front of the train, but I'd love to hear of any alternatives you can think of!

On the layout I am building we use H0 Maerklin system with feedback modules (the track is split in sections, when the trains enters one sections a circuit is closed and the signal sent to the computer) and control entire layout with WinDigipet. We calibrate the speed of every train and get sub 1 cm accuracy for stopping.

But if you want to put the brains on the train and not on the computer a reed switch on board and magnets on the track should do the trick. If you can control the speed you can stop the train very accurately (+/- 1 cm).If you don't like the idea of magnets on the track then infra red diodes. They work well on our DC Car system (also in H0) for speed, lights, etc, but are significantly less accurate and precise for stopping.

Faller is working on ultrasound positioning in three dimensions(think GPS, but with ultrasound). It still doesn't work very well, though.

For a design I did for a client, I used the reed switches and magnets suggested above. Another thought if you needed continuosly variable sensing might be to have something roll alongside the train with an encoder wheel. Then you could sense the actual position anywhere on the track (dead-reckoning). You could probably even incorporate that into the train wheels directly. Obviously more complicated than the reed switches and magnets and would require modifying your train.

And last possible suggestion would be just to install limit switches along the track that your train bumps as it goes. But I bet that's similar to the H0 Maerklin system with feedback modules mentioned by Shpaget.

If you mean passing control signals along the track itself... hmm... I can think of a few rather complicated ways to do that like introducing high-frequency ripple or AC coupled/decoupled RF, but the simplest approach would just be using wireless.

OK, I think I see what your doing. However you have no need of all the complexity and cost of having Arduino on the train send data to Ardiuino in control which then turns on/off power. Much simpler just to let the Arduino in control do every thing and at 1/4 of the cost! Remember KISS "Keep It Simple Stupid", is the best design rule of all.

I'm also thinking about hall sensors in the track (magnets and coils in the engine) and LDR's placed in the track (the engine puts the LDR into shade as it passes over - should be able to be seen with ADC and would also work when the train s moving in reverse!

@holmes4, ah, I think I understand what you're saying...On this particular train set, the center rail powers the train. Are you suggesting I configure the train so that it no longer responds to the center rail?

I think he is trying to tell you to control the power to your rails with the arduino at a central location (not on the train), regardless of what rails you use. Your arduino turns on the power, turns off the power, or controls the speed by varying the voltage on the rails.

@shpaget, I'm not familiar with reed switches, but they sound interesting -- I'll check them out.

Reed switches are two springy metal pieces sealed inside a glass tube. When a magnet is brought near, the two metal pieces are attracted to each other and make contact.My solution is to place the reed switches just under the track (the small ones are easily hidden) and attach a magnet to the underside of the loco. Use the Arduino to detect when the switch closes so it can slow/stop the train. The reed switches should be placed at right angles to the track

You can also use reed switches to differentiate between different (stopping and non-stopping?) trains.

Let's make a few things clear. You mention third (center) rail, which makes me think you are also using Maerklin, right?It also appears you are using analog locomotives, right?Do you want the system to be self controlled, or do you plan on starting the trains, setting their speed, turning turnouts etc?

Feedback modules on the layout I work on function like this:There are three rails, two regular and the third in the middle which is not really a rail but just a series of pins on each tie/sleeper/crosstie, whatever you call those wooden blocks holding the rails together.The phase of the current comes through this third rail, the ground is on the two outside rails. However, for the feedback to operate properly we sever the connection between the two ground rails effectively isolating one. Now ground comes from only one side. Also the feedback rail is not one continuous conductor, but separated strategically. For example each of many track blocks consist of three separate feedback stretches of track. One long on which the train runs at full (or otherwise determined) speed, one braking on which the train prepares for stopping and starts reducing the speed and the third one for stopping.The wheels axles on the train are conductive, so when the ground is picked up on one track it is transfered to the feedback track on the other side. That ground is then detected by the feedback module (just a bunch of shift registers, actually) and sent to the computer for processing. When the computer receives the information that a particular feedback section is occupied it starts slowing down/stopping the train. It also prevents collisions by not allowing a train to start moving unless the route it intends to take is clear of other traffic.

The way I understood you was that you were thinking of putting an arduino on a train, and control each train that way without communication back to a stationary base. That is why I suggested putting the reed on the train and magnets on the track, so there is no need to send the signal back to the train.If you want your system to know where each train is, and want to keep it as simple as possible I would go with IR LED on the train sending unique ID signal to the receivers alongside the track. When the train turns on a turnout it sends its identification and effectively location, since you can arrange the LEDs to receive only when the train is in a particular position and angle.