#define irLedPin 13 // IR Led on this pin
#define irSensorPin 8 // IR sensor on this pin
#include <Servo.h>
Servo servoLeft;
int irRead(int readPin, int triggerPin); //function prototype
void setup()
{
servoLeft.attach(2);
pinMode(irSensorPin, INPUT);
pinMode(irLedPin, OUTPUT);
Serial.begin(9600);
// prints title with ending line break
Serial.println("Program Starting");
// wait for the long string to be sent
delay(100);
}
void loop()
{
delay(10); //wait for the string to be sent
int value =irRead(irSensorPin, irLedPin) ;
if ( value == HIGH)
{
servoLeft.write(0);
}
else
{
servoLeft.write(180);
}
Serial.println(value); //display the results
digitalWrite(irLedPin, LOW);
delay(200);
}
int irRead(int readPin, int triggerPin)
{
digitalWrite(triggerPin, HIGH);
return (digitalRead(readPin));
}