Infrared proximity sensorsInfrared proximity sensors work by sending out a beam of
IR light, and then computing the distance to any nearby
objects from characteristics of the returned (reflected)
signal. There are a number of ways to do this, each with its
own advantages and disadvantages:

Reflected IR strength
You could build a simple IR proximity sensor out of
essentially just an IR LED and IR photodiode. This simple
sensor, though, would be prey to background light (i.e.,
your IR "receiver" would be responding to naturally
present IR as well as reflected IR).

Modulated IR signal
A better solution would be to modulate your transmitted
IR (i.e., to send out a rapidly-varying IR signal), and
then have the receive circuitry only respond to the level
of the received, matching, modulated IR signal (i.e., to
ignore the DC component of the received signal, and only
trigger off the AC component). This method, though, is
still at the mercy of the characteristics (in particular,
IR reflectance) of the obstacle you're trying to
sense.

TriangulationThe best way to use IR to sense an obstacle is to
sense the angle at which the reflected IR is returned to
your sensor. By use of a bit of trigonometry, you can
then compute distance, knowing the location of your
transmit and receive elements. Needless to say, this
isn't a simple sensor to build yourself.

You're probably money ahead by
just buying an IR proximity sensor with this logic built
in. One I particularly like is the Sharp GP2D15 IR
Ranger. It has a built-in detection range of 24 cm (this
keeps its cost, and the complexity of your interface
circuitry down), is reasonably priced, and is available
from Acroname.
Acroname
also has an interesting article covering the operation
and utilization of all the impressive Sharp IR sensors
here.

The GP2D15 interface is 3-wire with power, ground and
the output voltage (the sensor outputs Vcc
when it sees something at 24 cm distance); it requires
4.5 - 5.5 V power for operation, and eats about 50 mA of
current as long as it is powered. So its advantages are
(1) its simple interface, and (2) easy, reliable sensing
of obstacles at a distance. Its disadvantages are (1) its
requirement for 5 V power, and (2) its requirement for 50
mA of current regardless of whether anything is being
sensed (neither of these recommend this sensor for
solar-powered 'bots).

If your BEAMbot's circuitry has provision for a
"touch-switch" contact sensor, the GP2D15 can easily be
used instead, with the addition of an NPN transistor:

Acoustic proximity sensorsOne oft-used method (at least on larger, pricier 'bots)
of avoiding hazards is via sonar ranging. Here, acoustic
signals ("ping"s) are sent out, with the time of echo return
being a measure of distance to an obstacle. This does,
unfortunately, require fairly accurate timing circuitry --
so acoustic sensors really require a processor of some sort
to drive them. Also note that acoustic sensing essentially
requires the use of commercial sensors, there's no real way
to "homebrew" something from scratch.

There's now also a "new kid on the block" -- the
Devantech SRF04 UltraSonic Ranger. Acroname
sells it (see their page on it here),
and "Tech Geek" has a review on it here.
This guy costs about twice what the Sharp IR sensors cost,
but has a much wider range of sensing; it costs far less
than the Polaroid acoustic rangers, is easier to interface,
and draws less power.

Capacitive proximity sensorsYour 'bot can also sense its distance to objects by
detecting changes in capacitance around it. When power is
applied to the sensor, an electrostatic field is generated
and reacts to changes in capacitance cause by the presence
of a target. The main disadvantage to this sensor (often
called a capaciflector) is that its usefulness is dependent
on properties of the obstacles it is sensing (namely, their
dialectric constant). The higher the dielectric constant
(say, water), the more sensitive a capacitive sensor is to
that target. The sensing distance depends on the dielectric
constant of the target and the surface areas of the probe
and the target.

Inductive proximity sensorsAnother method for sensing distance to objects is
through the use of induced magnetic fields. The primary
problem with this method is that it is largely confined to
sensing metallic objects.

For more information...

There's a great writeup on "hacking" the distance
sensor from a Polaroid OneStep camera here
(this is essentially a disection of the camera).
Meanwhile, the same site has a related article on
interfacing a processor to this sensor here.