   return 100000 / num;
 }
 
+int irSensorPin = 2;
+int irLED = 3;
+
 int IR()
 {
-  int num = sonsor_reading(2);
+  int num = irRead(irSensorPin, irLED);
   return num;
 }
 

        if(IR())
          delay(1000);
        else
          delay(light());
    }
            
}

void setup()
{
  Serial.begin(9600);
  Serial1.begin(9600);
  Serial2.begin(9600);

  int sensorPin = pin;
  int reading = analogRead(sensorPin);
  return reading;
}

int irRead(int readPin, int triggerPin)
{
  int halfPeriod = 13; //one period at 38.5khZ is aproximately 26 microseconds
  int cycles = 38; //26 microseconds * 38 is more or less 1 millisecond
  int i;
  for (i=0; i <=cycles; i++)
  {
    digitalWrite(triggerPin, HIGH); 
    delayMicroseconds(halfPeriod);
    digitalWrite(triggerPin, LOW); 
    delayMicroseconds(halfPeriod - 1);     // - 1 to make up for digitaWrite overhead    
  }
  return digitalRead(readPin);
}

// Helper Functions
