# Märklin model trains, traffic automation and control

**URL:** <https://discourse.nodered.org/t/marklin-model-trains-traffic-automation-and-control/65211>\
**Category:** Share Your Projects\
**Created:** [17 July 2022 11:53 UTC](https://discourse.nodered.org/t/marklin-model-trains-traffic-automation-and-control/65211 "2022-07-17T11:53:42Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [18 July 2022 07:41 UTC](https://discourse.nodered.org/t/marklin-model-trains-traffic-automation-and-control/65211/7 "2022-07-18T07:41:38Z")

</div>

Strange you should menton that, as I'm collecting my thoughts on using MQTT to control a model railway.

Before I retired I worked as a computer science and microelectronics lecturer. One of my tasks was thinking-up and running projects for the students. Over a period of time I got a series of students to build a model railway based on CAN bus (as CAN was used by the major employer who supported the college).  
The speed of the train was controlled by PWM as applied to track's voltage.

I use Wemos D1 Mini (ESP8266) modules around my house for reporting temperature/humidity and for controlling relays and operating LEDs - all via MQTT mesages and Node-RED.

My idea is to modify the train's motor connection...

- disconnect it from the track's pickup
- install an ESP-01S (tiny microcontroller) in the body of the train or the tender
- install an H-bridge chip and attached the motor to it

So the ESP-01S is powered from the track via an on-board voltage regulator. The (full) track's voltage is applied to the H-bridge with is driven by some pins on the ESP-01S (e.g. PWM and Dir).

I'm planning on working on this as a Winter-2022 project with a couple of my grandsons. I've done a few simple tests with a length of track and have got promising results. I implemented a similar PWM control system for a couple of slot racing cars way back in 2019 - which was just pure fun.

> [@Slot car racing - - - just pure fun](https://discourse.nodered.org/t/slot-car-racing-just-pure-fun/8782):
>
> I make no excuse at all - this is just pure fun. My students will love it !!!! I've just bought a slot car racing set from a local charity shop and have connected it to a WeMos D1 Mini on a breadboard driven from Node-RED via MQTT. On the breadboard is a PCA9685 (16-channel, 12-bit PWM module). It took some time sorting out the best PWM frequency and range settings, but eventually settled on 1500Hz with a range also of 1500. The car goes from a slow "creep" to just below "max speed", as at …

I should add that my projects are 'trivial' compared with @Mrb32 magnificent layout/system.

Here a photo of an ESP-01S (25mm by 15mm)  
 ![ESP-01s](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/7/c700881a61860b691b5cb63dd17d11ce2574eb68.jpeg)

---

_[View the full topic](https://discourse.nodered.org/t/marklin-model-trains-traffic-automation-and-control/65211)._
