sun tracker using two dc motor

hey guys,
i have two dc actuators and two H-bridge and arduino and 4 LDRs
i wrote a code to control a panel forward sun, but my supervisor of my project want me to write it on a fuzzy or PID way
please help me to write this code. or to find a way that help me to write it
this is my old simple code :

i wrote it for one actuator

int lightPin = A0; //define a pin for Photo resistor
int lightPin2 = A1; //define a pin 1 for Photo resistor 2
const int Motor1Pin1 = 2; // H bridge (b1)
const int Motor1Pin2 = 4; // (b2)
void setup()
{
Serial.begin(9600); //Begin serial communcation
pinMode(Motor1Pin1, OUTPUT);
pinMode(Motor1Pin2, OUTPUT);

}

void loop()
{
Serial.println(analogRead(lightPin));
Serial.println(analogRead(lightPin2));

if ( analogRead(lightPin)- analogRead(lightPin2)>100 )
{
digitalWrite(Motor1Pin2, LOW);
digitalWrite(Motor1Pin1, HIGH);
Serial.println("right");
}
else if (analogRead(lightPin2)- analogRead(lightPin)>100)
{
digitalWrite(Motor1Pin1, LOW);
digitalWrite(Motor1Pin2, HIGH);
Serial.println("left");
}
else
{digitalWrite(Motor1Pin2, LOW);
digitalWrite(Motor1Pin1, LOW);
}
//delay(250); //short delay for faster response to light.
Serial.println("------------------------------------");
}

Do you understand what your supervisor means by "a fuzzy or PID way"?

I can't imagine why any complicated code is needed for this project. In principal it only requires

while left LDR is darker move motor a little towards the right LDR

and vice versa.

20 or 30 lines of code?

Its not as if the sun moves quickly or erratically.

...R

Hi, I don't think the sun moves fast enough for PID to be effective, or to even check if it is functioning properly.

Strange supervisor, moving the goal posts after you have started the project.

Tom...... :slight_smile: