This project builds a light-following solar tracker that automatically scans for bright light sources and holds position when one is detected. Using an Arduino Uno, SG90 servo, and LM393 photoresistor module, the tracker sweeps back and forth across a 90-degree range until it finds illumination, then locks onto that direction. The guide includes a complete wiring diagram, parts list, and Arduino firmware with configurable thresholds and scan speed.
Builders will learn how to interface analog sensors with digital logic, control a servo motor with debouncing for stable readings, and implement a simple search algorithm. The project demonstrates practical applications in renewable energy monitoring, robotics, and light-responsive automation while keeping assembly straightforward enough for makers of all skill levels.
Wiring diagram
Gather all the parts
Assemble it in 5 steps
1. Prepare power safely
Power the Uno by USB. For reliable servo operation use a regulated 5 V 2 A supply, especially with a panel attached. Leave the L293, DC motors, 9 V battery and solar panel power wires disconnected.
- USB-only servo power is not reliable and can reset the Uno. Test only unloaded if using USB power temporarily; unplug if it jitters, resets or gets warm.
2. Connect one light sensor
With power disconnected, connect LDR VCC to Uno 5V, GND to GND, and DO to D2. Leave AO disconnected. Adjust the small sensor screw to set the brightness threshold. No second LDR or divider is needed.
3. Connect the servo
Connect yellow signal to D9, red to external supply positive, and brown to supply negative. Connect supply negative to Uno GND. Do not connect external supply positive to Uno 5V.
- Never force the powered servo shaft by hand. Holding the commanded angle is normal and forcing it can damage the gears.
4. Mount and allow room to scan
Test unloaded first. Mount the LDR on the moving panel facing the same direction. Support a tiny lightweight panel on a balanced pivot with clearance from 45 to 135 degrees. The servo starts at 90 degrees. In darkness it sweeps back and forth from 45 to 135 degrees; when sufficient light is detected it holds its current angle. It resumes sweeping when light disappears.
5. Set the light threshold
Turn the module adjustment screw until the DO indicator turns on at your desired brightness. With DO connected to D2, uncover the sensor to check that the servo holds, then shade it to check that sweeping resumes. Most LM393 modules output LOW with the DO LED on. If yours behaves backwards, change LIGHT_PRESENT_LEVEL from LOW to HIGH and Deploy again.
- This stops at the first sufficiently bright position, not necessarily the brightest one. Mount the LDR on the moving panel; a stationary LDR cannot follow direction.
- The SG90 is a positional servo, not a continuously rotating motor. Never force its arm by hand.
- This is an indoor one-axis demonstration, not a weatherproof or self-powered installation.
Review all connections
1. Connections between "left" and "Arduino"
2. Connections between "servo" and "Arduino"
3. Connections between "supply" and "Arduino"
Deploy the firmware
#include <Arduino.h>
#include <Servo.h>
constexpr uint8_t LIGHT_PIN = 2;
constexpr uint8_t SERVO_PIN = 9;
// Most LM393 boards pull DO LOW when their threshold LED is on.
// Change to HIGH if your module behaves in reverse.
constexpr uint8_t LIGHT_PRESENT_LEVEL = LOW;
constexpr int MIN_ANGLE = 45;
constexpr int MAX_ANGLE = 135;
constexpr unsigned long STEP_MS = 35;
constexpr unsigned long DEBOUNCE_MS = 100;
Servo tracker;
int angle = 90;
int direction = 1;
bool candidateLight = false;
bool lightPresent = false;
unsigned long candidateSince = 0;
unsigned long lastStep = 0;
void setup() {
pinMode(LIGHT_PIN, INPUT_PULLUP);
candidateLight = lightPresent = digitalRead(LIGHT_PIN) == LIGHT_PRESENT_LEVEL;
candidateSince = millis();
tracker.attach(SERVO_PIN, 1000, 2000);
tracker.write(angle);
}
void loop() {
const unsigned long now = millis();
const bool reading = digitalRead(LIGHT_PIN) == LIGHT_PRESENT_LEVEL;
if (reading != candidateLight) {
candidateLight = reading;
candidateSince = now;
}
if (now - candidateSince >= DEBOUNCE_MS) lightPresent = candidateLight;
if (lightPresent) {
lastStep = now;
return; // Keep sending the same position: hold, don't release the servo.
}
if (now - lastStep < STEP_MS) return;
lastStep = now;
if (angle >= MAX_ANGLE) direction = -1;
if (angle <= MIN_ANGLE) direction = 1;
angle += direction;
tracker.write(angle);
}Remix this project
Make it yours in one click
Open a full copy of this project in your own Schematik workspace, diagram, code, parts, and assembly steps included. Swap the sensor, add features, or redesign the whole thing with AI. The author's original stays untouched.




