# Single-axis solar tracker with two LDR sensors and a servo on Arduino: design worksheet and code

> A ₹1,394 design worksheet for a one-axis solar panel tracker that turns east to west with two LDRs and a servo, with the cosine-loss maths and an honest look at whether the tracker’s own power use cancels the gain.

Canonical: https://roboticsengineering.in/projects/single-axis-solar-tracker-ldr-servo-arduino/ | Published: 2026-11-04 | Updated: 2026-11-04

**A ₹1,394 tracker that slowly turns a small panel toward the sun. Two light sensors on either side of a shade wall tell it which way to turn, and a servo nudges the panel a degree at a time. The page works out how much light is lost when a panel is misaligned and, importantly, whether the tracker uses more power than it gains.**

**Scope:** intermediate. This is a design worksheet with illustrative costs. It has not been bench-tested by this site. The cosine table was computed by script. The tracker is a learning project. For a small panel, the control electronics and servo can use as much energy as the tracking gains, so unless the panel is large the right answer is often a fixed panel facing the right way. Panel output also depends on sunlight conditions and panel temperature, which this page does not model.

## How it works

Panel output is roughly proportional to the cosine of the angle between the sun’s rays and the panel’s normal. A panel 10 degrees off the sun still gets about 98.5 percent, 20 degrees off gets about 94 percent, 30 degrees about 86.6 percent and 45 degrees about 70.7 percent. Because the cosine falls slowly at small angles, the tracker does not need to be precise; a few degrees of error costs little.

Two LDRs in a divider each sit on one side of a thin wall. When the sun is straight ahead, the wall shades neither and the readings match. If the sun moves east or west, one LDR is shaded and the readings differ; the sketch turns the panel one degree toward the brighter one and waits. The sun moves about 15 degrees an hour, so one degree about every four minutes keeps up, and the sketch checks every 20 seconds.

## Bill of materials

| Part | Qty | Unit | Total |
| --- | --- | --- | --- |
| Arduino Uno R3 (or compatible) | 1 | ₹550 | ₹550 |
| LDR (photoresistor) | 2 | ₹15 | ₹30 |
| 10 kilohm resistors | 2 | ₹2 | ₹4 |
| Metal-gear servo (MG995 class) | 1 | ₹250 | ₹250 |
| Small solar panel, 6 V 2 W | 1 | ₹250 | ₹250 |
| Panel frame, hinge and shade wall (card or acrylic) | 1 | ₹200 | ₹200 |
| Breadboard | 1 | ₹60 | ₹60 |
| Jumper wires | 1 | ₹50 | ₹50 |
| Parts total | ₹1,394 |  |  |

Scroll the table sideways to see every column.

Prices checked Nov 2026. Shipping and tools are not included.

Prices are illustrative figures for Indian sellers in November 2026, before shipping, and have not been checked against current listings.

## The numbers

| Misalignment | Relative output |
| --- | --- |
| 10° | 98.5% |
| 20° | 94.0% |
| 30° | 86.6% |
| 45° | 70.7% |

*Relative output = cos(angle). This is a simple model and ignores reflection, atmosphere and temperature.*

Energy balance matters. An Uno on its own commonly draws tens of milliamps from 5 V, which is a fraction of a watt, and a servo draws more when it moves. A 2 W panel gaining 20 to 30 percent from tracking gains around half a watt at best in good sun, so the tracker’s own use can cancel it. Ways to cut the loss: sleep the Arduino between moves, power it from a separate small supply, and move rarely.

## Power and wiring

| Part | Connects to | Note |
| --- | --- | --- |
| Left LDR divider | A0 | LDR to 5V, 10k to GND |
| Right LDR divider | A1 | Same arrangement |
| Servo signal | D9 |  |
| Servo power | Separate 5 V supply, common GND | Do not use the Uno 5V pin for a large servo |

*Mount the LDRs on either side of a wall about as tall as the LDRs’ width, facing the same way as the panel.*

