Digitize your analog Marklin HO model trains

DIY train decoder for Marklin analog HO trains

Similar projects worth following
In this project I will try to control my old analog Marklin trains with a self made digital system.

Their are many systems already present to do this, but they can be expansive, but most of all it's fun to build one myself.

The final goal will be to develop an entire system that controls not only trains but also rail tracks and scenery through a computer system.

This project will only cover a way to control the trains.


An analog HO train consists out of a motor that will move the train over the tracks. The motor used in Marklin analog HO trains are universal (AC-DC motor), that said it can be powered by an  AC- or DC-power supply. Another big advantage is that it has a high starting torque. 

To control the train, a variable voltage is applied to the motor, through the rail tracks. Marklin uses a 3 rail system to power the motor. 

To switch the direction of the train , Marklin uses a relay to switch the polarity of the stator coil. 


In order to control the train with a computer I came up with a concept that uses RS485 to send and retreive data from the train. 

One of my problems was that I also wanted to use the old rail tracks, that's why it was necessary to apply the communication and power supply on the same line. That's why I use RS485 combined with the necessary filters to power my trains on the same line as the RS485 bus. 

Texas Instruments posted a document where they cover a concept to combine RS485 with a DC power supply with only 2 wires:

I designed a PCB that seperates the RS485 data and power, controlled by an Atmega328P microcontroller. 

The combined power and data bus is seperated by input filters, the RS485 data is converted to UART and read by the microcontroller. Power is used to power the microcontroller (converted to 5V) and to power a single channel DC motor driver (MAX14870) that will drive the motor of the Marklin train.

The motor driver can change the direction and speed(voltage applied) of the motor through PWM.   

I use a Polulu board with the MAX14870 already soldered on, it's small and it can easily be put inside the train along with the microncontroller PCB.  It also contains a feature to detect over-current drawn from the motor. One of the best features is that it is capable to deliver a continous 1,7A to the motor which is perfectly in  the range of the Marklin motor. The input voltage is variable between 4 - 36Vdc. 

I will power the rail tracks with 24Vdc, and each motor will draw around 900mA  (@22Vdc). Even with a high ballast weight applied to the train , the current will never exceed 1,7A which makes the MAX14870 ideal. 

A further improvement would be too integrate the MAX14870 IC into the design of the microcontroller board. 

In order to change the direction I can use two concepts:

The first one is to change the stator coil of the Marklin motor with a permanent magnet. This method is used by a lot of DIY'ers that want to convert their analog Marklin trains to digital ones. Their are companies that sell magnets that can replace the stator coils. But it comes with a price tag, that I'd rather try to avoid. With this method the direction is changed by inversing the anker of the motor. This is done by the MAX14870 IC. 

A second method is too keep the stator coils and switch between those two coils with a small relay. I use a micro relay (5VDC latching) from Omron which is half the price of a stator magnet replacement kid as mentioned above.  

Both methods can be used with microcontroller board that I designed. 

The dimensions of the PCB board had to be very small. Marklin trains in HO scale don't have a lot of space inside (because of the scale used). By removing the old relay of the stator coils I had enough space to put the microcontroller board (21mm x 28mm) and the Polulu board (12mm x 15mm) with an Omron micro relay inside the train. 

350px-3016-schema (1).png

wiring schematic of an analog Marklin train (HO scale)

Portable Network Graphics (PNG) - 26.52 kB - 09/08/2017 at 13:21



Microcontroller board schematic

Portable Network Graphics (PNG) - 73.66 kB - 09/08/2017 at 13:16



Polulu board

JPEG Image - 50.68 kB - 09/08/2017 at 13:16



Polulu board

