Hi friends
I know that most of us around here are too good at arduino programming but I am a newbie, and just started working with it. I have worked on some of simple projects, but I am now struck with one of my actual project (for which I started with arduino), the Solar Alignment platform for PV Cells.
I have a very simple configuration, using an Arduino UNO board with a Motor Driver Controller L298D, that controls 2 powerful high torque motor (Not servo but Geared Motors). My light sensor is a voltage divider made of 4 LDR’s, that send signals to 4 analog inputs. I coded most of the part to align the face of LDR’s to exact location of the light source but I am having a hard time now making a bug get fixed . Basically, each motor works individually fine but actually as they don’t know the other motor’s position; so as soon as one motor gets to the point where arduino told it to be, the other motor changes the position of the platform completely so they never seem to get aligned to the light source.
It’s quite similar to the what Geo Bruce did here http://www.instructables.com/id/Arduino-Solar-Tracker/, just the difference is that I am using a motor driver with Geared Motors, instead if Servo Motors, means I cant use the Servo.h for it.
|
O | O
O | O
|
The design of the Sensor is like this, LDR’s starting from the Top Left > Top Right > Bottom Left > Bottom Right are marked as a0, a1, a2, a3 respectively
Here is my Code:
//MOTOR 1
int ENA=7;//connected to Arduino's port D7
int IN1=5;//connected to Arduino's port D5
int IN2=3;//connected to Arduino's port D3
//MOTOR 2
int ENB=13;//connected to Arduino's port D13
int IN3=11;//connected to Arduino's port D11
int IN4=9;//connected to Arduino's port D9
int sensitivity = 0; // Used to set the sensitivity of the LDR's
void setup()
{
Â
 Serial.begin(9600);
Â
pinMode(ENA,OUTPUT);
pinMode(ENB,OUTPUT);
pinMode(IN1,OUTPUT);
pinMode(IN2,OUTPUT);
pinMode(IN3,OUTPUT);
pinMode(IN4,OUTPUT);
//CODE FOR INIT MOTOR 2
digitalWrite(ENB,HIGH);
digitalWrite(IN3,LOW);
digitalWrite(IN4,LOW);
 //CODE FOR INIT MOTOR 1
digitalWrite(ENA,HIGH);
digitalWrite(IN1,LOW);
digitalWrite(IN2,LOW);
}
void loop()
{
 int a0 = analogRead(A0);
 int a1 = analogRead(A1);
 int a2 = analogRead(A2);
 int a3 = analogRead(A3);
Â
 int a01 = a0+a1;
 int a23 = a2+a3;
 int a12 = a1+a2;
 int a03 = a0+a3;
Â
 Â
 if(a01-a23 > sensitivity || a01-a23 < -sensitivity)// vertical adjustment
 {
  if(a01<a23)
  {
  digitalWrite(IN3,HIGH);
  digitalWrite(IN4,LOW);//Setting Motor 2's Direction clock-wise
  }
  else if(a01>a23)
  {
   digitalWrite(IN3,LOW);
  digitalWrite(IN4,HIGH);//Setting Motor 2's Direction anticlock-wise
  }
 }
 else
 {
  digitalWrite(IN3,LOW);
  digitalWrite(IN4,LOW);//Stop Motor 2
 }
Â
 if(a12-a03 > sensitivity || a12-a03 < -sensitivity)// horizontal adjustment
 {
  if(a12<a03)
  {
digitalWrite(IN1,HIGH);
digitalWrite(IN2,LOW);//Setting Motor 1's Direction clock-wise
  }
  else if(a12>a03)
  {
   digitalWrite(IN1,LOW);
   digitalWrite(IN2,HIGH);//Setting Motor 1's Direction anticlock-wise
  }
 }
 else
 {
digitalWrite(IN1,LOW);
digitalWrite(IN2,LOW);//Stop Motor 1
 }
}