Circuit:-
Code:-
#include <Servo.h> //servo library
Servo servo;
int LDR = 8;
int servoPin = 9;
void setup()
{
Serial.begin(9600);
servo.attach(servoPin);
pinMode(LDR,INPUT);
servo.write(0); //close cap on power on
delay(100);
servo.detach();
}
void loop()
{
if(digitalRead(LDR)==LOW)
{servo.attach(servoPin);
servo.write(90);
delay(1000);
servo.write(0);
}
else
{
servo.write(0);
}
}
No comments:
Post a Comment