

#include <Servo.h>
Servo myservo;  // create servo object to control a servo
#define SENSOR  7  //connect IR Sensor to pin7
int anglepin = A0;  // analog pin used to connect the potentiometer
int angle;    // variable to read the angleue from the analog pin


void setup() {
   Serial.begin(115200);
   myservo.attach(8);  // attaches the servo on pin 8 to the servo object
   pinMode(SENSOR,INPUT);
   myservo.write(15);

}

void loop() {
    short sensor=0;
    sensor=digitalRead(SENSOR);
   // Serial.print("sensor=");
    Serial.println((int)sensor);

  angle = analogRead(anglepin);            // reads the angleue of the potentiometer (angleue between 0 and 1023)
  angle = map(angle, 0, 1023, 0, 180);  

  
    if(0==sensor)
    {
        Serial.println("Sensor is triggered!!");
        delay(200);
        myservo.write(angle);
        
    }
    else{
            myservo.write(angle-30);
            }


}
