IR Distance Sensor

Parts

-Arduino microcontroller and carrier board

-LiPo battery

-Sharp Distance Sensor (Data Sheet)

Prepare the breadboard

Program the Microcontroller

/**
 * @file: blinking LED example
 * @date: 4/5/2011
 *
 * @DESCRIPTION
 * SHARP IR distance sensor, use correct cable! 
 * 
**/
#define IRpin 1 // analog pin for reading the IR sensor
//--- Function: Setup ()
void setup() 
{
     Serial.begin(9600); // start the serial port
}
//--- Function: Loop ()
void loop() 
{
     float stepsize = 5.0/1024; // 5V supply, value which is between 0 and 1023
     float volts = analogRead(IRpin)* stepsize; // value from sensor * stepsize
     float delta = (80-10)/2;                    // worked out from figure 2
     float distance = delta*pow(volts, -1.10); // theoretical distance / (1/Volts)S
     
     Serial.println(distance); // print the distance
     delay(100); // wait
}