This project implements a dual-axis solar tracker using an AVR ATmega microcontroller.
It reads four LDR sensors (via ADC), calculates light intensity differences, and drives two servo motors
(azimuth + elevation) to align a solar panel (or any platform) toward the strongest light source.
An I2C LCD (HD44780 + PCF8574 backpack) is used to display sensor values and tracking information, and UART prints debug logs to a serial monitor.
- ✅ Dual-axis tracking (Azimuth + Elevation)
- ✅ 4× LDR sensors read using ADC channels
- ✅ Servo control using Timer1 PWM (50Hz)
- ✅ I2C LCD driver (PCF8574 backpack)
- ✅ LCD page switching (example: show sensors on page 1, angles/PWM on page 2)
- ✅ UART debug output (9600 baud)
- AVR ATmega MCU (example: ATmega8 / ATmega328P)
- 4× LDR sensors + voltage divider resistors
- 2× servo motors (SG90 / SG5010, etc.)
- I2C LCD module (16x2 or 20x4) with PCF8574 backpack
- External 5V supply for servos (recommended)
- Common ground between MCU and servo supply
- LDR1 → ADC0
- LDR2 → ADC1
- LDR3 → ADC2
- LDR4 → ADC3
- Servo Azimuth → OC1A (PB1)
- Servo Elevation→ OC1B (PB2)
- SDA → PC4 (ATmega328P) / SDA pin (depends on MCU)
- SCL → PC5 (ATmega328P) / SCL pin (depends on MCU)
- LCD I2C Address: usually
0x27or0x3F
- TX → UART RX of USB-to-TTL adapter (9600 baud)
⚠️ Servos can draw high current. Power them from a separate 5V supply and connect GND together.
- Read the 4 LDR values using ADC.
- Compute average brightness for:
- Up vs Down
- Left vs Right
- Compute errors:
errUD = down - uperrLR = right - left
- If the error exceeds a threshold, adjust servo angles by a small step.
- Clamp angles to stay within
0..180. - Display values on LCD and print debug values using UART.
Project/
src/
main.c
i2c.c
i2c_lcd.c
Header Files/
i2c.h
i2c_lcd.h
simulation.pdsprj
README.md