The Arduino Hits The Rails

Certain hobbies come in clusters. It isn’t uncommon to see, for example, ham radio operators that are private pilots. Programmers who are musicians. Electronics people who build model trains. This last seems like a great fit since you can do lots of interesting things with simple electronics and small-scale trains. [Jimmy] at the aptly-named DIY and Digital Railroad channel has several videos on integrating railroad setups with Arduino. These range from building a DCC system for about $45 (see below) to a crossing signal.

There are actually quite a few basic Arduino videos on the channel, although most of them are aimed at beginners. However, the DCC — Digital Command and Control — might be new to you if you are a train neophyte. DCC is a standard defined by the National Model Railroad Association.

Model trains pick up electrical power from the rails. DCC allows digital messages to also ride the rail. The signal shifts from positive to negative to indicate marks and spaces. By diode switching the electrical signal, the train or other equipment can get a constant supply of current. However, equipment monitoring the line ahead of the diodes can read the data and interpret it as commands.

To accommodate old equipment, you can stretch the high or low values to make the average voltage either positive (forward) or negative (reverse). This can heat up DC motors, though, so it may shorten the life of the legacy equipment.

The build uses an available Arduino library, so if you want to get into the protocol you’ll have to work through that code. We had to wonder if there were other places where passing power and data on the same lines might be useful. There are other ways to do that, of course, but this would be a reasonable place to start if you needed that capability.

If you want to use an mBed system instead of an Arduino, there’s a great tutorial for that. Either way, it is just the thing for your next coffee table.

13 thoughts on “The Arduino Hits The Rails

  1. Some clarification: in DCC, power and signal on the rails is the same thing. It’s alternating, and bits are encoded in the signal. The signal is simply rectified to get DC for a motor and whatever other functions.

    DCC has taken things quite far from what used to be the case with model trains. For starters, you can run two trains on the same rails in any direction, independently, at any time. Yes, you can invoke head on collisions, but that’s generally frowned upon in the hobby. You can also control lighting. DCC decoders mounted in engines are processor-based, meaning you can have lighting control and effects, sound effects, back EMF motor control, locomotive inertia settings, even sound effects onboard, including the ability to have a more labored sound on an incline, based on motor loading. Speed tables can be used to calibrate models such that a given throttle setting equates to very similar speed in another model at the same throttle setting. Kick voltages can be set for starting a motor off at really low RPM. Features and bells and whistles, literally in some cases, are extensive.

    Beyond mobile decoders and their motor, lights, and sound control, you can wire up turnouts, trackside lighting, you name it, any sort of animation automation you can imagine. Some guys have done DCC rail cranes, giving the ability to run your crane from a remote (called a throttle in model railroading). There are even protocols for transponding, for reporting an ID within a given track section to track a train’s location. And yes, various USB interfaces exist for computer-based control.

    Model Railroading ain’t what it used to be…

    1. Just another example – I wired a decoder to control a turntable, using an auto-reverse module (device that automatically switches polarity of a rail section when a short is encountered) for the table. The end result is, I can drive a train onto the table, turn it around 180 degrees, and send it back, all while just going “forward” for that engine, all from a throttle, all remotely controlled by DCC.

  2. Why aren’t people using Raspberry Pi s to do this? After all, the RPi is much more powerful than an Arduino, and can do much more sophisticated control.

    Let’s see some really sophisticated model train control using an RPi, please.

    1. I suspect it is mostly because somebody did it with an arduino first. Though there are electronics enthusiasts in the model railroad world, lots of us just want to have fun building and running our trains. When someone writes code to turn an inexpensive set of components into a nifty controller, we’re much more apt to think, “ah that will get me running cheaper than buying the big commercial system that advertises in the magazines.” We tend not to say, “I think the R2000 retro encabulator has quantum ebullient architecture that makes it a better choice.”

      If you want to build a better DCC controller though, I say go for it! The world of model railroaders will beat a path to your YouTube channel.

    2. Probably because and Arduino is much better at generating signals. The timing in DCC is down in the microsecond range. Too fast for a multiuser operating system to manage accurately.

  3. I would like to see some advancement in “dead rail”. That is, no need to electrify the rails at all. I thought with the progress in battery tech and r.f. protocols, there would be a plethora of experimenters out there.
    Apparently not. (yes there are a few) Effectively, the loco becoming an RC train.
    I’m lacking the skills to make it workable in H.O. gauge, but I know (hoping) there are a lot folks that are plenty capable.

    1. For HO and the smaller gauges, you’d need to use dummy locos or freight cars to contain the batteries, because there isn’t that much room in the average diesel model for batteries. That would ruin the operating realism a bit, if you like short trains and/or switching manuevres (of course steam engines often have separate tenders that could carry batteries)

      There’s been lots of good hacking in model railroading. Some of the stuff they did during or just after WW II have to be seen to be believed.

      Also check out JMRI –

  4. As one output can handle only 2A it would be good to put the output channels in parallel to get 4A output. Perhaps the jumper wires are required to put the inputs in parallel. A RPi is probably overkill, as a Windows PC is used anyway to supply the GUI for the train track and train control.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.