Arduino-Based Dual Axis Solar Tracker for Solar Panel

I am a graduating student and I badly need your help regarding my project which is an arduino-based dual-axis solar tracker or solar panel. I have simulated my circuit and code in Proteus and it worked but when I implemented the project, I couldn’t get it to work. I don’t really know what’s wrong. Maybe you can critique my program or circuit. Please help me guys.

Here’s the code:
#include <Servo.h>
Servo myservo;
int pos = 90;
int ldr1 = A0;
int ldr2 = A1;
int tolerance = 2;

Servo myservo2;
int pos2 = 90;
int ldr3 = A2;
int ldr4 = A3;
int tolerance2 = 2;

void setup()
{
myservo.attach(9);
pinMode(ldr1, INPUT);
pinMode(ldr2, INPUT); //
myservo.write(pos);
delay(2000);

myservo2.attach(10);
pinMode(ldr3, INPUT);
pinMode(ldr4, INPUT);
myservo2.write(pos2);
delay(2000);
}
void loop()
{
int val1 = analogRead(ldr1);
int val2 = analogRead(ldr2);
int val3 = analogRead(ldr3);
int val4 = analogRead(ldr4);

if((abs(val1 - val2) <= tolerance) || (abs(val2 - val1) <= tolerance)) {
} else {
if(val1 > val2)
{
pos = pos+1; }
if(val1 < val2)
{
pos = pos-1;
}
delay(900);
}
if(pos > 180) { pos = 178; }
if(pos < 0) { pos = 0; }
myservo.write(pos);
delay(50);

if((abs(val3 - val4) <= tolerance) || (abs(val4 - val3) <= tolerance)) {
} else {
if(val3 > val4)
{
pos2 = pos2+1;
}
if(val4 > val3)
{
pos2 = pos2-1;
}
delay(900);
}

if(pos2 > 180) { pos2 = 178; }
if(pos2 < 0) { pos2 = 0; }
myservo2.write(pos2);
delay(50);
}

"It doesn't work" was a waste of your time typing, and of our time reading that useless bit of "news".

The code does something. You expect it to do something. You failed to tell us what either of them are.

  if((abs(val3 - val4) <= tolerance) || (abs(val4 - val3) <= tolerance)) {

I would expect someone that was planning to graduate soon to understand what the abs() function does. You haven’t a clue, obviously.

PaulS:

  if((abs(val3 - val4) <= tolerance) || (abs(val4 - val3) <= tolerance)) {

I would expect someone that was planning to graduate soon to understand what the abs() function does. You haven’t a clue, obviously.

I don’t see how you reach that conclusion based on the piece you quoted

…R

Robin2:
I don’t see how you reach that conclusion based on the piece you quoted

…R

How does the absolute value of val3 - val4 differ from the absolute value of val4 - val3?

PaulS:
How does the absolute value of val3 - val4 differ from the absolute value of val4 - val3?

Ahhh ... I missed that.

...R

PaulS:
“It doesn’t work” was a waste of your time typing, and of our time reading that useless bit of “news”.

The code does something. You expect it to do something. You failed to tell us what either of them are.

Neither of the two servo motors move. Is it possible for arduino to supply two 5-volt motors?

rhidjel:
Neither of the two servo motors move. Is it possible for arduino to supply two 5-volt motors?

You should not power even a single motor from the Arduino 5v pin - it cannot provide enough current and trying to draw too much current may damage your Arduino.

Give the motors their own power supply with the motor GND connected to the Arduino GND.

...R