An Arduino Nano–based dual-LDR solar tracker that sweeps a servo motor across a 120° arc to lock onto the brightest light source, paired with a real-time Python dashboard that streams and visualizes live telemetry from the device.
This project combines embedded hardware control with real-time data visualization. An Arduino Nano reads two LDR (light-dependent resistor) sensors and drives a servo motor to continuously orient toward the strongest light source. A companion Python script connects over serial, parses the telemetry stream, and renders a live scrolling graph with sensor state, servo angle, movement direction, and tracking stability.
Two LDRs are mounted on opposite sides of the servo arm. On each loop iteration, the Arduino reads both sensors and applies the following logic:
| Left LDR | Right LDR | Action |
|---|---|---|
| BRIGHT | DARK | Step servo left (−5°) |
| DARK | BRIGHT | Step servo right (+5°) |
| BRIGHT | BRIGHT | Nudge toward center (90°) |
| DARK | DARK | Hold current position |
The servo is constrained between 30° and 150°, providing a 120° tracking arc. Each step is 5°, and the control loop runs with an 80 ms delay.
After every iteration, the Arduino transmits a comma-separated telemetry line over Serial at 9600 baud:
<left>,<right>,<angle>
The Python dashboard reads this stream, parses each frame, and updates a rolling 100-sample live graph at approximately 20 Hz.
| Component | Specification |
|---|---|
| Microcontroller | Arduino Nano |
| Light Sensors | 2× LDR module (digital, active-low) |
| Actuator | Servo motor (standard, 5V) |
| Misc | Breadboard, jumper wires |
| Arduino Pin | Connected To |
|---|---|
D2 |
Left LDR output |
D3 |
Right LDR output |
D9 |
Servo signal |
5V |
LDR and servo VCC |
GND |
LDR and servo GND |
Note: The LDR modules used here output
LOWwhen light is detected (active-low). The firmware inverts these readings internally so that1consistently means bright and0means dark throughout the codebase and telemetry stream.
File: solar_tracker.ino
Written in C++ using the Arduino Servo library (built-in — no additional installation required). On each loop cycle the firmware:
- Reads both LDR pins via
digitalRead. - Inverts the active-low signals for logical consistency.
- Applies the four-case tracking logic to compute the new servo angle.
- Clamps the angle to the [30°, 150°] range using
constrain. - Writes the updated angle to the servo.
- Transmits
left,right,angleover Serial at 9600 baud.
File: solar_dashboard.py
| Library | Purpose |
|---|---|
pyserial |
Serial communication with the Arduino |
matplotlib |
Live plot rendering via plt.pause() animation |
collections.deque |
Efficient fixed-length rolling window for data |
The dashboard maintains a rolling window of the last 100 angle samples and refreshes the plot every ~50 ms. The figure title bar displays a live summary:
Left: BRIGHT | Right: DARK | Angle: 75° | Dir: LEFT | Stability: 84.3%
Stability is calculated as the percentage of samples where the servo angle did not change — a proxy for how well the tracker has locked onto a stable light source.
Open solar_tracker.ino in the Arduino IDE and upload it to your Nano. The only dependency is the built-in Servo.h library — no Library Manager installation is needed.
pip install -r requirements.txtEdit the PORT constant at the top of solar_dashboard.py to match the port your Arduino is connected to:
# Linux
PORT = "/dev/ttyACM0"
# macOS
PORT = "/dev/cu.usbmodem14101" # port name varies — check Arduino IDE
# Windows
PORT = "COM3"You can find the correct port in the Arduino IDE under Tools → Port.
Ensure the Arduino is connected, then run:
python solar_dashboard.pyA dark-themed Matplotlib window will appear and begin plotting live servo angle data. Press Ctrl+C in the terminal to stop.
Solar-Tracker-with-Python-Dashboard/
├── solar_tracker.ino # Arduino firmware (C++)
├── solar_dashboard.py # Real-time Python dashboard
├── requirements.txt # Python dependencies
├── LICENSE
├── .gitignore
└── README.md
This project is licensed under the terms of the LICENSE file included in this repository.