IR sensor & digital read

Hi, i m trying to read an digital input from a sensor , infrared.

int ledPin = 13;   // LED connected to digital pin 13
int inPin = 12;     // pushbutton connected to digital pin 7
int val = 0;       // variable to store the read value

void setup()
{
  pinMode(ledPin, OUTPUT);      // sets the digital pin 13 as output
  pinMode(inPin, INPUT);        // sets the digital pin 7 as input
  Serial.begin(9600);
}

void loop()
{
  val = digitalRead(inPin);     // read the input pin
    Serial.print(val);

  digitalWrite(ledPin, val);    // sets the LED to the button's value
}

the problem is that when i start the arduino board, let s say i get value 0. If i put my hand in front of the sensor i get value 1. Then it just remains 1. Again if i restart the board with my hand in front of the sensor i get 1, if i take it away i get 0 and remains 0 forever. Please help!

i m sory but that not help me

Your code talks about a pushbutton but not an IR sensor. Perhaps that's your problem. Or perhaps your comments are completely wrong which doesn't exactly help us.

Please provide a link to the IR sensor you are using and how it is connected. There are many different things called IR sensors.

Steve