element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Project Videos
  • Challenges & Projects
  • element14 presents
  • Project Videos
  • More
  • Cancel
Project Videos
Documents Building an Autonomous LEGO Train with CircuitPython and LIDAR -- Episode 672
  • Documents
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Project Videos to participate - click to join for free!
Related
Recommended
Engagement
  • Author Author: cstanton
  • Date Created: 4 Jul 2025 10:26 AM Date Created
  • Last Updated Last Updated: 7 Jul 2025 2:47 PM
  • Views 12313 views
  • Likes 8 likes
  • Comments 14 comments

Building an Autonomous LEGO Train with CircuitPython and LIDAR -- Episode 672

Lorraine hacks a Bluetooth-controlled LEGO train in this week’s episode of element14 Presents, mounting a track system to the ceiling of her home. She integrates CircuitPython, a Seeed XIAO board, NeoPixels, and a spinning LIDAR sensor to detect walls and control the train’s movement. Lorraine's project covers setup, track planning, component integration, and a ground-level test before moving the build to its final ceiling-mounted location. Watch to see how it performs!

Watch the Video

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

What happens when a Bluetooth-controlled LEGO train meets a maker's imagination and a ceiling with just enough clearance? In this episode of element14 Presents, Lorraine takes on the challenge of modifying a standard LEGO train to follow custom commands, detect obstacles, and operate on an overhead track. The result is a creative blend of electronics, coding, and home decor, designed to move a train through the airspace of a living room using smart control.

image

Design Intentions

The project began with a clear goal: to control the LEGO train programmatically and free it from its default Bluetooth remote. Rather than having the train occupy floor or shelf space, Lorraine designed a track layout to mount along two walls at ceiling level. The vision was to have the train run at set intervals, detect walls, and respond to its environment—all without manual input. This required integrating control logic, sensing capabilities, and a power-conscious hardware setup, all embedded within the constraints of a moving LEGO train.

image

Component Choices

The core controller is the Seeed Studio XIAO nRF52840 Sense board—compact, Bluetooth-enabled, and compatible with CircuitPython. It was small enough to fit inside a LEGO train carriage while providing the computing power needed for real-time control. A NeoPixel RGB LED strip was used to light up the train's windows with programmable color effects. For obstacle detection, a rotating LIDAR sensor was mounted on top of the train. Although a simpler ultrasonic setup could have sufficed, the LIDAR offered wider coverage and visual appeal. A separate battery setup powered the XIAO, with an optional servo mechanism considered for toggling the train’s power supply to conserve energy.

image

Challenges and Code

One of the primary challenges was managing power consumption. The LIDAR sensor in particular drew significant power, raising concerns about the available battery life. While a servo was considered for turning off the train’s main battery to conserve energy, it would also consume power and possibly reduce overall efficiency. The code was developed in CircuitPython using libraries for NeoPixel control and serial communication. Existing Python code examples were adapted to work with CircuitPython, removing unnecessary features like data plotting and focusing on extracting distance values to detect when the train should stop.

image

Results!

Initial testing was carried out on a dining room table with curved LEGO track sections to simulate ceiling conditions. The train ran successfully, with LEDs illuminating the interior and the LIDAR detecting nearby walls and stopping the train appropriately. Some adjustments are still needed for cornering behavior and battery optimization, but the system is functional and ready for final installation on the ceiling. This project demonstrates how off-the-shelf LEGO hardware can be enhanced using microcontrollers and sensors to create a smart, interactive home feature.

image

Supporting Downloads and Links

  •  Episode 672 Resources  

Bill of Materials

Product Name Manufacturer Quantity Buy Kit
SEEED STUDIO SBC, XIAO nRF52840 Sense, ARM Cortex-M4, 256kB RAM, 2MB Flash, Bluetooth, USB-C SEEED STUDIO 1 Buy Now
DFROBOT Servo Motor, Micro, 6 V, 0.17 N-m DFROBOT 1 Buy Now
DFROBOT LED Strip, Digital, RGB, Weatherproof, 60 LED, 1m, BBC Micro:bit Boards DFROBOT 1 Buy Now
Lego train
Lego track
Wood
 LiDAR LD06 Module (Farnell stock a similar model from DFROBOT )
  • custom LEGO track
  • Bluetooth LEGO train
  • home automation with LEGO
  • LEGO automation
  • NeoPixel LED train
  • seeed xiao
  • LIDAR sensor train
  • ceiling train setup
  • CircuitPython project
  • LEGO train modification
  • electronics maker project
  • LEGO train hack
  • element14 community project
  • DIY smart train
  • train distance sensing
  • friday_release
  • Share
  • History
  • More
  • Cancel
