Lego Train build (wifi controlled)

Well, I decided to jump back into Trains after many years. I decided that since I never considered myself great at model building that I’d jump into Lego trains. Now trains are an expensive hobby, and Lego is an expensive hobby. Does that make this doubly expensive? Kinda. I have decided to cut some corners though. I decided that I like *unique* builds, and that means not the same 10 trains Lego offer to everyone. Now, since I no longer have my original stash of Lego, my parts to build with are limited (to zero) so I’m starting with prebuilt sets. I actually found lots of lego-like trains on aliexpress, but eventually found out that a good number of the lego knock-offs (trains and otherwise) were cloned from rebrickable.com plans. So, I guess if you want to build one of those designs and don’t want to pay the piecemeal cost of real Lego, you may be able to find it on aliexpress. A word of warning, however, is that my aliexpress set did not come with stickers or the sticker pdf so I bought the plans from the actual author. To me this is still worth it since the kit on aliexpress was under $50 while real Lego would have cost around $240 for the parts.

assembled per instructions, with stickers

Next I needed track. aliexpress is also great for that, I think they are way, WAY closer to the cost of what is just injection molded bits of plastic than Lego. I also don’t find that the modern knock off quality is as bad as it used to be in the ’90s. This is not some Mega Blocks stuff, it’s still not *perfect*, but it’s plenty good for me. The variety also blew me away, There’s powered switch tracks, pedestrian bridges, stops, crossings, helixes, huge sets… and it ranges from $5 for small pieces to $100 for complicated sets including crossings, switches, raised sections… It’s very reasonably priced. You can also get tunnel entrances, bridges, and a bunch of other very nice pieces.

If I linked to ANY of these, they would be dead links by the time I published this post

I, however, have an even cheaper way to manage the track. There’s a wonderful thingiverse page that has all sorts of track pieces ready for printing. It had both track pieces that are available, but also some that were never available and are compatible all the same. The cross track with my aliexpress kit was a modern style that is built out of many small pieces and some of these hinged variable radius pieces. I printed a couple classic cross pieces to try out and they fit perfectly with no cleanup whatsoever.

Now, to the power. I saw that the original locomotive model was designed to fit a motor, and the tender was designed to fit a battery pack and receiver, so I bought the required parts to convert it. I did a little hacking however. The engineer’s compartment had to be mostly ripped out to fit the motor (but the essential running gear was left intact in this design). I would like to add a bit more structure to replace the missing parts, but that would require buying more parts and I haven’t settled on a variety pack of parts for tinkering yet. The Tender can contain a standard Lego battery, but I can’t actually get power into or out of that battery pack without disassembling a lot of the train so I tweaked that battery pack. I also didn’t like the idea of being locked in to a certain system of expensive accessories so I threw in an esp8266 and a L298 motor controller to control the speed of the train.

Hacked battery

This is a knock off of the Lego Power Functions rechargeable battery box. It has a knob on top to change the voltage and polarity of attached motors, but I don’t use that aspect of it. It had a standard power connector, but that wasn’t conveniently located for me, same with the power button, same with the barrel jack. I relocated all the power in and out and control to the ends (where I can get at them with my setup) and gave it a microusb connector as my C breakout was too big to fit.

This is the pinout of the power functions connector. Motors are hooked to C1 and C2, that is the same as controlling them with an h-bridge motor controller and either driving it full forward or full reverse. Other devices that want full power all the time (like my microcontroller) are hooked to 9v and gnd, the voltage on those pins doesn’t change with the speed/direction knob.

All that makes this work is a d1mini (esp8266 breakout board) and a solarbotics l298 breakout board. This board is slightly too big to work well in this application, but it has a spot for an onboard 7805 to power the microcontroller from the same battery as the motor. I replaced the 7805 with a switching regulator for higher efficiency. The code to drive this is super simple, I just grabbed a wifi web server motor controller program, tweaked it for forward and back range, and added a dead zone.

So, that’s the first pass at motorized wifi train control and parts sourcing. I’m probably going to make a system compatible with this mattzobricks guy. His stuff looks exactly like what I want. I also found other resources like 4DBrix for track and sensor 3d models and some suggestions on track layout and skipping the lego battery pack all together.

EDIT: there is a follow-up that shrinks the motor controller substantially.

One Response to “Lego Train build (wifi controlled)”

  1. Lego train v2 | Evan's Techie-Blog Says:

    […] already have an update. That l298 motor controller was way overkill for this and did not really fit where I wanted it to […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


%d bloggers like this: