LM317 variable power supply
Turn a 12 V adapter into an adjustable 1.25–10 V supply for your experiments.
Shop by category
Shop all componentsTwo light sensors sit either side of a small wall on the panel edge. When the panel faces the sun both are lit; as the sun moves, the wall shades one of them, and the servo turns the panel a little towards the lit side until both are lit again. It is the simplest form of the trackers used on solar farms, and it can collect noticeably more energy than a fixed panel in the morning and evening.
Tick anything you already have and the total updates.
The brain of the project
Works with the same pins and code as the original Arduino Nano.
Light sensor on the east side of the panel: its output goes LOW when that side is in bright sun.; Light sensor on the west side of the panel: its output goes LOW when that side is in bright sun.
Small hobby servo that turns to any angle from 0 to 180° on command.
Follow the colours: red is power, dark grey is ground, blue is a signal.
solar_tracker_single_axis.inoVerify & upload in Electrolark// Single-axis solar tracker
// Geekobot project library · board: Arduino Nano
// Wiring diagram, parts list and build steps: Geekobot project page "solar-tracker-single-axis"
#include <Servo.h>
// ---- pins ----
const uint8_t LDR_EAST = 2;
const uint8_t LDR_WEST = 4;
const uint8_t SERVO_PIN = 3;
Servo servo;
// ---- latest readings ----
bool litEast = false;
bool litWest = false;
Servo tracker;
int angle = 90; // 0 = facing east, 180 = facing west
const int STEP = 2; // degrees per move
const unsigned long MOVE_EVERY_MS = 400;
unsigned long lastMove = 0;
void setup() {
Serial.begin(115200);
pinMode(LDR_EAST, INPUT);
pinMode(LDR_WEST, INPUT);
servo.attach(SERVO_PIN);
tracker.attach(SERVO_PIN);
tracker.write(angle);
}
void loop() {
if (millis() - lastMove < MOVE_EVERY_MS) return;
lastMove = millis();
litEast = digitalRead(LDR_EAST) == LOW;
litWest = digitalRead(LDR_WEST) == LOW;
// the divider between the sensors shades one of them when the panel is not facing the sun
if (litEast && !litWest) angle = max(0, angle - STEP);
else if (litWest && !litEast) angle = min(180, angle + STEP);
// both lit: facing the sun, hold. Both dark: night or cloud, hold until the sun is back
tracker.write(angle);
Serial.print(F("east ")); Serial.print(litEast); Serial.print(F(" west ")); Serial.print(litWest); Serial.print(F(" angle ")); Serial.println(angle);
}
The sketch above runs here on a simulated Arduino Nano. Move the sliders for the sensors and buttons it reads, and watch the Serial monitor, display and outputs change.
Some modules invert DO. Change == HIGH to == LOW in the code.
Power the servo from a separate 5 V supply and join the grounds; add a 470 µF capacitor across the servo supply.
Open the Serial Monitor at 115200 baud and check for messages. Make sure you chose the right board and port in the Arduino IDE.
Close other programs using the serial port, try another USB cable (some are charge-only) and press reset just before uploading.
Yes. Most of the code works unchanged on an ESP32 with the ESP32 board package. Watch for 5 V modules: ESP32 pins are 3.3 V, so 5 V output signals need a resistor divider.
Use a 5 V USB phone charger or a power bank into the board's USB port. Loads such as pumps, fans and solenoids need their own supply.
6 parts: Nano CH340 Development Board (Soldered), 2 × Digital LDR Light Sensor Module – LM393, TowerPro SG90 9g Micro Servo (180°), Solar Panel (6V), Solderless Breadboard (830 points) and Dupont Jumper Wires (40 pcs). Tools: Digital Multimeter and Wire Stripper and Cutter. On this page you can tick the parts you already have and add only the rest to your cart.
It is a intermediate project and takes about 2–3 hours. The build on this page has 10 steps.
No. This page has the complete, tested code (solar_tracker_single_axis.ino). Install this library first: Servo.
Yes. The Run it panel under the code runs this exact sketch on a simulated board. Move the sliders or press the buttons for the sensors it reads, and the Serial monitor, display and outputs react as they will on the real build. It is a simulation, so real readings depend on your parts and wiring.
About ₹575 for the parts at the prices on this page, plus tools if you do not have them. Quantity price breaks lower the cost when you build several.
PWM pulses and servo control; Thresholds set in hardware vs software.
Ideas that reuse this build: Solar panel power meter and Solar panel output in class. They are listed under Take it further on this page.
Turn a 12 V adapter into an adjustable 1.25–10 V supply for your experiments.
Build your own USB power bank and learn how lithium charging works.
Free power for outdoor sensors: sunlight in, 5 V USB out.
Beeps when the mains goes off at night, so the fridge and the alarm clock do not quietly die.
Learning project. Check every circuit and the datasheet of each part before you power it up.
east 1 west 1 angle 90 east 1 west 1 angle 90 east 1 west 1 angle 90 east 1 west 1 angle 90 east 1 west 1 angle 90 east 1 west 1 angle 90
A simulation of the sketch above, so you know what to expect. Real readings vary with your parts and wiring.