CODE:-
#include <Servo.h>
int ldrval;
int ldrpin=A0;
int servopin=9;
int servopress=90 ;
int servoopen=36;
Servo myservo;
void setup() {
// put your setup code here, to run once:
pinMode(ldrpin,INPUT);
myservo.attach(servopin);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
ldrval=analogRead(ldrpin);
Serial.println(ldrval);
if (ldrval<=300) {
myservo.write(servopress);
Serial.println("press");
delay(100);
}
myservo.write(servoopen);
Serial.println("open");
delay(1);
}
0 Comments