18 / 20
Sun-tracking solar panel
Balance two light sensors to aim a servo-mounted panel.
Run this experiment →Why it’s here
Change the sun position and compare sensor difference with panel angle.
How it works
Balance two light sensors to aim a servo-mounted panel. A small difference should not move the servo. The deadband prevents jitter near balance. This guided model targets the original ESP32 and Arduino-ESP32 3.x; radio, acoustics, loads and mechanics are simplified.
Try it
- Open this experiment
- Change the sun position and compare sensor difference with panel angle.
Connections
- GPIO 34 / 35 — Left / right LDR dividers · 3V3
- GPIO 18 — Panel servo
Example sketch
#include <ESP32Servo.h>
Servo arm;
int angle = 90;
void setup() {
arm.setPeriodHertz(50);
arm.attach(18, 500, 2400);
}
void loop() {
int left = analogRead(34), right = analogRead(35);
if (abs(left - right) > 100) angle = constrain(angle + (right > left ? 1 : -1), 0, 180);
arm.write(angle);
delay(30);
}Check your understanding
Why add a deadband?
Show the answer
A small difference should not move the servo. The deadband prevents jitter near balance.