Go over to the paralax web site and look at the bo-bot projects.
Some place there is complete basic stamp code for this. Look in the document section. You can do this using IR or what they call wiskers.