Giving Your Robot a Brain: Lesson on Programming with LEGO Mindstorms

Giving Your Robot a Brain: Lesson on Programming with LEGO Mindstorms
Page content

The mere mention of computer programming is enough to strike fear in the hearts of many adults, but never fear; LEGO has taken remarkable strides towards making the experience as pleasurable, accessible, and straightforward as possible while still leaving the room for more advanced users to write remarkably sophisticated programs.

Even before they get started on the computer, help them to define the task that they will be trying to accomplish. Once they’re working on the computers, they’re less likely to pay attention to the finer details of planning! Emphasize the need to consider what the sensors, motors, and TECHNIC parts are capable of- creating a robot that can hug the walls of a room or maze is possible, while making a robot that can run on two legs is not, or, at least, not with stock parts!

To get started, start the LEGO Mindstorms NXT software, then select either “Start New Program” or “Open Recent Program”. Have the students select the first option, then decide on a name for their team. To facilitate finding their files again, a very important concern when programming, have them use a consistent format such as “Team name-program number”. Once they have done this, they will see a gridded screen with a Mindstorms icon and a highlighted box labeled “Start”. To the left is a palette that allows you to access different categories of commands: Move, Play, Sound, Display, Wait, Loop, and Switch are the available categories, in order. To get started programming, all you have to do is find the programming block you want, click on it, and drag it into the program.

For the purposes of this exercise, we’re going to restrict our work to the Move and Sound blocks. Have the students select one, then drag it into the program and drop it. As soon as they do this, the program will link it to nearby blocks in order to establish a sequence for program execution. Looking at the bottom of the screen, they will notice different variables that they can change: in the case of the move block (the one with the gears on it), the controls allow you to alter the direction of the robot (making it turn), move duration and the time span associated with it, the power setting, and whether the motor actively stops or coasts after the move is finished. The sound block settings allow you to adjust the volume, play a sound file or tone, repeat, or wait until the completion of the previous move to start this block.

The initial goal of all teams is to program their robot to move forwards to a point, pivot 180 degrees, play a sound, return to its starting point, pivot 180 degrees, the play another sound to signal completion. When everyone has finished, discuss the exercise as a group.

This post is part of the series: Robotics in the Classroom

Rev up your science and engineering education by using robotics in the classroom to teach hands-on concepts in an engaging, fun, and flexible manner!

  1. Introducint LEGO Mindstorms NXT: Next Generation Robotics
  2. Mindstorms NXT in the Classroom, Session One
  3. Mindstorms NXT in the Classroom, Session Two: Going From Parts to Robots
  4. LEGO Mindstorms NXT in the Classroom, Session Three: Sensing the World Around You
  5. Mindstorms NXT In The Classroom, Session Four: Giving Your Robots A Brain
  6. The Many Benefits of Teaching Robotics in the Classroom