Interfacing Sharp IR sensor to Arduino Duemilanove

Hi every one hopefully you can help me out

I recently purchased a sharp GP2Y0A21YK0F from adafruit

And I basically wanted it to trigger a servo to go all the way to the right when it was 26 inches a way or roughly 74cm

I made a test code that was essentially a modified version of The example pot but it didn't work

#include <Servo.h>
int IRpin = 1; // analog pin for reading the IR sensor
Servo myservo;
int val;

void setup() {
myservo.attach(9);
pinMode (IRpin,INPUT);

}
void loop() {
val= analogRead(IRpin);
val = map(val,10,300,0,179);
myservo.write (val);
delay(15);
}

When I tried this sample program it worked
as far as reading the sensor values however I know this code is
just to show you the serial data of the IR sensor

int IRpin = 1; // analog pin for reading the IR sensor

void setup() {
Serial.begin(9600); // start the serial port
}

void loop() {
float volts = analogRead(IRpin)0.0048828125; // value from sensor * (5/1024) - if running 3.3.volts then change 5 to 3.3
float distance = 65
pow(volts, -1.10); // worked out from graph 65 = theretical distance / (1/Volts)S - luckylarry.co.uk
Serial.println(distance); // print the distance
delay(100); // arbitary wait time.
}

Any help on how I can get the sensor to turn the servo all the way right when its 76cm away would be really appreciated

So, when the second block of code prints 76, you want the servo to move?

Just add:

if(distance >= 75.5 && distance <= 76.5)
{
   myServo.write(someValue);
}

between the Serial.println and the delay statements.

Well I would like the servo to activate after the IR sensor detects within in that range and as soon as that range is triggered I would like the servo to go all the way to the right when object in front of the sensor moves

So basically here is the program blocks

1.Wait for Infrared to trigger in specified range- 2.When range triggered wait for target to move- 3. When target moves turn servo all the way to the right after five seconds. 4. Return servo to middle position

That's basically what I want to happen

Hopefully it not to hard to do
because I'm a little lost