Actions
  • Share
  • More
  • Cancel
  • Sign in to reply

Top Comments

  • beacon_dave
    beacon_dave 14 days ago +1
    Ever get the feeling you missed out ? Wooden LEGO® train from the 1940s The Hobby Train set could be built into 30 different official models ( Hobby Trains is released in 2007 as a LEGO Factory set…
  • Workshopshed
    Workshopshed 10 days ago in reply to beacon_dave

    A lidar is so much cooler than a tickertape. That kind of experiment could also be done with a video camera from the side and some kind of image recognition but you'd need to compensate for the change of angle.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • beacon_dave
    beacon_dave 10 days ago in reply to beacon_dave

    Another one could be to replicate a classroom physics experiment, whereby a ticker tape timer was attached to a OO gauge model railway locomotive to measure its acceleration and deceleration as it sped down the length of a lab bench.

    The LIDAR module could replace the ticker tape timer in this case by logging the distances travelled over time intervals.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • beacon_dave
    beacon_dave 10 days ago

    I was trying to think of some creative STEM type activities this project could also be used for and the best I have come up with so far, is line and offset survey. Set the track (line) to traverse a room/corridor and have the LIDAR measure at 90° and 270° (offset). The data can then be collected and plotted.

    An additional sensor could detect the track sleepers to help measure distance traversed.

    The LIDAR module can also output point cloud data, which could be used to survey the area at the start and end of the traverse to complete the space.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • beacon_dave
    beacon_dave 14 days ago

    Ever get the feeling you missed out ? 


    image
    Wooden LEGO® train from the 1940s

    image
    The Hobby Train set could be built into 30 different official models
    (Hobby Trains is released in 2007 as a LEGO Factory set.)

    https://www.lego.com/en-gb/history/articles/b-lego-trains

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB 14 days ago

    Great build, lots of fun for the whole family.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • robogary
    robogary 14 days ago in reply to beacon_dave

    Thank you, somehow I missed it in the video. 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • beacon_dave
    beacon_dave 14 days ago in reply to robogary

    PDF in the video:

    https://docs.rs-online.com/c099/A700000007824693.pdf

    which links to:

    https://github.com/LetsOKdo/ld19

    which links to:

    https://www.ldrobot.com/images/2023/05/23/LDROBOT_LD19_Datasheet_EN_v2.6_Q1JXIRVq.pdf

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • robogary
    robogary 15 days ago

    Inspirational project. Can you share some details on the lidar sensor used ? 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • beacon_dave
    beacon_dave 15 days ago

    You could perhaps upgrade the shelf with a railway viaduct (LEGO styling ?) replacing the angle brackets and then have the base of the viaduct merge into cubby-hole style shelving and then from cubby-hole into horizontal staggered display shelving expanding to book shelving.

    The viaduct arches could be fitted with pixel LED uplighting for mood lighting or party lighting (with wake word detection so by saying 'KITT' it puts it into Larson scanner mode... etc.) 

    You could then work on projects for each cubby hole to fit in alongside other knick-knacks. Previous projects like your  Moon phase display, your ladder to the ISS space station, your Strava donkey derby and your Eye of Sauron, could all perhaps be worked into it.

    And then perhaps need some sort of an animatronic clock...

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • beacon_dave
    beacon_dave 15 days ago in reply to dougw

    Bit small perhaps for a cat to ride on to the next station. Slight smile

    I guess the lidar could be set to keep a safe distance from the cat until it got used to it. 

    Just a shelf though ? Surely a full blown cat wall playground is required here Cat

    You know, hours of work to design and craft only for your four-pawed furry friend to take zero interest in after completion (apart from the pile of cardboard boxes in the corner that the parts arrived in...)

    How would you accessorise it though ? Treat dispenser that dispenses based upon the calories expended on climbing the wall ? Cat pinball machine with sensors that trigger lights and sounds and move features of the climbing wall around ? Record the cat's movements and use it to create generative art in digital picture frames ?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube