Using Arduino to control Märklin Z Switch Points

Fun

Detail picture of an Märklin Z Switch Point

After being able to run the model train using Bluetooth it was now time to look at all the equipment that makes a Model Train that much more fun to operate. I’m talking about Switch Points, Signals and so on. Controlling a Switch Point makes it possible to automate a whole multi-train setup. As much as it may be fun to collide trains, it’s more challenging and fun to NOT make them collide and have two or more trains running in an interesting pattern. Everyone can run a Train in a circle, no skill there, but having it switch tracks is cooler.

Problems and solutions

Switch Points have 3 cables attached to them, one yellow and two blue ones. The transformer has a yellow and grey output, delivering 10V AC. To cable the switch up, one connects the yellows together and the grey is used to switch the Switch Point by connecting it to either one of the blues for a short time.

The main issue I was facing was that Switch Points in Märklin Z are controlled by AC (whereas the trains run on DC). As the Arduino is using DC, I can’t control it directly. Therefore, just as I did with the L298N I need an element that facilitates the changes for me. The solution I settled on was a relay. Relays are cheap and easy to source (prefabricated 8 relay boards cost around 12EUR). The relays I used are probably a bit over the top as they are also able to switch 220V with 2A and are used a lot in home automation. The main reasons that I chose these are that they are also very good to control low-power equipment, and are easily available and cheap, making them a viable solution.

Cableing diagram to wire up an Switch Point

The next challenge was to see how the Switch Points are controlled. The Gauge Z Switch Points contain a magnet that pushes/pulls a rod that switches the rail. The original control switches are more like pushdown switches than toggle switches. The difference is that a toggle is permanently either On or Off, while a pushdown switch is only On when it’s pushed down and when released goes back to Off, hence the name. A relay operates more like a toggle switch. The relays used have 3 PINs (OptionA [Default]), Input, OptionB) on the utility side (the side that we want to control). The input is in the middle and the two options are flanking it. If no power is present, the relay connects the Input with OptionA hence the default. If power is applied to the relay, it switches and Input is now connected to optionB. If the power is taken away again, it reverts to optionA.

If I would have used a relay to control the switch points, the magnet inside would run the whole time, so I would reduce its lifetime. The Märklin Switch Points cost almost 60 EUR a piece if you can get them. There are 3-way relays but they don’t come pre-fabricated and are more expensive. So I had to make do with a normal 2-way toggle relay.

To solve the problem to my full satisfaction, I used a second relay that switches the power (Gray Cable) on and off, I called it the Floodgate. The wiring and the code I had to write needed to follow these principles:

  • the floodgate must be closed, so the magnets don’t run all the time. Only open the floodgate relay, when a Switch Point is switched and then switch it off again.

  • The default (no Power) setting for a really is OptionA. Therefore it would be best to connect the output of the floodgate to OptionB so if the power of the Arduino fails no Switch Points would be getting any current.

  • To make it more efficient I decided to switch direction first and then open the floodgate for a short time. This would make sure I don’t switch the electromagnets too often, thereby increasing their lifespan.

  • I needed to find out how long (in milliseconds) I would have to open the floodgate for the Switch Point to switch properly.

For the first test, I used the USB power of the Arduino instead of the Transformer. I also added a pushbutton, to flip the direction in the test code. The push button was not necessarily needed but made the whole testing a lot easier.

After running some tests I came to the conclusion that 300 milliseconds is the right amount of time for the floodgate to be open in order to make sure the electric magnet in the Switch Point is doing its job.

The test code is here: https://github.com/DanielLangenhan/maerklinZ/blob/main/weiche.ino

One challenge completed…

I was now able to properly switch my Switch points and Signals as well as operate a Decoupler. However, the issue I created with this solution is that I now need one wire plus one per Switch Point connected to the Android. The Nano has 12 digital ports (ESP has 16 ). The current solution would not leave me with much space for further expenses. Let’s count the ports used:
For the Nano I have to use two ports for Bluetooth, I need 3 ports for one L298N, which leaves me with 7 free ports. That means I can connect a maximum of 6 Switch Points or 3 Switch Points and a second connection to the L298N. Which is not that much.
Using the more modern ESP32 instead of the Nano would result in 6 more ports I can use, but I want to optimise the whole setup. So the next improvement should be to address this, right?

I will be using a Shift Register to control 16 relays with 3 cables….when the parts I need have arrived.

Previous
Previous

Controlling tracks

Next
Next

Use Bluetooth to control Märklin Z Model Train