
Electric model trains are brilliant in their simplicity. The locomotives have little electric motors and the rails on the tracks act as wires to get power to those motors. But as is always the case with electric motors, there are varying levels of sophistication when it comes to speed control. To upgrade his ancient Z scale model train set, Clem Mayer from element14 Presents built this high-quality controller.
Model trains come in several common sizes, from the big outdoor-friendly G scale (1:25) to the tiny Z scale (1:220) that Mayer has — and there are more exotic sizes out there, too. Occasionally you’ll see large steam-powered locomotives, but most model trains are electric. Some traditional (read: old) controllers used AC power through transformers. But most modern models use DC power. Some even have digital control, so two locomotives on the same track can run at different speeds.
Mayer’s original controller was the simple DC type, but its voltage output was inconsistent. At low speeds in particular, it struggled to provide clean power. Fortunately, technology has come a long way. It is now easy and affordable to provide fairly clean DC power of varying voltage.

To achieve that, Mayer used an Arduino UNO R4 WiFi board. The user sets the desired train speed with a rotary encoder, so any arbitrary granularity is possible with quick changes to variables in the sketch. It then powers the rails through an Arduino Motor Shield Rev3, which has the ubiquitous L298N H-bridge driver. That’s meant specifically for powering motors through variable output voltage, so it makes perfect sense to use here.
That worked well right “out of the box” with a very simple sketch, but Mayer found that it still felt twitchy when making speed adjustments. So, he added a ramping algorithm that slows voltage changes for a smoother feel.
The result is a high-quality controller that makes the antique Z scale model train set pleasant to run.
The post Building a controller for tiny Z scale model trains appeared first on Arduino Blog.
Read more here: https://blog.arduino.cc/2026/03/16/building-a-controller-for-tiny-z-scale-model-trains/


