Automatic curtain

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?

new doc 46_2.jpg

Does the servo move through about 180 degrees and stop at each end or is it a so called continuous rotation "servo" ?

If the former then how is it expected to move the curtains ?
If the latter then you will either have to move the "servo" for a fixed period to open/close the curtains or incorporate limit switches in the circuit to stop the curtains when they become open and closed.

How are you intending to power the servo ?

How to post your code in the Arduino forum:

Start the Arduino IDE and load or type in your code.
Right click in the editor window then left click [Select All].
Right click again then left click [Copy].
In the forum [New Topic] or [Reply] page, click the

</>

code symbol in the upper left.
Right click in the box that appears then left click [Paste].

Or type:

[code]

Type or
paste your
code here

[/code]

I did one of these.

I used a steeper hooked up to a gear chain. I had buttons to move the curtain, buttons to 'mark' the opened and closed positions, and a button to 'arm' the curtain (which moved the curtain t the closed position). At daybreak, it would move the curtain to the 'open' position and disarm itself. Using a stepper, moving the curtain to a given position was juts a matter of counting the steps.

So, like, do you have an annoying streetlight just outside your window, too?