Solar tracker. cloudy tracking and return to sunrise position

Hi all..
new to the forum and coding....ish.
I have built a solar tracker and is tracking well...
I want to add in couple of parameters....eg, if it is cloudy (sensor reading low light value) Tracker makes intermittent steps to track where the sun would be....
Also, if dark, (sensor reading very low light value) tracker returns to sunrise position. (ie, rotate CCW 180, or, step CCW overnight, and hold until sensors detect high value).

Here is my current working code.....
dont know why but my readings are back to front, so high light levels = low percentage reading( bright = 0, dark = 100.

const int rightSensorPin = A0;
const int leftSensorPin = A1;
int rightSensorRead = 0;
int leftSensorRead = 0;
int rightLightPct = 0;
int leftLightPct = 0;
int degreeChange = 2;

//Arduino's CustomStepper library
//Author:  Igor Campos
#include <CustomStepper.h>
CustomStepper stepper(8, 9, 10, 11);
void setup() {
  Serial.begin(9600);
  stepper.setRPM(1);
  stepper.setSPR(2100);
}

void loop() {
  rightSensorRead = analogRead(rightSensorPin);
  leftSensorRead = analogRead(leftSensorPin);
  rightLightPct = map(rightSensorRead, 0, 1023, 0, 100);
  leftLightPct = map(leftSensorRead, 0, 1023, 0, 100);
  degreeChange = map(abs(rightLightPct-leftLightPct),0,100,2,10);
  Serial.print("right = ");
  Serial.print(rightSensorRead);
  Serial.print(" left = ");
  Serial.print(leftSensorRead);
  Serial.print(" Pct r/l = ");
  Serial.print(rightLightPct);
  Serial.print("/");
  Serial.println(leftLightPct);
  if(rightLightPct == leftLightPct ){
    Serial.println("Aligned");
  }else if(rightLightPct > leftLightPct +1){
    Serial.println("Turning CW!");
    rotateRight();
    stepper.run();
  }else if(leftLightPct > rightLightPct +1){
    Serial.println("Turning CCW!");
    rotateLeft();
    stepper.run();
  }
  
  delay(750);
     
}

void rotateLeft(){
  stepper.setDirection(CW);
  stepper.rotateDegrees(degreeChange);
  while(stepper.isDone() == false){
    stepper.run();
  }
}
void rotateRight(){
  stepper.setDirection(CCW);
  stepper.rotateDegrees(degreeChange);
  while(stepper.isDone() == false){
    stepper.run();
  }
}

I have been tinkering with the code but no........

  if(rightLightPct <80 &= leftLightPct){             // if all aligned no movement
    Serial.println("Aligned");

} else if(leftLightPct <10 &> rightLightPct +1){   // Bright Sun = sensor reading below 10%
    Serial.println("Tracking Sun");
    rotateRight();
    stepper.run();
     
} else if(leftLightPct >10 &> rightLightPct +1){   // cloudy = Tracking 
    Serial.println("No Sun -- Step Tracking");
    rotateRight();
    stepper.run();
    
} else if(rightLightPct >80 == leftLightPct +1){    // Night detection  = sensor reading above 80%
    Serial.println("Repositoning for Sunrise");
    rotateLeft();
    stepper.run();

Any guidence woul be greatly appreciated....
Sarah..

P.S.
Motor is mounted under tracker so left is right and so on.....
I cant make it too easy.....x

Please post a photo of a hand-drawn wiring diagram, with parts, part values and pins clearly labeled.

Maybe add the two percentages together and use that sum in your new tests.

Welcome to the forum and thanks for using code tags.

We can probably guess, but we would not need to guess if you posted your schematic! Did you read the forum guide in the sticky post yet?

.....what?

Not sure what you are trying to say there but I'm pretty sure that code won't do what you want/think it will.

I don't know the level of precision you need, but there are very good formulas to predict the position of the sun, any time of the year, you just need to know your latitude and longitude.

What Arduino do you have? There are several solar position libraries, but the best choice depends on which processor you're using.

That's how I'd be inclined to do it, but it doesn't allow for clouds causing the "correct" position to be less productive.

image

That is the expected result. The voltage divider uses a 1K resistor connected to 5V and the LDR to GND. Since the LDR resistance drops as light intensity increases, the ADC value decreases with light intensity increase.

If the right sensor is lower than value) and equal to left sensor, then tracker is aligned. No movement.

Just a general track.... Doesnt have to be spot on.

Check Kalogirou:
https://www.sciencedirect.com/topics/engineering/solar-incidence-angle

  rightLightPct = map(rightSensorRead, 1023, 0, 0, 100);
  leftLightPct = map(leftSensorRead, 1023, 0, 0, 100);

That should fix your sensor readings.

Adjusting values to try and understand them.......

Thankyou..x

The correct code for that would be

if(rightLightPct < 80 && leftLightPct == rightLightPct){

The &= operator in C/C++ is for use when performing binary bit-wise operations. It's not what you need at all. You need a logical "and" not a bit-wise "and", which is && in C/C++.

Ok, what about the English explanation for this one?

} else if(leftLightPct <10 &> rightLightPct +1){   // Bright Sun = sensor reading below 10%

}else if (leftLightPct <10 && rightSensorPct == leftSensorPct -1) {
???

Does this compile without producing fatal error messages?

else if(leftLightPct >10 &> rightLightPct +1){

As requested above, please explain your thinking (or what you are trying to accomplish), in plain English.

To be honest, was getting "rotateRight not defined" error.
posted the code to see if I had missed something.
Looks like my code was all wrong anyway..... Still learning...