Fun Projects for your LEGO MINDSTORMS NXT!

Home     Projects     Help     Contacts

Ball Hunter
Building: Advanced
Program: Advanced

Building Instructions


Start by building the Castor Bot.  Click the picture for building instructions.

Building Instructions






Make sure the wire comes out on the top side of the motor as shown below.




Connect the rest of the wires as follows and route them as shown to keep them out of the way:
Light Sensor Shortest wire (20 cm) Port 3
Ultrasonic Sensor Medium wire (35 cm) Port 4
Claw Motor Medium wire (35 cm) Port A

Ball Hunter Programming

Use the program Ball_Hunt for the Ball Hunter.  This program makes the robot do the following:

  1. Pivot in place in a full circle and find the closest ball by scanning with the ultrasonic sensor.

  2. Drive to the closest ball and grab it.

  3. Use the light sensor to see if the ball is blue or red.

  4. If the ball is blue then push it a little farther to get it out of the way, drive back to the starting position, then go back to step 1.

  5. If the ball is red then we found it, so stop.


Using the Ball Hunter

The Ball Hunter will navigate more accurately on hard floors, but the balls like to roll around like crazy on hard floors, so short carpet works pretty well.  In deep carpet, the wheels will slip a lot and make the driving inaccurate.  You could also use a hard floor with something very small to keep the balls in place such as placing them inside small rubber bands on the floor, but something like a ball stand made out of LEGOs will be seen by the ultrasonic sensor even if the ball is no longer there and confuse the program.
  • Start the robot in the middle of a large clear area.  If it sees any walls or other objects, it may get confused and try to go grab them.

  • Place just the red ball, or both the red and blue balls, anywhere around the robot, but reasonably close to it (no more than about two feet away).  Closer will work better. 

  • The hardest and most interesting case is using both balls, with the blue ball starting closer to the robot, as shown to the right.  This will cause the robot to go after the blue ball first, reject it, then go after the red ball.


  • Depending on where the balls start, the program may or may not successfully find the red ball.   Try several different starting positions and see if you can determine which work better and why.

  • Try changing what the robot does after finding the blue and red balls.  Add something interesting.

  • This Ball Hunter's navigation strategy is fairly simple and highly dependent on accurate measurements from the rotation sensors.  Things like wheel slippage in carpet will start to mess it up.  There is certainly room for improvement in the program or even the overall strategy.  Can you improve it?  For example, after the robot reverses its pivot turn and turns back to point at where it thinks the closest ball was, you could add another ultrasonic scanning pass, this time perhaps pivoting to the left and right by just 30 degrees or so, to try to come up with a more accurate heading to the ball.  You could also imagine trying to stop halfway when driving to the ball, scanning again, and correcting the heading then if necessary.

Get nxtprograms.com on CD!
Click here for info

Home     Projects     Help     Contacts


Copyright 2007-2011 by Dave Parker.  All rights reserved. 
All project designs, images, and programs are protected by copyright.  Please see the usage policy.