Designing a solar tracking system with 4 LDR, 1 stepper motor and 1 servo motor

Hi,

Currently i am working on a project on solar tracking system.

The main components:
4 x light dependent sensors (LDR),
1 x stepper motor, 5V Stepper Motor w/ULN2003 Driver,
1 x servo motor,
1 x micro controller, ARDUINO UNO,

The stepper motor is used to track the vertical movement; zenith angle which is at the base and the servo motor is used to track the horizontal movement; elevation angle at the solar panel.
There is a 9V battery to power the stepper motor.

When the code was uploaded into ARDUINO UNO, nothing happen. Tried covering the LDRs but there were no rotation of the stepper or the servo motor.

I have checked my LDRs with a multimeter and they were in working condition.
The motors were tested with a similar program without the use of LDRs and they were working as well.

May i know what am i missing in the code as the compiler did not show any error. I have use references from other sources.

There is a image of the circuit connection.

Some help will be much appreciated.

#include <Servo.h>
Servo Hservo; // servo at pv
int Horizontal = 0; // set to home position

#include <Stepper.h>
const int stepsPerRevolution = 512;
Stepper Vstepper(stepsPerRevolution, 8, 9, 10, 11);

// LDR
// name = analogpin;
int topleft= 3; // (red)
int bottomleft = 5; // (Blue)
int topright = 2; // (Green)
int bottomright= 4; // (Yellow)

void setup()
{
  Serial.begin(9600); //initialize serial port
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  Vstepper.setSpeed(40); // setting the speed of stepper 
  Hservo.attach(12); // servo at pin 12  
}
void loop()
{
int tl = analogRead(topleft);
int tr = analogRead(topright);
int bl = analogRead(bottomleft);
int br = analogRead(bottomright);
int delayt = 25;
int sensitivity = 100;
int avgl = (tl + bl) / 2;
int avgr = (tr + br) / 2;
int avgt = (tl + tr) / 2;
int avgb = (bl + br) / 2;
int diffv = avgl - avgr; //diff between left n right
int diffh = avgt - avgb; //diff between top n bottom

if (-1* sensitivity > diffv || diffv > sensitivity) // check for difference in sensitivity
{
if (avgl > avgr) // if average left is greater than average right
{
Vstepper.step(stepsPerRevolution);
}
else // if the average left is smaller than average right
{
Vstepper.step(-stepsPerRevolution);
}
}

else if (-1* sensitivity < diffv || diffv < sensitivity)
{
Vstepper.step(0);
}

if (-1*sensitivity > diffh || diffh > sensitivity)
{
if (avgt > avgb)
{
Horizontal = -- Horizontal;
if (Horizontal < 0)
{
Horizontal = 0;
}
}

else if (avgt < avgb)
{
Horizontal = ++ Horizontal;
if (Horizontal > 180)
{
Horizontal = 180;
}
}
else if (avgt == avgb)
{
  //nothing
}
Hservo.write(Horizontal);
}
delay(delayt);
}

Full page photo.pdf (754 KB)

First, solve the motor power supply problems.

The small, rectangular PP3 9V batteries are for smoke alarms and are useless for motors.

Never attempt to power a motor or servo from the Arduino +5V, as that will either interfere with the Arduino function, or even destroy it.

Use a separate power supply for both, and connect the grounds together.

hi i want to make a solar trucker with bipolar stepper motor and tb6560 driver i can't find any code about this any one can help me??

You can try to adjust this project - https://www.instructables.com/id/DIY-Miniature-Solar-Tracker/

Hi..can i request the your diagram or circuit connection .. I cant understand the image that you post..tnx