smart train

This commit is contained in:
2026-04-04 12:31:29 +01:00
parent c88785295b
commit c0ae79dda8
+19 -8
View File
@@ -20,18 +20,29 @@ tags: ["Smart-Home", "ESP32"]
![Featured Image](./featured.png)
### 📋 Project Highlights
* **Goal:** What was the main objective?
* **Tech Stack:** Proxmox, Docker, Caddy, etc.
* **Outcome:** Did it work? Is it still running?
* Learning how to integrate electronics with IOT
* Experiment with basic motor control
* Setup an automated train that will eventually go around a Christmas tree based on smart home parameters.
---
### 🚀 The Deep Dive
This is where you write your main paragraphs. You can drop images anywhere using the standard syntax. Thanks to the style block above, they will automatically stay at 50% width.
During Covid I purchased a cheap second hand Hornby train set from Facebook Marketplace. After spending a surprisingly long time sanding rust off the tops of the tracks I was able to get the old train running again. These old analogue train sets work by connecting a power supply to the tracks and varying the PWM. This varied power causes the motor in the train to run faster or slower. This made me wonder how difficult it would be to setup a WIFI enabled micro controller to control the power to the tracks, thus enabling me to control the train both from my phone and to even become a part of my smart home.
## Motor Control
The microcontroller chosen was the ESP8266 due to its low cost, simple integration into home assistant and built in WIFI. This was connected to a L298N motor controller, an IR sensor gate and a Neopixel light strip. Everything was then mounted underneath the train tunnel to hide the wiring from view.
![Description](./tunnel.jpg)
### ESPHome
The ESP microcontroller was then flashed with ESPHome and added to home assistant. The code was written in yaml to utilize the IR gate to detect when the train had passed through. This allowed me to count the number of laps and with some careful timing meant I could make the train automatically stop at the station. The motor controllers were set as a gradual 1-10 scale going forwards and a simple on/off reverse button. Finally control of the Neopixel strip was added. This was further synced with the IR gate to allow the lights to be turned on as the train enters the tunnel.
### Smart Home Integration
With the train now fully controllable from within home assistant the control was expanded to google assistant. Since I already had google connected to my home assistant server I simply needed to add the configuration to expose the new controls. This allowed me to turn the train on/off with voice commands through my google home mini speakers.
![Description](./station.png)
---
### 🏁 Summary & Lessons Learned
Wrap up your project here. What would you do differently next time? This provides that "closing" feel for a future employer.
### 🏁 Future
The core functionality of this project is completed with everything I wanted to achieve being successful. Future improvements would be expanding the train control functionality and adding another sensor to make stopping at the station simpler and more reliable at different speeds.