Skip to content

AVR ATmega-based dual-axis solar tracker using 4 LDR sensors, 2 servo motors, and an I2C LCD with UART debugging.

Notifications You must be signed in to change notification settings

s3q/DualAxisSolarTrackingSolarPanel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Dual-Axis Solar Tracker (AVR ATmega + I2C LCD)

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.


Features

  • ✅ 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)

Hardware Requirements

  • 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

Wiring (Typical)

LDR Inputs (ADC)

  • LDR1 → ADC0
  • LDR2 → ADC1
  • LDR3 → ADC2
  • LDR4 → ADC3

Servo Outputs (Timer1)

  • Servo Azimuth → OC1A (PB1)
  • Servo Elevation→ OC1B (PB2)

I2C LCD (TWI)

  • SDA → PC4 (ATmega328P) / SDA pin (depends on MCU)
  • SCL → PC5 (ATmega328P) / SCL pin (depends on MCU)
  • LCD I2C Address: usually 0x27 or 0x3F

UART Debug (TX)

  • 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.


How It Works

  1. Read the 4 LDR values using ADC.
  2. Compute average brightness for:
    • Up vs Down
    • Left vs Right
  3. Compute errors:
    • errUD = down - up
    • errLR = right - left
  4. If the error exceeds a threshold, adjust servo angles by a small step.
  5. Clamp angles to stay within 0..180.
  6. Display values on LCD and print debug values using UART.

Project Structure

Project/
  src/
    main.c
    i2c.c
    i2c_lcd.c
  Header Files/
    i2c.h
    i2c_lcd.h

  simulation.pdsprj
  README.md

About

AVR ATmega-based dual-axis solar tracker using 4 LDR sensors, 2 servo motors, and an I2C LCD with UART debugging.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages