Sief AliEmbedded & Full-Stack
Back to Projects
Embedded Systems & RoboticsCompleted

SPST — Solar Panel Sun Tracker

FreeRTOS-driven dual-axis sun tracking firmware on ATmega32 with sensor fault protection

SimulIDE Circuit & Peripheral SchematicATmega32 Wiring
SPST — Solar Panel Sun Tracker Circuit Diagram
Hardware & Peripheral Allocation
Microcontroller:ATmega32 (8-bit AVR RISC)
Architecture Pattern:Layered Driver Stack + FreeRTOS Preemptive Tasks
Simulation Environment:SimulIDE v1.1 circuit with simulated LDR voltage dividers and servo response
Peripheral & Pin Allocation:
  • ▹ADC (10-bit differential sampling for LDRs)
  • ▹Timer1 (16-bit Fast PWM for Servo control)
  • ▹USART (System telemetry and state logging)
  • ▹GPIO (Status LEDs and limit feedback)

Technical Overview

Solar Panel Sun Tracker (SPST) is an embedded firmware application created for the Digital Egypt Cubs Initiative (DECI) Level 5. The project simulates an automated solar panel tracker on an ATmega32 microcontroller. Rather than simply driving a servo based on raw sensor thresholds, SPST is engineered with a strict layered architecture: separating low-level register manipulation (MCAL) from device peripherals (HAL) and high-level tracking logic (App). The firmware uses FreeRTOS tasks to concurrently handle sensor sampling, position calculation, fault detection, and telemetry without blocking the microcontroller or missing real-time deadlines.

Engineering Decisions & Rationale

Why the system is structured this way rather than standard simplifications.

1.Layered MCAL and HAL Abstraction

Register writes to ADMUX, ADCSRA, and TCCR1A are encapsulated inside MCAL drivers. High-level tracking logic operates purely on abstract sensor lux readings and degree angles, allowing the firmware to be ported or simulated without changing business logic.

2.Hysteresis Deadbands & Cloud Hold Logic

Small illumination fluctuations often cause continuous servo jitter, wearing out mechanical actuators. SPST enforces a configurable ADC deadband and detects cloud cover (diffuse light where both LDRs drop below a threshold), freezing servo orientation until direct sunlight returns.

3.Fault Tolerant State Machine

If either LDR produces an out-of-bounds voltage (indicating a broken wire or shorted sensor), the system triggers a fault state, illuminates a diagnostic LED, logs the anomaly over UART, and locks the panel in a safe position.

Key Technical Highlights

  • Layered MCAL (Microcontroller Abstraction Layer) and HAL (Hardware Abstraction Layer) architecture
  • Differential dual-LDR light tracking with hysteresis deadbands to eliminate servo jitter
  • Autonomous night parking: parks the solar panel at east-facing baseline upon prolonged darkness
  • Cloud detection and hold behavior to avoid erratic hunting under overcast skies
  • Sensor fault diagnosis detecting disconnected or shorted LDRs with safe fallback states
  • UART diagnostic telemetry streaming real-time tracking states at 9600 baud (8N1)
Technologies Used
Embedded CFreeRTOSATmega32SimulIDECMakeAVR-GCCMCAL/HALUART