Hello,
I'm working on a little project.
In this project I want to create a curtain that opens when its light and closes when its dark.
the curtains are hanging on a pully that is powered by a servo.
I have the following parts:
1x Servo (don't now the exact type of the servo, but it gots enough power to open the curtains)
1x Lightsensor
1x Ardiuno uno
1x Groove shield
[/color]
So I've written a code so the servo turns clockwise when its light and turns left when is dark.
The following codes works:
#include <Servo.h>
Servo myservo;
int pos = 0;
int photocellPin = 0; // the cell and 10K pulldown are connected to a0
int photocellReading; // the analog reading from the analog resistor divider
void setup(void) {
myservo.attach(9);
Serial.begin(9600);
}
void loop(void) {
photocellReading = analogRead(photocellPin);
Serial.print("Analog reading = ");
Serial.print(photocellReading);
if (photocellReading < 200){
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
for (pos = 0; pos <= 90; pos += 1){
}
}
}else if (photocellReading < 800)
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
But now I having a problem, the servo won't stop, the light (or dark) stimulus continu's in a loop and drives the servo in a continues loop. So, the sensor has to stop when a dark (or light) stimulans is done once.
So my question is:
How can i apply this into a code?