Automated Lego Train Container Terminal

The inspiration for this installation was the Maersk train that I bought recently. Take a look at the Maersk train and you will notice that there’s no space between containers and the wagon: they just fit. The problem with automating things with Lego is that it isn’t very accurate: there’s always some backlash. And due to this backlash, you cannot make a system that puts Maersk containers onto the Maersk train.

Maersk_wagonSo I decided to use different containers; smaller ones. The ones that were part of the train sets in the ‘90s: just 4 studs wide. And since these containers were smaller, I could more or less use a copy of the 8868 technic arm. I got this set when I was a kid and it has always been one of my favorite Lego Technic sets.

But there was a problem: the containers were too slippery! The grabber couldn’t generate enough force to actually hold the container, even with an extra pneumatic cilinder. So I needed something made out of rubber on the grabber. After some digging on Bricklink, I found the part 45590: a rubber double axle connector. When these were put on the claws of the grabber, it was strong enough to lift a container!

MotorValveTo control the valves of the pneumatic system, I used special servo motors mounted on a Lego pneumatic valve, manufactured by This way, I could just steer the servo motor from the arduino to switch a pneumatic valve. At that time I didn’t have a regulated compressor, so every time I flipped a pneumatic valve, I turned the compressor on for a few seconds to be sure there was enough air pressure in the system.

In the first design the robotic arm was turned using pneumatic cilinders, just like the 8868 set. The turning appeared not accurate enough and it was replaced by an NXT motor which can be controlled very precisely. The NXT motors were connected to a special NXT shield for Arduino, also manufactured by

The idea was to create a terminal with two robotic arms which both could load and unload containers on/from a train. A train would stop at a side track so a switch was set to the side track when the sytem wanted to load/unload a train. The containers unloaded by crane 1 could be transported with a conveyor to the point where they could be loaded on another train by crane 2 and vice versa. Both robotic arms had a dedicated controller.

The system was able to recognize which of the two container trains had stopped for loading or unloading and the system kept track on which positions on which trains were occupied by a container. Knowing this, the system could pick containers to unload and pick places on the train to load containers. There was a random control on it: since the system knew how many containers were available for unloading, it picked a random number for the amount of containers that would be unloaded. After unloading, it would do the same for loading the train in another instance.

When I finished the building and the equipment inside, everything worked just fine. Until I set it all up in the living room… It was a very big layout and to set it all up, and I needed to clear out the living room. It took a few hours to set it all up, with help of a friend of mine. Probably due to the noisy environment of multiple Lego trains running, the communication between the different controllers (Arduino’s) didn’t work properly, which resulted in a sometimes completely dead container terminal! After a long day of looking for errors I found out it had to be the communication, which sometimes just worked just fine which made it harder to determine the problem. The next day (after a restless night) I decided to do some ad-hoc quick and dirty soldering to make one side of the terminal work. With some reprogramming I managed to make it all work on one side.

Since just one side of the terminal worked properly, there will be a container terminal 2.0 in the distant future!

Youtube videos