Photoresistor controlled servo

I am needing a hand fixing the code for my project. I want the servo to rotate a certain distance when the photoresistor light reading reaches a certain point, but it doesn’t do anything when it surpasses the threshold.

#include <Servo.h>

Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0; // variable to store the servo position
int photopin1 = A0;
int threshold = 300;

void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
Serial.begin(9600);
}

void loop() {
if(photopin1 >= 400) {
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(150); // waits 15ms for the servo to reach the position
}
}
Serial.println(analogRead(photopin1));
delay(200);
}

You were using the pin number as the input value from the photoresistor. Try this instead:

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position
int photopin1 = A0;
int value = 0;
int threshold = 300;

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  Serial.begin(9600);
}

void loop() {
  value = analogRead(photopin1);
  if(value >= 400) {
    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(150);                       // waits 15ms for the servo to reach the position
  }
  }
  Serial.println(value);
  delay(200);
}
  if (photopin1 >= 400)

You told the program that the value of photopin1 was A0.

You should be testing the analogRead() value of photopin1 not the value of the pin number

When using the code above I get continuous rotation it doesn't stop for the next light.

I’ve gotten continuous rotation to stop, but now using this code it does not turn.

#include <Servo.h>

Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0; // variable to store the servo position
int photopin1 = A0;
int value = 0;
int threshold = 300;

void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
Serial.begin(9600);
}

void loop() {
value = analogRead(photopin1);
if(photopin1 >= 400) {
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(150); // waits 15ms for the servo to reach the position
}
}
Serial.println(value);
delay(200);
}

continuous rotation

Have you actually got a servo or a servo butchered to provide continuous rotation ?

  value = analogRead(photopin1);
  if (photopin1 >= 400)

Why do you ignore the value read from the pin ?

I have a sail-winch servo designed to rotate up to 3.5 turns HS-785B. I had thought that was what you had meant as well when you said "You told the program that the value of photopin1 was A0.
You should be testing the analogRead() value of photopin1 not the value of the pin number".

My apologies I understand what you were referring to in that comment now.

Any other suggestions you can think of?

Please post the code as it is now
I note that in the code posted so far there is nothing to move the servo from 180 once it is there.