Mr Hobbles

Automated Trains - A Pure Lego Solution

Recommended Posts

Following on from my previous topic about combining old and new Lego technologies, I decided to take it a step further and automate the trains. :) In the process, I added a new piece of Lego technology to the mix - Lego Education WeDo (1.0) hubs and sensors.

I decided to use WeDo (1.0) sensors for train detection for a couple of reasons.

  1. 9v light sensors plugged into the Control Lab could work, but are susceptible to changes in environmental light. I might still try this in the future though.
  2. Powered Up/LPF2 motion/distance sensors would work, but other than the SPIKE Prime hub, have no constant power solution at the moment - only batteries. I hope Lego offer some kind of mains/USB power option for the Powered Up hubs.
  3. WeDo hubs plug straight into USB, allowing constant power and no battery issues. The distance/motion sensor is also identical to the Powered Up/LPF2 one, offering infrared distance detection.


Below are a couple of videos of the setup working, but here's the breakdown.

  • Lego Dacta Control Lab. This controls:
    • The two signals. The first signal has red on port A, and green on port B. The second signal has red on port C, and green on port D. Each light is a Power Functions LED (the second bulb is hidden inside the control box beside the signal).
    • The two switches. One of the switch motors is on port E, the other is on port F. These are Power Functions medium motors.
    • The 9v track on port H. The Metroliner 4558 has a 9v motor.
  • Lego Education WeDo (1.0). There are two hubs, each with two distance/motion sensors attached.
    • The first hub powers the "Far away" side, and is used to detect trains approaching one side, while detecting trains at the end of the other side.
    • The second hub powers the "near" side, and does the opposite.
  • Lego Powered Up hub and Lego Control+ Medium motor powering the Crocodile 10277.
  • MacBook Pro running the Node.js/Typescript code that powers this, utilizing some libraries I've written and open sourced. The WeDo's are plugged straight in via USB, the Control Lab has a RS232 to USB converter cable.

The automation goes as follows:

  1. Track switches are set. Light is set to green. Train is slowly sped up until predefined max speed.
  2. Train does three loops. On the third loop, as the train passes the signal, it is set back to red.
  3. Train slowly comes to a stop in front of the red signal.
  4. Go back to step 1 for the other track/train.

Hope you enjoy. :)
 

 

 

Edited by Mr Hobbles

Share this post


Link to post
Share on other sites

Very nice. Still my dream to once create a fully automated and programmable LEGO train layout. Perhaps when I retire (in 20-30 years :( ).

Share this post


Link to post
Share on other sites
8 minutes ago, GianCann said:

Great job!

Too bad that the WeDo 2.0 hub costs too much :(

I actually have several...I forgot to mention those! They’re a good alternative if you want mains power, but the issue is that if power or the BTLE connection is interrupted, they turn off. It requires you to physically press the green button to reconnect, which may not be an option if the hubs are far away on the layout.

I preferred to stick to a wired data connection if I can, except for the trains. :)

Share this post


Link to post
Share on other sites

I think that is not possible to have a definitive solution with only LEGO products that offer a flexibility of power energy, communication and programming.

I preferr a solution with less cable on the layout (just the wire from sensor to hub), getting the power from the 9v track. But this solution requires however an hack to the hub to taken power from the track...

However, instead of the Wedo Hub, I think that there is a better solution based on City/Train Hub with Pybricks.
In case of lost BLE communication, the hub don't go in power off and you can reconnect to it without problem.

Edited by GianCann

Share this post


Link to post
Share on other sites

Very nice job @Mr Hobbles. Nice to see how you combined all those different systems. @GianCann that would be indeed an important advantage then over the standard firmware.

Share this post


Link to post
Share on other sites
On 7/24/2020 at 2:44 AM, Mr Hobbles said:

...

...

When I try to go to https://github.com/nathankellenicki/node-wedo/ I get an Error 404

Would ne nice to can have a look into the Library

Share this post


Link to post
Share on other sites
On 7/23/2020 at 11:59 PM, GianCann said:

I think that is not possible to have a definitive solution with only LEGO products that offer a flexibility of power energy, communication and programming.

We'll have to disagree there, I think I proved it above. ;) However I think it requires older Lego products - newer Powered Up products don't have a good solution for power/energy. I hope they come out with a hub type that allows power to be supplied via a cable - even better if it could be controlled over the cable as well as Bluetooth.

I also don't mind cables - they provide full power instead of requiring batteries, and if I were to build a properly build layout, I would hide the cables underneath Lego plates or something else. Personally I only want to use batteries if the model is moving, such as a train. For sensors, switches, signals etc, I prefer wires. I also like your idea of powering via the track, but I prefer pure Lego solutions that don't require modifications.

I do like the idea for Pybricks, but I think it excels for standalone builds that don't require a computer to control. In my case, for coordination of multiple devices/trains, I think the stock firmware works best, using a central computer for control.

Edited by Mr Hobbles

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.