arduino page
As an Arduino user, here I will put my own arduino stuff
Table of contents:
SRF-04 Ultrasonic ranger with arduino
I've put together an SRF-04 ultrasonic ranger module and an Arduino board. I've picked up SRF-04 because it's cheap and has a good range sensitivity.
How it works

Feeding the sensor init pin with a pulse, should give back a pulse out of the echo pin, with a time proportional to the distance.
Thanks to the Arduino framework, it is very easy to code a minimal firmware that prints out the value read by the sensor.
Here it is:
#define echoPin 2 // the SRF04's echo pin
#define initPin 3 // the SRF04's init pin
#define ledPin 13
unsigned long pulseTime = 0; // variable for reading the pulse
void setup() {
pinMode(initPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
// send the sensor a 10microsecond pulse:
digitalWrite(initPin, HIGH);
delayMicroseconds(10);
digitalWrite(initPin, LOW);
// wait for the pulse to return. The pulse
// goes from low to HIGH to low, so we specify
// that we want a HIGH-going pulse below:
pulseTime = pulseIn(echoPin, HIGH);
// print out that number
Serial.println(pulseTime, DEC);
// blink led, and wait
digitalWrite(ledPin, HIGH);
delayMicroseconds(1000*500);
digitalWrite(ledPin, LOW);
delayMicroseconds(1000*500);
}
Distance sensor using reversed leds
You can make a cheap distance sensor just using LEDs!
When a LED is hit by light, a voltage appears at his pins. If the LED is first reverse biased, it spots a capacitance effect, and the light which hits the LED affect the discharge time
I tried different LEDs (ultra bright red, ultra bright yellow, infrared), and I found the best (but also expensive) are the IR LEDs. You are free to try any kind of diodes, but consider that ultra bright LEDs will give you better results.

Here's a proof-of-concept program for the arduino:
#define LED_cathode 3
#define LED_anode 2
unsigned long time;
void setup() {
pinMode(LED_anode, OUTPUT);
pinMode(LED_cathode, OUTPUT);
digitalWrite(LED_anode, HIGH);
digitalWrite(LED_cathode, LOW);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
Serial.begin(9600);
}
void loop() {
// forward bias the led
// This constitutes the "ON" state of the led
pinMode(LED_anode, OUTPUT);
digitalWrite(LED_anode, HIGH);
digitalWrite(LED_cathode, LOW);
delayMicroseconds(200);
// reverse bias the led
// This constitutes the 'CHARGE' state of the led,
// filling it with a 5v charge which it discharges
// internally based on the light level
digitalWrite(LED_anode, LOW);
digitalWrite(LED_cathode, HIGH);
pinMode(LED_anode, INPUT);
time = pulseIn(LED_anode, LOW, 200);
// print the value to serial
Serial.println(time, DEC);
}