IR Lego Power Function for train, switch control with servo motor, light signal using remote wifi controlled MCU based on ESP32-C3 super mini running .NET nanoFramework!
Push the publish tag, or a tag prefixed with publish-, to create a GitHub Release. Publishing a GitHub Release manually also starts the publishing workflow.
Each release contains the LegoInfrared.bin, SignalSwitch.bin, and TrainDetect.bin firmware files. Docker images for amd64, arm32, and arm64 are published to ghcr.io/<owner>/<repository> with tags in the form <architecture>-<release-tag>.
One LegoInfrared module allows to control any Lego Power Function and support all Lego modes including exclusive modes which can't be done thru any of the Lego remote control through API. Please refer to the LegoInfrared project for more details. In our case, this module will control trains.
Specific module allow to control servo motors used to pilot Lego switches and to pilot red/green signal lights. Check this video to see in action the project in a real Lego city!
Once the module flashed, you will be able to set the wifi to each module. For this, connect to the LegoInfrared wifi that is available, then go to the URL http://192.168.4.1 from a browser, set the values and you'll be good to go! If you've done something wrong, the wifi hot spot will still be present and you can reenter the credentials.
In case of success, the IP address of the module will be displayed. You can now connect back to your wifi and connect to the IP address of your module. You still need to give the module an ID in the case of the switches/signals ones. Each ID must be unique. You will also have to select if you want just the switch, the signal or both.
The infrared module require a bit of electronic. You'll need a to drive enough power in the infrared led to be able to control trains or other Lego Power Functions in large rooms or with a lot of lights. For this, you'll need to build the equivalent electronic:
The module is configured. You can change the default values if you're using a different model and make your own electronic.
Servo motor to be at +5V voltage. The control pin should be connected to the configured pin.
For the hardware part, you'll need simple servo motor, here is a basic view on how to integrate them with the Lego switch:
Piloting signals is quite straight forward and you need a little bit of electronic:
You have a default circuit file that you can edit. A PowerPoint can be used to quickly create the circuit and the elements. Note the name of the files which must be the same.
You need to setup docker on your machine and install Docker or Podman.
You also need to ensure you have gpiod installed: sudo apt-get install gpiod
docker run -d \
--name legotrain \
--restart unless-stopped \
--network host \
-v $(pwd)/LegoTrain/config:/app/config \
ghcr.io/ellerbach/legotrain:arm32-publish-1.0The Dockerfiles use FROM --platform=$BUILDPLATFORM so the .NET application is compiled on the host architecture while the final image targets the selected architecture. BUILDPLATFORM is set automatically by Docker BuildKit; do not set it manually.
Docker Desktop includes Buildx. On Linux, install the Docker Buildx plugin, then verify that it is available:
docker buildx version
docker buildx inspect --bootstrapThe helper scripts build one architecture at a time and tag the image as <architecture>-<version>:
./build-docker.ps1 -Platform amd64 -Version 1.0
./build-docker.ps1 -Platform arm64 -Version 1.0
./build-docker.ps1 -Platform arm32 -Version 1.0./build-docker.sh --platform amd64 --version 1.0
./build-docker.sh --platform arm64 --version 1.0
./build-docker.sh --platform arm32 --version 1.0To build directly with Buildx, use the matching platform and Dockerfile. --load imports the single-platform result into the local Docker image store:
docker buildx build --load --platform linux/amd64 -f LegoTrain/Dockerfile -t legotrain:amd64-1.0 .
docker buildx build --load --platform linux/arm64 -f LegoTrain/Dockerfile.arm64 -t legotrain:arm64-1.0 .
docker buildx build --load --platform linux/arm/v7 -f LegoTrain/Dockerfile.arm32 -t legotrain:arm32-1.0 .Add --push to either helper script to publish to its configured registry. For direct Buildx commands, replace --load with --push and use a registry-qualified image name.
Release images are available from ghcr.io/ellerbach/legotrain for amd64, arm64, and arm32.
API are available. Documentation in this file. This does allow to pilot any Lego IR element, more than just trains.


