LEGO WeDo Framework
LEGO WeDo Framework is a .NET library that enables programmatic control of LEGO WeDo 2.0 devices via Bluetooth. It works in conjunction with the Bluetooth Framework and provides a complete API for accessing motors, tilt sensors, motion sensors, and color sensors from C# applications. The project is open-source and distributed under a permissive license.
LEGO WeDo is an educational robotics platform designed for young learners. It combines standard LEGO bricks with a
Bluetooth-enabled SmartHub, a motor, and a range of sensors—typically including a tilt sensor and a motion sensor. The official
programming environment uses a visual, block-based language that is excellent for introducing logic, sequencing, and basic computational
thinking. However, the WeDo Framework opens a more advanced pathway:
developers and educators can bypass the graphical IDE and interact with the hardware directly from C# or any .NET language. This
creates a natural bridge from drag-and-drop programming to professional, text-based development.
In practice, the WeDo Framework exposes the SmartHub, motor, and sensors as strongly typed C# objects. Learners can write commands such as motor.SetPower(50); motor.Start(); and immediately observe a physical LEGO model respond. Because the feedback is tangible, abstract programming concepts—variables, loops, conditionals, event handlers, and even asynchronous operations—become concrete and easier to grasp. For example, a child might use an if statement to check the tilt sensor and change the motor’s direction, or use a while loop to make a vehicle drive forward until its motion sensor detects an obstacle. These activities provide a low-stakes, high-engagement environment where errors are visible, and debugging feels less like fixing abstract code and more like solving a physical puzzle.
The framework also supports integration with custom software, games, and automated systems, which greatly expands the learning potential. A student could write a C# console application that reads sensor data and logs it to a file, build a simple Windows Forms dashboard to display live sensor values, or even connect WeDo inputs to a game loop where physical gestures control an on-screen character. This not only reinforces core programming skills but also demonstrates how embedded devices, desktop applications, and real-world data can work together in a single .NET ecosystem. By moving from visual blocks to C# using the same familiar LEGO models, children experience a gradual, supported transition into professional software development while remaining engaged through hands-on play and experimentation.
Hardware Components
The WeDo 2.0 kit includes the following hardware elements:
- LEGO Building Elements - Standard bricks, beams, gears, and connectors for mechanical construction.
- SmartHub - The central control unit with Bluetooth Low Energy (BLE) connectivity. It supplies power to the motor and sensors and handles communication with the host.
- Motor - A DC motor with an integrated rotation sensor that provides positional feedback.
- Sensors - Detachable modules that provide environmental input:
- Tilt sensor
- Motion sensor
- Color sensor (optional, depending on kit version)
Sensor and Motor API Overview
The library abstracts the Bluetooth GATT protocol used by the SmartHub and exposes a set of .NET classes and events. Key capabilities include:
Tilt Sensor
Reports orientation state: TiltLeft, TiltRight, TiltUp, TiltDown, Level,
and AnyTilt. Applications can subscribe to TiltChanged events to react to physical manipulation in real time.
Motion Sensor
Detects objects within a range of approximately 15 cm using ultrasonic sensing. Provides distance readings and event notifications when an object enters or leaves the detection zone.
Motor with Rotation Feedback
Supports forward and reverse rotation with adjustable speed (duty cycle). The integrated rotation sensor reports the current angle in degrees, enabling precise closed-loop control of position or speed.
Color Sensor
Returns the detected color as an enumeration (Red, Green, Blue, etc.) and also provides ambient light
intensity measurements.
Bluetooth Communication and Protocol
The SmartHub uses Bluetooth Low Energy (BLE) and exposes a custom GATT service. The LEGO WeDo Framework handles device discovery, connection establishment, service/characteristic discovery, and implements the WeDo 2.0 communication protocol. All low-level Bluetooth operations are delegated to the Bluetooth Framework, which supports multiple Bluetooth stacks and platforms.
Developers do not need to deal with raw GATT operations; the library provides high-level methods such as:
ConnectAsync(string deviceAddress)SetMotorSpeed(int speed)ReadTiltState()SubscribeToMotionEvents()
Error handling and asynchronous operation patterns follow standard .NET conventions.
Open-Source License and Distribution
This library is released as open-source software under the MIT License. The source code is publicly available, allowing inspection, modification, and redistribution. Key points:
- Free for commercial and non-commercial use.
- No royalties or licensing fees.
- Can be incorporated into proprietary applications without disclosing your own source code.
- Community contributions and bug reports are welcome via the GitHub repository.
The project is actively maintained and tested against the latest .NET versions.
Download and Source Code
The complete source code, documentation, and examples are available on GitHub.
Integration into Applications and Games
Because the framework is a standard .NET library, it can be referenced from any .NET project type: console, WPF, WinForms, ASP.NET, or Unity (via .NET Standard compatibility). Typical use cases include:
- Educational software - Replace the block-based editor with a custom C# teaching environment.
- Game controllers - Use the tilt sensor or motion sensor as input for computer games or interactive installations.
- Robotics prototypes - Rapidly prototype motion control algorithms using the motor's rotation feedback.
- IoT and automation - Trigger actions on a PC when a sensor threshold is exceeded.
- Diagnostics and logging - Record sensor data streams for analysis.
Asynchronous programming patterns (async/await) are fully supported, enabling responsive UI applications without blocking
the main thread.
Frequently Asked Questions
- Which .NET frameworks are supported?
- The library targets .NET Standard 2.0 and is compatible with .NET Framework 4.6.1+, .NET Core 3.1+, .NET 5/6/7/8, and Xamarin.
- Can I use this with the original LEGO WeDo (not 2.0)?
- No, the original WeDo used a USB hub and a different protocol. This library is designed exclusively for WeDo 2.0 with Bluetooth LE.
- Is the Bluetooth Framework included?
- The WeDo Framework depends on the Bluetooth Framework. You must have a valid license for the Bluetooth Framework to use WeDo in production. However, the WeDo library itself remains free and open-source.
- Where can I report bugs or request features?
- Please use the GitHub issue tracker: https://github.com/btframework/WeDo/issues.