This is the code that I use but I still need to insert a second LDR. My servo stops now with one LDR. But what do I insert for another LDR?
#include <Servo.h>
Servo myservo; //name servo
int photocellPin = A0; //define photo cell reading input
int photocellReading; //define photo cell reading variable
int shadeOpen = 0;
int shadeClosed = 0;
void setup()
{
Serial.begin(9600); //initiate serial @ 9600 baud
myservo.attach(11); //define pin 11 as servo signal pin
}
void loop()
{
Serial.print("Brightness = "); //print "Brightness = "
Serial.println(photocellReading); //print the photocell reading
photocellReading = analogRead(photocellPin); //define photocellReading as pin 0 input from LDR
photocellReading = map(photocellReading, 0, 1023, 0, 179); //map the LDR input to a value between 1-180 so the servo can understand it
{
if (photocellReading <= 70 && shadeClosed == 0) //if the LDR is showing darkness and the shade isn't closed already
{
myservo.write(110); //then tell the servo to rotate forwards at a steady rate (close shade)
delay(2500); //2.5 second delay while shade is closing
myservo.write(95); //stop rotation after dalay
shadeClosed = 1; //set shadeClosed var as true
shadeOpen = 0; //set shadeOpen var as false
}
else if (photocellReading >= 110 && shadeOpen == 0) //if the LDR is showing light and the shade isn't open already
{
myservo.write(70); //then tell the servo to rotate backwards at a steady rate (open shade)
delay(2500); //2.5 second delay while shade is opening
myservo.write(95); //stop rotation after dalay
shadeOpen = 1; //set shadeOpen var as true
shadeClosed = 0; //set shadeClosed var as false
}
delay(1);
}
}