Projects / Light-tracking turret

Light-tracking turret

Beginner1.5 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. NANO754 lux

    Build the divider

    Wire the four LDRs and resistors and print the four values.

  2. NANO

    Check the pattern

    Cover one sensor and see its value change.

  3. NANO

    Fit the baffle

    Add the cross between the sensors.

  4. NANO33°

    Add the servos

    Power them from the separate supply.

  5. NANO

    Upload

    Shine a torch and watch the turret turn.

  6. NANO

    Fix the directions

    Flip the signs if it turns the wrong way.

  7. NANO

    Tune the dead band

    Raise DEAD if it jitters and lower it if it is lazy.

In short

How do you build a light-tracking turret?

A pan-tilt turret points a pointer or small camera at the brightest light. You need Arduino Nano, LDR Photoresistor × 4, Resistor 10 kΩ × 4, Servo pan-tilt bracket (SG90), 5 V 2 A USB adapter, Electrolytic Capacitor 100 µF, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 7 steps and about 90 minutes.

Level
Beginner
Time
About 90 min
Parts
8

Parts list

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

Wiring

FromToWhy
LDR top-left5V and Nano A0, with 10 kΩ from A0 to GNDDivider 1
LDR top-right5V and Nano A1, with 10 kΩ from A1 to GNDDivider 2
LDR bottom-left5V and Nano A2, with 10 kΩ from A2 to GNDDivider 3
LDR bottom-right5V and Nano A3, with 10 kΩ from A3 to GNDDivider 4
Pan servo signalNano D9Left and right
Tilt servo signalNano D10Up and down
Both servo red wires5 V adapter +Servo power, not the Nano 5V
Both servo brown wires5 V adapter - and Nano GNDCommon ground
100 µF capacitorAcross the servo supply near the servosAbsorbs surges

Code

Mount the four light sensors in a square on the front of the turret with a cross of card or thin plastic between them, so that each sees more light when the lamp is on its side. Light over the left pair makes the turret turn left; flip the signs in the code if it turns away instead. The dead band stops it hunting when the light is centred. Power the servos from a separate 5 V adapter and share the ground with the Nano; two servos can pull enough current to reset the Nano if taken from its pin. Put a small camera, a pointer made of card or a lamp on the head. Do not mount a laser pointer, because a stray beam can harm eyes. Arduino IDE, board "Arduino Nano" (processor ATmega328P, or ATmega328P (Old Bootloader) for clones).

Runs on a virtual Arduino Nano 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).

// Four LDRs in a 2 by 2 square, a baffle cross between them, and two servos.
#include <Servo.h>

Servo pan, tilt;
int panPos = 90, tiltPos = 90;
const int DEAD = 25;           // ignore small differences (dead band)
const int STEP = 1;            // degrees per move

void setup() {
  pan.attach(9); tilt.attach(10);
  pan.write(panPos); tilt.write(tiltPos);
  Serial.begin(9600);
}

void loop() {
  int tl = analogRead(A0), tr = analogRead(A1), bl = analogRead(A2), br = analogRead(A3);
  int top = tl + tr, bottom = bl + br, left = tl + bl, right = tr + br;

  if (abs(left - right) > DEAD) panPos += (left > right) ? -STEP : STEP;     // flip signs if it runs away
  if (abs(top - bottom) > DEAD) tiltPos += (top > bottom) ? STEP : -STEP;
  panPos = constrain(panPos, 10, 170);
  tiltPos = constrain(tiltPos, 30, 150);
  pan.write(panPos); tilt.write(tiltPos);

  Serial.print(tl); Serial.print(' '); Serial.print(tr); Serial.print(' ');
  Serial.print(bl); Serial.print(' '); Serial.println(br);
  delay(15);
}

What the serial monitor should show

Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Nano with its sensors at their default values. Your numbers will follow your real readings, but the format should match.

512 513 512 512
513 512 512 512
512 512 511 511
512 511 512 511
511 512 512 511
512 512 512 513

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 leftTurret turns left
Torch aboveTurret tilts up
Light centredTurret rests
Moving the torchTurret follows

If it does not work

Turns away from the light

Flip the signs for that axis.

Jitters

Raise DEAD and check the supply capacitor.

Nano resets

Power the servos separately.

Hits end stops

Adjust the constrain limits.

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

Ask Lark AI

Common questions

What parts do I need for the light-tracking turret?

Arduino Nano, LDR Photoresistor × 4, Resistor 10 kΩ × 4, Servo pan-tilt bracket (SG90), 5 V 2 A USB adapter, Electrolytic Capacitor 100 µF, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).

How long does the light-tracking turret take to build?

About 90 minutes for a beginner maker, in 7 steps.

How do I know the light-tracking turret works?

Torch on the left: Turret turns left. Torch above: Turret tilts up. Light centred: Turret rests.

Turns away from the light: what should I check?

Flip the signs for that axis.

Jitters: what should I check?

Raise DEAD and check the supply capacitor.

Nano resets: what should I check?

Power the servos separately.

Hits end stops: what should I check?

Adjust the constrain limits.