JPEG Image - 65.91 kB - 09/08/2017 at 13:16


  • 1 × ATmega328P Microprocessors, Microcontrollers, DSPs / ARM, RISC-Based Microcontrollers
  • 1 × MAX481 Switches and Multiplexers / Analog Switches and Multiplexers
  • 1 × POLULU MAX14870 single channel PWM motor driver
  • 1 × omron g6k-2p-y-5VDC micro relay 5VDC

  • DC - supply over RS485

    alexander debou09/13/2017 at 07:51 1 comment

    In this log I'd like to explain the concept to feed power over the data bus:

    Their are a couple of configurations to combine the power supply and data on the same bus. It all depends oon seperating the power supply from the data.  The data is transmitted over a differential voltage across the two terminals of the RS485 driver (A - B) 

    The picture above shows a possible configuration. A shielded cable is used to reduce noise when data is send over the cable. The seperation of the power supply and data is done by the capacitors C1,C2 and the inductors L4A, L4B. 

    Simply said: 

    The two capacitors will block the DC - voltage from the power supply while the inductors will act as a very high impedance towards high frequency signals ( RS485 data). It's important to choose the inductor value with the according baudrate or transmission speed of the data. 

    The inductive reactance (XL = 2 * Pi * f * L) will increase with a higher inductance value, or higher frequency. It's important to lower the noise on the DC-power bus of the slave device as much as possible by using:

    * The highest possible transmission speed 

    * The highest possible inductance value

    The transmission speed depends also on the lenght of the cable, while the inductance value depends on the type of inductor (core, without core) , and the number of windings. One problem is the physical size of the inductor. In my application of the concept everything has to fit inside a small place

    (usable volume space: 20mm x 35mm x 9mm). 

    A bigger value will result in a higer number of windings. A seconde note is the current through the inductor. Because the train will demand currents at 900mA, the inductors windings will have to withstand the current (also the current saturation value of the inductor is important). The high inductance value and the current rate will result in a relative big inductor. 

    A downside of this configuration is signal noise of the power supply. All power supplies introduce some noise to the connected circuits. It's important that the power supply has some noise reduction circuits to minimalise the noise. This is important because the DC-voltage is supplied on both wires of the cable, and the capacitors to the RS485 driver only block DC-voltages noth noise (which are AC-components).

    Other configurations cancel the signal noise of the power supply by connecting the positive terminal of the power supply to both wires of the cable and the negative terminal to the shielding braid of the cable. This implementation cannot be used because we connect the cable to Marklin tracks, which have only two seperated rails. 

    Other signal noise may come from the motor used in these trains. It will be necessary to do some tests and choose good components:

    * Determine the maximal length of the cable with the highest transmission speed and low data errors.

    * Determine the ideal inductor ( important: type, physical size, current ratio). 

    * A good DC - power supply with a low signal noise ratio or a good noise reduction filter. 

    The design of the PCB only includes the capacitors that will block the DC-components on the cable. Because of the size of the inductors ( I'll be using axial inductors) they will not be placed on the PCB. 

    This link explains different kinds of configurations that can be used to power devices over a RS485 bus:

    (Picture used in this post came from this link and is edited a bit to be used in my application)

  • waiting for components, and software progress

    alexander debou09/08/2017 at 13:37 0 comments

    After the design of my concept , it's time to test al the boards, at software , and tune everything. 

    I'm currently waiting for the components to arrive, everything comes from China so I will have to wait a couple of weeks for my orders to arrive. At the moment I'm writing the software , and I'll test it with an Arduino Nano and a Polulu board. 

    The goal is to write software that receives data packets from a computer (connected with a adapter to the RS485 - POWER bus) handle that data and control the motor with this data. Each train will act as a RS485 slave with the computer acting as a master. 

    To test the functionality of the software and hardware I'll make a small interface (in C#) with Visual Studio to control the train (speed, direction, start stop, lights on/off , ... ).

    Further updates will be posted! 

View all 2 project logs

Enjoy this project?



Jasper Sikken wrote 06/26/2020 at 20:22 point

Hi Alexander, I like the power over RS485. Is it working? What voltage and current. WHat is inductor value and manufacturer part number? Can you show schematic and picture with inductor? 

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates