Controlling SG90 mini servo with light switch

Hello, I have been trying to build a project with one part of it involving a photo-diode and an Led where I put something in between the two for a switch to acivate a servo motor. I then set up Arduino to use serial monitor to knowledge the difference to activate the SG90 servo motor with an if statement. Whenever I do the basic sweep example built into Arduino, my setup works fine, but whenever I try my modified code, the servo does nothing but rumble. Here is my modified code below. Thank you!

// Sweep
// by BARRAGAN http://barraganstudio.com
// This example code is in the public domain.

#include <Servo.h>

Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created

int pos = 90; // variable to store the servo position
int sensorPin = A5; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor

void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);

Serial.begin(9600);
}

void loop()
{
sensorValue = analogRead(sensorPin);
Serial.println(sensorValue);
if (sensorValue>1000){

for(pos = 90; pos < 0; pos -= 1) // goes from 90 degrees to 0 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
}
delay(5000);
for(pos = 0; pos>=90; pos+=1) // goes from 0 degrees to 90 degrees
{
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
}
}

}

How is your setup wired?

You say you're using a photodiode and a LED. How are these connected?

It's probably a good idea to display the analog input in the serial monitor so you can see what the readings are.

Also read the "How to use this forum" sticky. Item #7 tells you how to post code. You can edit your original post and you code tags.

DuaneDegn:
How is your setup wired?

You say you’re using a photodiode and a LED. How are these connected?

It’s probably a good idea to display the analog input in the serial monitor so you can see what the readings are.

Also read the “How to use this forum” sticky. Item #7 tells you how to post code. You can edit your original post and you code tags.

Hello, surprisingly enough I just switched out the code that set the servo to go from 90 degrees to 0 and back to the Arduino example sweep code going from 180 to 0 and back and it worked. Any ideas as to why that could happen? Everything seems okay in the serial monitor with this adjustment so the readings give over 1000 in the serial monitor when I put my finger in between the photodiode and the led and in the 900s when I leave it alone. With the previously posted code, it would work for a short time and just stop giving new values in the serial monitor.

Do not cross-post. Other thread removed.

ok