Build it step by step
0 of 7 doneBuild the divider
Wire the four LDRs and resistors and print the four values.
Check the pattern
Cover one sensor and see its value change.
Fit the baffle
Add the cross between the sensors.
Add the servos
Power them from the separate supply.
Upload
Shine a torch and watch the turret turn.
Fix the directions
Flip the signs if it turns the wrong way.
Tune the dead band
Raise DEAD if it jitters and lower it if it is lazy.
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
- Development BoardsBuyArduino Nano × 1
- SensorsBuy
- PassivesBuyResistor 10 kΩ × 4
- Motors & ActuatorsBuy
- PowerBuy
- PassivesBuy
- PrototypingBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| LDR top-left | 5V and Nano A0, with 10 kΩ from A0 to GND | Divider 1 |
| LDR top-right | 5V and Nano A1, with 10 kΩ from A1 to GND | Divider 2 |
| LDR bottom-left | 5V and Nano A2, with 10 kΩ from A2 to GND | Divider 3 |
| LDR bottom-right | 5V and Nano A3, with 10 kΩ from A3 to GND | Divider 4 |
| Pan servo signal | Nano D9 | Left and right |
| Tilt servo signal | Nano D10 | Up and down |
| Both servo red wires | 5 V adapter + | Servo power, not the Nano 5V |
| Both servo brown wires | 5 V adapter - and Nano GND | Common ground |
| 100 µF capacitor | Across the servo supply near the servos | Absorbs 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.
| Check | Expected |
|---|---|
| Torch on the left | Turret turns left |
| Torch above | Turret tilts up |
| Light centred | Turret rests |
| Moving the torch | Turret 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 →
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.
