Let's Make Robots!

Huge fully automated Lego train layout

Make sure that trains don't crash into each other and stop at stations

I've built a huge Lego train layout which is fully automated by a few Arduino's. The passenger trains ride around and after a while they stop at the station. The freight trains intersect with the track of a passenger train. A section of the track of the freight trains can be powered down: if the passenger train passes the intersection, the freight trains will stop. The trains use PWM signals to start and stop. For starting it is actually needed: otherwise the locomotive will disconnect from the wagons and drive away by itself. I've used four analog distance sensors to detect where the trains are. Since I had some Arduino's laying around, I was lazy and used three of them. That way I didn't really have to worry about race-conditions.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Cool! Cool!

They spelled my name wrong though ;)

Thanks for all the comments! I'm thinking about a version 2.0, with automated trackswitches and some extra trains. The problem is: I don't have much extra space in my living room to build it! This already took me almost 2 days to set it up, make a video and put it all away again. Maybe I need to buy a bigger house with a bigger living room ;)

You my friend, have come up with an awesome idea.... Love it. 

I never had a train set when I was a child, but created an HO-guage layout with three trains, after I had children of my own. That was about 1972 (yep, 41 years ago). Looking at yours, I can visualise how much better it could have been been if micro-controllers had been readily available at that time.  If picaxes or arduinos had been around then (at current 1972 prices so I could afford them...) I feel certain I could have had a much better train layout. As it was, my layout was sort of (ho-hum) average... Keeping the trains from running into each other was a matter of timing, rather than robotic control. I took the slower trains onto a siding when the "express train" was catching up to them.

Your work is great. I really like the controls and the way you have the individual trains on their own schedules yet working together.



My father is a trainiac since he was a child. He made his first HO-gauge when he was 20 and designed a mechanical timing automation with a pair of home fan motors and a gearbox from spare parts with a very big reduction. A tiny metal wheel makes contact with every metal contact along her circular path, activating relays, lights and trains. I will upload an entire post about this when I make a video. The system is still working on his current layout without problems

That would be nice to see. I would enjoy that.


If micro-controllers were available in 1972, the whole technical world would be 20 years ahead from now ;) The slower/faster trains was my first idea too, then I had the idea to add some sensors and isolated track sections to make it more "interactive".

I see a failure in theme here... why aren't the trains carrying beer kegs? :P

my only complaint, I dislike the mixing of lego and non lego. Needs to be mindstorms man :P

otherwise, awesome. I always wanted a lego train when I was younger, never got one. I guess your never too old for lego though. As it is, even at the age of 18 I had the technic stuff out 2 weeks ago, made a semi automatic rubber band launcher.