Building the IoT Railroad: Smart Control for a Classic DC Layout
đź§ Why I Built This
This project started like a lot of mine do: I wanted to combine something nostalgic with something technical. After relocating and downsizing my layout space, I saw an opportunity to do something different with my model train setup—integrate it with my homelab and smart control stack.
The result: a DC-powered model railroad wired with IoT-enabled block control, a web dashboard, and plans for full automation—all built around ESP32s, Node.js, and MQTT.
This isn’t a DCC layout. It’s traditional DC—with modern control layered on top.
🛤️ The Track Plan
The layout is built on Bachmann E-Z Track in a dogbone configuration. It includes:
- A single-track mainline
- A passing siding
- A small yard
- A coal mine spur
Scenery will come later. For now, this layout is a testbed for how far I can push smart DC control.
⚙️ How It Works (Now)
Right now, the track is divided into five manually controlled blocks:
- Mainline
- Main Passing Siding
- Yard Passing
- Coal Spur
- Yard Spur
Each block is controlled via an ESP32 and H-Bridge motor driver. These are exposed to the network through a simple Node.js-based dashboard, which I run from my homelab.
Key features:
- Control any block’s power from any device on the network
- Group power control dropdowns for syncing blocks
- A “lights-on” mode that powers lights without moving the train
This all happens in real time—no lag, no cloud, no unnecessary UI. Just a responsive dashboard and physical control through microcontroller relays.
🔄 What’s Coming Next
Phase 2: Turnout Automation
Each turnout will be controlled via dual relays, triggered by the dashboard.
To prevent coil burnout, relays will only pulse for a fixed duration. A second ESP32 will handle turnout control to offload the main system.
Phase 3: Block Detection + Automation
Using current sensors, I’ll detect occupancy per block. This will eventually allow for:
- Automated routing
- Visual feedback on dashboard
- Remote permission-based train ops
The long-term goal: open this up to controlled remote access, where other users can operate the layout in real time under defined limits.
🔌 Why Not Just Use DCC?
DCC is great. But this wasn’t about ease—it was about experimentation.
I wanted to see what it would take to build an open, networked train control system using basic DC principles, IoT hardware, and my own stack. It’s a chance to prototype control logic that’s flexible and completely vendor-independent.
Also: if something breaks, I can fix it. That’s the beauty of DIY.
đź§Ş Stack Breakdown
Microcontrollers:
- ESP32 for track block control
- Planned: second ESP32 for turnout automation
Backend:
- Node.js + Express
- Local MQTT broker (planned)
- REST endpoints for block toggles
Frontend:
- Basic HTML + JavaScript
- Hosted locally on the homelab
- Mobile-optimized for use from phone/tablet while operating trains
Data flow:
plaintextCopyEditDashboard UI → Node.js API → ESP32 relay control → Track blocks
↑
(future: MQTT sensors for feedback)
📦 Where It’s Going
Long-term, I want this to be a full-blown interactive layout control platform with:
- Remote user session support
- Real-time turnout feedback
- Track plan overlays with active status indicators
- Voice or MQTT-based commands
- Simple control rights: "you get the coal spur", "you control mainline"
It’s a niche project—but it scratches the same itch as security research. You build systems, break assumptions, and learn a ton along the way.
🎤 Final Thoughts
This isn’t the most photogenic layout I’ve built—but it’s the smartest. And honestly? Wiring this system taught me more than most of my weekend pentests.
If you’re into model railroading, ESPs, or building strange but satisfying hybrid systems—this project might be up your alley.