Skip to Main Content

Programming the LEGO MINDSTORMS NXT Robotics Toolkit
with MATLAB and Simulink

Free Code for LEGO MINDSTORMS NXT Remote Control and Embedded Control


The LEGO® MINDSTORMS® NXT robotics invention system lets you create and control robots using programmable motors and sensors. You can use MATLAB and Simulink to quickly program and test your LEGO MINDSTORMS NXT robots in a variety of ways.

MATLAB Based Code for LEGO MINDSTORMS NXT Remote Control

The remote-control solution, which runs on your host computer, uses the MATLAB serial I/O capability to send commands to the LEGO MINDSTORMS NXT through a Bluetooth connection.

With the remote-control solution, you can:
  • Start programming right away without any additional toolboxes
  • Work in the MATLAB environment for development and debugging
  • Work with MATLAB and Simulink Student Version
  • Learn programming concepts such as iteration, conditional statements, and object-oriented programming
Simulink Based Code for LEGO MINDSTORMS NXT Embedded Control

The Embedded-Control Solution is developed using Simulink, Real-Time Workshop, and Real-Time Workshop Embedded Coder; it is then converted into machine language and downloaded to run on the LEGO MINDSTORMS NXT.

With the embedded-control solution, you can:
  • Avoid Bluetooth range limitations because the program runs directly on the LEGO MINDSTORMS NXT
  • Program the motors and sensors precisely for coordinated, real-time execution
  • Model, visualize, and test your robot’s behavior using Virtual Reality Toolbox software
  • Learn about control algorithms and production code generation using
    Model-Based Design

To submit questions or comments about these solutions, please e-mail mindstorms@mathworks.com.

Related Products LEGO MINDSTORMS NXT and MATLAB Resources User Community Downloads
LEGO MINDSTORMS NXT Toolkit- Using MATLAB and Simulink to program LEGO MINDSTORMS NXT Robotics

Complete the form to download your free MATLAB and Simulink LEGO MINDSTORMS NXT code

*Is this for use in a student competition?

*Choose your solution.

1. The remote-control solution includes MATLAB classes, M-files, and a GUI demo.

2. The embedded-control solution includes Simulink blocks, NXT programs, and a list of resources.