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)

FREIGHT <> WAGON1 <> WAGON2 <> WAGON3

(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.

Lego Tracksections

And we are back for the next level! It’s time to divide up the track in sections so we can have a couple trains driving around. I found the blog at Lego.wordpress.com really interesting because it makes use of photosensors. I used microswitches, but they tend not to work really well with a carpet and everything, so I started using LDR’s instead. The result looks a bit likes this:

IMG_3028 IMG_3027 IMG_3026

I used a couple little prints to put the LDR’s on with a 10k Ohm resistor as voltage divider. This works pretty much ok. In the last picture you can see the first attempt of the setup. In the meantime I changed it a little bit, but not too much. The “railplan” looks like this at this point:

LegoTrainSchematic

In short, this is what happens so far:

1. Get the sensor reading

2. Determine the previous sensor (so you know which way your train is going)

3. Set the correct flags so we can call a function to get the trains up and running (e.g. what section will the train in be next?)

4. The function to get the trains running checks for some things. Of course we need to know if the next section to where the train is going will be busy or not. This can later be used to set switches and signposts!

As of this evening the sensors started acting up, but my detection mechanism worked flawlessly. It gives the current position, train number and next section via the Arduino Serial Monitor.

Ah well, more to fiddle around with! Catch you later!

Lego on Arduino

For the past couple days I’ve been working on getting my Lego trains to run via an Arduino (actually, it’s a fake one, but who cares!). On my YouTube channel (link) you can find my first attempt at stopping and starting with ease-in and ease-out. It’s, ofcourse, done with an infrared light, but the track is too big, so I ordered more LED’s from China. Takes a while to get here though …

The next task will be dividing the track into sections so two trains can drive the same track, but stay out of each others hairs and/or pass each other. After that there will be, hopefully, signalposts and automated switches.

The track division is made with old “micro” pushbottons from some alarmclocks. For now this works fine, but I’m planning on using LDR’s instead. The pushbutton methode dates back to about the stoneage, but it still works fine. I’ll be posting a movie about that soon.

B.t.w, you should also check out http://legopal.wordpress.com. Got some inspiration from there. I also Roland Wiersma a lot of thanks for creating the LegoPowerFunctions library for Arduino, found on GitHub. This library works really well!

Cheers!