Arduino code for ir sensor

This one is pretty easy, but I thought I would share the working code, I used analog pin0 for input this will give you the high and low values from the sensor on the serial port as well.

byte sensorPin=0;
int latestVal=0;
int maxVal=0;
int minVal=1024; 

void setup() {
  Serial.begin(9600);
  Serial.println("in setup");    
}

void loop() {
  //Serial.println("In loop");
  latestVal = analogRead(sensorPin);
  if(latestVal < minVal) {
    minVal = latestVal; 
  }
  if(latestVal > maxVal) {
    maxVal = latestVal;  
  }
  Serial.print("Max: ");
  Serial.print(maxVal);
  Serial.print(" Min: ");
  Serial.print(minVal);
  Serial.print(" Latest: ");
  Serial.println(latestVal);
  delay(1000);
}

Hello.

We should note that it looks like this code is intended for use with the Sharp IR distance sensor. Thanks for the contribution!

- Ben