Category Archives: Lego

Lego train revisited

General idea for a new train controller!

The idea is to have each train equiped with the following:

Arduino Nano

NRF204 Wireless transmitter

Infrared Emitter

The IR emitter will be put on the engine part and taped of so signals only get send to the local train. Lights are an option too of course. This way we can equip each train with it’s own unique NRF address and forget the whole Lego Power Functions channels and colors because the IR will only reach the one train.

On the Nano there will the NRF library, I like the RF24 library because of its ease of use, and the Lego Power Functions library.

One Arduino (also with an NRF will be in control of everything via Blynk app and the local Java server so minimum latency is guaranteed. Because the NRF also supports some sort of broadcast-to-all it’s easy to build in emergency stopping functionality, just in case. In the end this will probably be a Mega, but for now an UNO will probably be enough. This one will be connected via Ethernet (ENC28J60 SPI module).

Detection of the trains can be with reed contacts. This probably is the cheapest solution hardware-wise but you need to write a lot of software for that. Currently I’m investigating color-sensors. They have a tiny CCD with just a couple pixels for color detection. The huge advantage of this method is you can label each train at the bottom with unique colored bricks and have separate colors for different types of cars. You can measure length and direction of the train probably really easy:

ICE-LOC <> WAGON1 <> WAGON2 <> ICE-Close

(green) (blue) (blue) (red)


(purple) (yellow) (yellow) (red)

In this example we can differentiate between the freight train and passenger train and the start and end of the train. We can do all sorts of good stuff with this setup. For example have the passenger train get a higher priority, slow down the freight train at the station, read the train length etc.

Anyway, so far for the theory, we should put this in practice now, hopefully I’ll be able to show you some progress soon-ish. 🙂

Lego Trains again

Hello folks.

I’ve made a little project and video of my next step in Lego-train control land. You can check it out over here on YouTube

It’s basically simple detection with reed-contacts. I’ve placed a little magnet on the front of the train and the display let’s you look at where it is. Also this is my first go at the display, it works neat!

There are many, many, things to do. The next step will be detecting which way the train is going and using two magnets. On the front and on the back of the train. After that I’m thinking of running more trains on one track. The idea is to have one train automated and the other at manual control. So if the manual train blocks anything like a station or a section, the automated train reacts by stopping or whatnot.

Anyway, short text, but nifty progress. The reed magnets work perfect! I’ve just soldered them onto a little print which is made to fit between the Lego rails, like so:

IMG_3460-300x225 IMG_3461-300x225

Not the most compicated thing, but it runs really well. Much better than using physical buttons or photoresistors.