Interfacing Arduino with LDR module to activate servo motor
Arduino Code:
#include <Servo.h>
Servo myservo; // create servo object to control a servo
const int LDRpin = 4;
void setup() {
myservo.attach(5); // pin 5 of Arduino with servo motor
pinMode(LDRpin, INPUT);
myservo.write(0);
delay(500);
myservo.write(90);
}
void loop() {
if(digitalRead(LDRpin)==0)
myservo.write(0); // tell servo to go to a particular angle
else
myservo.write(90);
}
Video:
No comments:
Post a Comment