Go Down

Topic: Arduino Train: How to Program "Stop Locations?" (Read 1 time) previous topic - next topic

Hi all,

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!



Feb 07, 2013, 10:21 pm Last Edit: Feb 07, 2013, 10:23 pm by Shpaget Reason: 1
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.


You could isolate a very short section of rail. The metal wheels of the rolling stock would short this out to the adjoining sections when passing over it.

Or depending on aesthetics, an LDR mounted between the rails. When rolling stock passes over it it will go dark...
Beginners guide to using the Seeedstudio SIM900 GPRS/GSM Shield


You may well be better of keeping the Adruino off the train that way you can think about having it control the points and the signals as well.



Feb 08, 2013, 12:07 am Last Edit: Feb 08, 2013, 12:26 am by Retroplayer Reason: 1
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.

Hey all, thanks for the ideas!

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

@holmes4, I setup my arduino to receive HTTP post requests via this tutorial: http://www.twilio.com/blog/2012/08/diy-home-automation-using-twilio-powerswitch-arduino-and-pusher.html so I can turn it on and off remotely.

I'm still hazy on the program, but I'm thinking this could work:

1. setup arduino A to control of the voltage of the tracks -- all starting and stopping will have to pass through this controller.

2. mount arduino B on the train and configure it to post "stop requests" to the web server based on its proximity to its "stop location" (possibly triggered by NFC or RFID tags?).

3. upon receiving a "stop" command from the arduino B, the webserver would then propagate this command to arduino A, which would then adjust the voltage accordingly.

What are your thoughts on this design? Is this overly complicated? Can you think of easier methods to remotely "deliver" the train to specific track locations?

Oh, and I just stumbled across Adafruit's NFC shield http://www.youtube.com/watch?v=WgLV5X1iWWw, which is totally awesome :)


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?


Not at all two rail or or center rail power is not relevant. I'm just thinking about cost.

For example cost the following,

my way - One controller deals with it all, cost one uno + sensors +actuators.
Your way - One uno +sensors +actuators + per train( 1 uno+one (say) wireless shield + WI-FLY module).



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.

Would an H-bridge used across the rails harm anything?


@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.

Go Up