Hello everyone, I am working on a solar tracker project and I used four LDR sensors to detect the direction of the sunlight. since the set up is very big, I connect the four LDRs sensors with their resistors 10K to wires around 3 meters long to the Arduino Uno board.
The problem is that only the LDR connected to A0 pin show logical results of reading, every time I sweep between the wires on the analog pins, only A0 read correctly.
![]()
Here is the code - notice is not complete for the whole project - yet I need to check the reading of LDRs first.
#include <Servo.h> // include Servo library
#include <AccelStepper.h> // inlcude stepper library
int actuator1 = 15; //int = integer , float =
int actuator2 = 16;
int actuator3 = 17;
int actuator4 = 18;
Servo servo_SolarTracker; // servo to move the solar tracker
int servo_angle = 0; // start at 0 degree
int servoLimitHigh = 180;
int servoLimitLow = 0;
AccelStepper stepper1(1, 2, 5); //pin 2 for controling steps and 5 for direction of stepper 1
AccelStepper stepper2(1, 3, 6); //pin 3 for controlling steps and 6 for direction of stepper 2
void setup()
{
Serial.begin(9600); //only for testing
pinMode(actuator1,OUTPUT);
pinMode(actuator2,OUTPUT);
pinMode(actuator3,OUTPUT);
pinMode(actuator4,OUTPUT);
servo_SolarTracker.attach(9); //attach servo signal to pin 9 in Arduino
servo_SolarTracker.write(0); // move servo to 0 degree at first
delay(3000); // wait for 3 seconds
stepper1.setMaxSpeed(100); // set max speed of stepper1 motors
stepper2.setMaxSpeed(100); // set max speed of stepper2 motors
}
void loop()
{
int tol = 35; //tolerance
int lt = analogRead(A0); // top left
int rt = analogRead(A1); // top right
int ld = analogRead(A2); // down left
int rd = analogRead(A3); // down rigt
Serial.println(lt); //only for testing
Serial.println(rt);
Serial.println(ld);
Serial.println(rd);
int av_sunrise = (lt + ld) / 2; // average value sunrise
int avr_sunset = (rt + rd) / 2; // average value sunset
int diff = av_sunrise - avr_sunset;// check the diffirence of left and rigt
//Serial.print(av_top); //only for testing
//Serial.print(av_down);
//Serial.print(av_sunrise);
//Serial.print(avr_sunset);
//Serial.print(diff);
if (diff > tol) // check if the diffirence is in the tolerance else change vertical angle
{
servo_angle = ++servo_angle;
if (servo_angle > servoLimitHigh)
{
servo_angle = servoLimitHigh;
}
servo_SolarTracker.write(servo_angle);
}
delay(500);
}

