Using a servo with LDR to turn a solar panel

Hey,

For school I'm making a solar panel that turns with the sun but my problem is I can't find a code.
When I use a program my servo keeps spinning around and ignores the LDR.
Can someone help me with a program please.

If someone gives you the code, what will you have learned?

But that's the problem I'm so new in Arduino that iI don't know anything about it.

BryanFTW:
But that's the problem I'm so new in Arduino that iI don't know anything about it.

EVERYONE started with zero knowledge, just like you.

find a tutorial...

(deleted)

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);
 
}
}

BryanFTW:
My servo stops now with one LDR.

That sounds like you have made huge progress since you said

But that's the problem I'm so new in Arduino that iI don't know anything about it.

I hope you are really proud of what you have learned.

And, now that you can get one LDR working why not try duplicating the LDR code - with different variable names - to see if you can get the other one to work.

...R
Planning and Implementing a Program

First correct either your program or the comments because they don't match

A section of your code and comments

      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

Your code with my comments

      myservo.write(110);                                         //tell the servo to move to 110 as fast as possible  
      delay(2500);                                                //2.5 second delay doing nothing
      myservo.write(95);                                          //tell the servo to move to 95 as fast as possible

What type of servo do you have ? Even if is one that moves slowly then why do you need to stop it after 2.5 seconds and reposition it ? Why not move it directly to where it is needed ?

How is the servo powered ? Not from the Arduino I hope.