Projects / Dual-axis solar tracker

Dual-axis solar tracker

Intermediate4 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. UNO150 lux

    Make the LDR cross

    Four LDRs with card dividers.

  2. UNO

    Wire the dividers

    Check the four readings.

  3. UNO71°SOLAR

    Mount the panel on two servos

    Free to move.

  4. UNO71°

    Power the servos separately

    Join the grounds.

  5. UNO

    Upload and test with a torch

    Move it around.

  6. UNO

    Swap signs if needed

    Until it follows.

  7. UNO

    Set the dead band

    Until it stops jittering.

In short

How do you build a dual-axis solar tracker?

Four LDRs and two servos keep a small solar panel model pointing at the light all day. You need Arduino Uno R3, LDR Photoresistor × 4, Resistor 10 kΩ × 4, MG996R metal gear servo × 2, Solar panel 6 V 1 W and 5 V 2 A USB adapter. It takes 7 steps and about 240 minutes.

Level
Intermediate
Time
About 240 min
Parts
6

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
LDR top left, 10 k to GNDUno A0Quadrant 1 (LDR from 5V to the junction)
LDR top right, 10 k to GNDUno A1Quadrant 2
LDR bottom left, 10 k to GNDUno A2Quadrant 3
LDR bottom right, 10 k to GNDUno A3Quadrant 4
Azimuth servo signalUno D9Turns left and right
Elevation servo signalUno D10Tilts up and down
Servo plus and minus5 V adapter of at least 3 A, not the Uno 5V pinServo power
Adapter minusUno GNDCommon ground

Code

Each LDR is part of a divider, so a brighter quadrant gives a higher reading. Averaging the two on each side shows which way the light comes from, and the servos nudge one degree at a time towards the brighter side until the difference falls inside a dead band, which stops them hunting back and forth. A small cross of card between the four LDRs shades them unequally and makes the signal stronger. This is a model for learning: the panel is light and only turns, and a real panel is too heavy for these servos. Power matters: an MG996R can pull over two amps when it moves or stalls, so give the servos their own 5 V supply of at least 3 A and join only the grounds, never run them from the Uno. Set the servo end limits so the panel cannot hit its frame, and keep fingers clear, as the servos are strong. The code parks at night, and if it turns the wrong way, swap the two signs. Arduino IDE, board "Arduino Uno".

Runs on a virtual Arduino Uno in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

// Dual-axis light tracker: compares four LDR quadrants and nudges two servos towards the brighter side.
// Library: Servo (built in). Board: Arduino Uno. A cross-shaped shade between the LDRs makes the difference stronger.
#include <Servo.h>
Servo az, el;
int azPos = 90, elPos = 90;
const int TOLERANCE = 40;                  // dead band, in ADC counts; raise it if the servos jitter
const int DARK = 80;                       // all four below this means night
void setup() {
  az.attach(9); el.attach(10);
  az.write(azPos); el.write(elPos);
}
void loop() {
  int tl = analogRead(A0), tr = analogRead(A1), bl = analogRead(A2), br = analogRead(A3);
  int top = (tl + tr) / 2, bottom = (bl + br) / 2, left = (tl + bl) / 2, right = (tr + br) / 2;
  if (tl < DARK && tr < DARK && bl < DARK && br < DARK) {          // night: park facing east and level
    if (azPos > 20) azPos--; if (elPos < 90) elPos++; else if (elPos > 90) elPos--;
  } else {
    if (abs(left - right) > TOLERANCE) azPos += (left > right) ? -1 : 1;     // swap the signs if it turns the wrong way
    if (abs(top - bottom) > TOLERANCE) elPos += (top > bottom) ? 1 : -1;
  }
  azPos = constrain(azPos, 10, 170); elPos = constrain(elPos, 20, 160);
  az.write(azPos); el.write(elPos);
  delay(60);                               // slow, small steps are gentler on the gears
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Torch on the leftPanel turns left
Torch abovePanel tilts up
Light steadyServos still
All coveredParks and stops

If it does not work

Servos jitter

Raise TOLERANCE and power them separately.

Turns away from the light

Swap the signs in the code.

Uno resets

Servos are on the Uno supply; use their own adapter.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the dual-axis solar tracker?

Arduino Uno R3, LDR Photoresistor × 4, Resistor 10 kΩ × 4, MG996R metal gear servo × 2, Solar panel 6 V 1 W and 5 V 2 A USB adapter.

How long does the dual-axis solar tracker take to build?

About 240 minutes for a intermediate maker, in 7 steps.

How do I know the dual-axis solar tracker works?

Torch on the left: Panel turns left. Torch above: Panel tilts up. Light steady: Servos still.

Servos jitter: what should I check?

Raise TOLERANCE and power them separately.

Turns away from the light: what should I check?

Swap the signs in the code.

Uno resets: what should I check?

Servos are on the Uno supply; use their own adapter.