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