Things You'll Need
Instructions
Build the LEGO Mindstorms Alpha Rex model according to the directions. The directions for the model are listed under References.
Connect the LEGO NXT brick to your computer using the Bluetooth or included USB cable. Run the NXT programming software.
Program three subroutines, one for walking forward, one for turning left, and one for turning right. To walk, use move blocks to program one leg to move and the motor on the back to tilt in the direction of the opposite leg. Repeat with the other legs to create walking movement. To turn, program one leg to move at a time. You may find it helpful to tilt the robot in the same direction as the tuning leg. If you have built the model before, you may already have these routines saved.
Program the robot to walk forward until the IR sensor picks up an obstacle. You can set the distance to be as close or far as you prefer.
Place a switch block on the end of the line. Program the block to randomly choose one of the two paths which it selects as an option.
Place the left and right turn blocks on the two branches of the switch block. This makes it so that the robot will randomly turn left or right when it detects an obstacle.
Place the entire program inside a loop. If you set the loop to infinite, the robot will walk forward indefinitely and turn when it sees obstacles. You can also set it to perform this only a few times.