## The sketch

```
// Single-axis solar tracker: Uno + 2 LDR dividers + servo
// Design worksheet: check the tracker uses less energy than it gains.

#include <Servo.h>

const int LDR_E = A0, LDR_W = A1;
const int SERVO_PIN = 9;
const int MIN_A = 20, MAX_A = 160;
const int DEAD = 30;                    // counts treated as equal
const int DARK = 60;                    // both below this: night
const unsigned long CHECK_MS = 20000UL; // check every 20 seconds
const unsigned long NIGHT_RETURN_MS = 600000UL;   // 10 minutes of dark

Servo panel;
int angle = 90;
unsigned long darkSince = 0;

void setup() {
  panel.write(angle);
  panel.attach(SERVO_PIN);
}

void loop() {
  int e = analogRead(LDR_E);
  int w = analogRead(LDR_W);
  unsigned long now = millis();

  if (e < DARK && w < DARK) {
    if (darkSince == 0) darkSince = now;
    if (now - darkSince > NIGHT_RETURN_MS) {   // night: face east for the morning
      angle = MAX_A;
      panel.write(angle);
    }
  } else {
    darkSince = 0;
    int diff = e - w;                           // positive: east is brighter
    if (diff > DEAD && angle < MAX_A) angle++;
    else if (diff < -DEAD && angle > MIN_A) angle--;
    panel.write(angle);
  }
  delay(CHECK_MS);
}
```

The sign of the correction depends on how the LDRs and servo are mounted; if the panel turns away from the sun, swap the two LDR pins or flip the two angle changes. The servo holds position with a small current even at rest, and detaching it between moves saves power but lets the panel sag in wind. The sketch has been proofread but not compiled on this site.

## Test plan

1. **LDR check:** shade each LDR in turn and see which reading falls.
2. **Direction check:** shine a torch from one side and confirm the panel turns toward it.
3. **Dead band:** adjust DEAD so it does not hunt in even light.
4. **Outdoor test:** set it up for a sunny morning and photograph the panel angle each hour.
5. **Energy test:** measure the tracker’s current over a day and compare with the panel’s output, with the tracker on and with a fixed panel.
6. **Wind and weather:** check the mount holds in a breeze and that electronics are covered from rain.

## What usually goes wrong

| Symptom | Likely cause | Fix |
| --- | --- | --- |
| Turns away from the sun | Sensor sides or direction reversed | Swap the LDR pins or flip the steps |
| Hunts back and forth | Dead band too small | Raise DEAD |
| Cloud confuses it | Uneven cloud shades one LDR | Use a longer check time and a bigger dead band |
| Servo overheats | Constantly holding a heavy panel | Balance the panel and detach between moves |
| Net energy loss | Controller uses more than it gains | Sleep between moves or choose a fixed panel |

## Upgrades

- **Sleep mode:** use the Arduino’s sleep modes with a timer wake-up.
- **Clock-based tracking:** compute sun position from time with a real-time clock.
- **Second axis:** add a tilt axis for the seasons.
- **Measure the gain:** log the panel voltage under a fixed load.

## Cost and parts notes

The ₹1,394 total is an illustration and does not include shipping. Use the [cost calculator](https://roboticsengineering.in/robotics-project-cost-calculator/) to compare sellers.

## Common questions

**How much does tracking gain?**

It depends on the site and the panel, and claims vary. At small scale, the tracker’s own use can cancel the gain, so measure before assuming.

**Why does 10 degrees of error cost so little?**

Output follows the cosine of the angle, which is flat near zero.

**Why a shade wall?**

It makes the two LDRs see different light when the sun is off to one side.

**What happens at night?**

The sketch waits ten minutes of darkness and then faces east for the next morning.

Last reviewed: November 2026. This is a design worksheet with illustrative costs. It has not been bench-tested by this site; library names, pins and limits must be checked against your board and the current library versions, and measurements from your build are welcome.
