How to automate LEGO trains using original LEGO pieces (and Python)
Lasse Deleuran Lasse Deleuran
26.7K subscribers
39,566 views
0

 Published On May 9, 2024

In this video I show how to use PyBricks to program a train and a train car to use a sensor for automation. Hub-to-hub communication using Bluetooth is used to tell the cars when to open their doors.

LEGO Train used in this video: https://www.lego.com/en-us/product/ex...
Sensors:
https://www.bricklink.com/v2/catalog/...{%22iconly%22:0}
and
https://www.bricklink.com/v2/catalog/...

Project for the code: https://github.com/LasseD/PybricksPro...

The code is written using PyBricks: https://code.pybricks.com/

Chapters:
0:00 Speed Building
1:36 Show the standard functionality
2:06 Build in a sensor
2:30 Remove the lights
2:36 Colors to detect
2:45 Code for color detection
3:00 Color detection
3:11 Code color sensing
3:18 Which colors are uniquely detected?
3:24 Use colors to command the train
3:44 Slow and fast driving
4:02 Stop at a station
4:46 Expand the station
5:05 Motorize the doors
6:10 Code the hub-to-hub communication
6:18 Code for the train car doors
6:48 Failed test due to non-ending broadcast
7:21 Mechanical fix (swap a motor)
7:34 Code fix to halt broadcast signal for doors
7:50 Testing
8:48 Expand the track
9:17 Failed test for reversing
9:38 Reversing is added to outer track
9:44 Fail due to cable having too little space between cars
9:57 Fix of car buffers
10:04 Final testing of all features

show more

Share/Embed