Solar Tracking System using Pic Microcontroller

The article explores a solar tracking system using a PIC microcontroller. Readers will gain an understanding of what a solar tracking system is, the necessity for such a system, the current methods in use, the process of designing a solar tracking system, a circuit diagram, and writing code for a solar tracking system using a PIC microcontroller. The journey begins with a basic introduction to a solar tracking system.

What is a Solar Tracking System?

A solar tracking system is a method to extract maximum power from solar panels. As we know, solar panels convert solar energy into electrical energy through the photovoltaic phenomenon. The greater the intensity of solar light that falls on the solar panel, the greater output is observed at the output of the solar panel. So, we need to develop a method that rotates the solar panel according to the sun’s tracking, so that we can extract maximum power from our installed solar panels.

Solar tracking systems are important due to their ability to maximize the exposure of solar panels to sunlight, thereby increasing power generation. Researchers have devised numerous methods for solar tracking systems, but this article will focus on two popular approaches. It will explore these methods in detail to provide a comprehensive understanding of solar tracking technologies.

  • Sun solar tracking system
  • Time solar tracking system

Sun Solar Tracking System

In this method, we rotate the solar panel with the help of a stepper motor in the direction of sunlight. The main purpose is to expose the solar panel to the maximum sunlight. The greater the sunlight, the greater the output of the solar panel. A stepper motor is used to rotate the solar panels in the direction of sunlight. In this method, two light sensors are used to measure sunlight. A light-dependent resistor (LDR) and a photodiode are both used for this purpose.

Time solar tracking system

This method is basically an enhancement of sun solar tracking system. In this advanced method of Solar tracking system, time is also involved for the rotation of solar panels according to sunlight direction. A real-time clock is used to keep information of real-time during the day. With the help of a real-time clock and microcontroller, the Solar tracking system turns off automatically in nighttime. The real-time clock uses time information during the day and season. Season information is also used to keep an idea about the rotation of the sun. With the help of this information, solar panels rotate according to the sun’s rotation.

In this article, We explain the concept of sun solar tracking systems. Such systems encompass the utilization of both hardware and software to develop a comprehensive project. The primary components of a solar tracking system are outlined below:


  • Solar panel
  • Stepper motor
  • ULN2003
  • 5-volt power supply
  • PIC16F877A microcontroller
  • Oscillator
  • Resistors
  • Capacitors
  • Light dependent resistor

Power supply

5 5-volt power supply is required to power ULN2003 and microcontroller. One can easily design a 5-volt power supply using a step-down transformer 220V / 12V AC. The step-down voltage is fed to a full bridge (full-wave rectification). After that, a polar capacitor is used to remove AC ripples from the output. After that, a 7805 voltage regulator is used to get regulated 5-volt output. This 5-volt output can be used for a power source to the PIC16F877A microcontroller and ULN2003. The circuit diagram of the 5-volt power supply is given below:

5 volt power supply using 7805
5-volt power supply using 7805

you may also read this article to design a power supply:

Sun Solar Tracking System Working

In this method, two light-dependent resistors are used. LDRs are separated with the help of a sheet (metallic sheet or wood shield). One on the left-hand side of the sheet and the other on the right-hand side of the shield. This is the main part of this project. Two light-dependent resistors measure the intensity of light with the help of a microcontroller. Now the question comes to mind: how do these light-dependent resistors rotate solar panels with the help of the solar panel? I will explain it later. If you don’t know how to measure the intensity of light using the PIC16F877A microcontroller, check the following article:

After reading the above article, I trust you now understand how to measure light intensity using a Light Dependent Resistor (LDR) and a PIC microcontroller. Now, let’s delve into the question: “How do these LDRs facilitate the rotation of solar panels with the assistance of a stepper motor?” The LDRs are employed to gauge the intensity of light with the support of a microcontroller. The microcontroller reads values from both light-dependent resistors, effectively determining the light intensity through these sensors.

When the light intensity is identical for both light sensors, the solar panels remain stationary, and the stepper motor remains inactive. This stability is maintained during nighttime when there is no ambient light. At sunrise, the left light sensor activates, initiating the rotation of the solar panel through the stepper motor. The motor’s rotation speed is contingent upon the intensity of light. The solar panel continues to rotate until the light intensity on both sensors becomes equal. Once equilibrium is reached, the solar panel stabilizes. This process repeats in the opposite direction after 12:00 am or in the afternoon. In the evening, when the light intensity from both sensors equalizes again, the solar panel returns to a stationary position. This cyclic process continues throughout the daytime.

Circuit Diagram Solar Sun Tracking System using PIC Microcontroller

The circuit diagram depicts a sun solar tracking system using a PIC16F877A microcontroller. This system is designed to track the sun’s movement and adjust the orientation of the solar panels to maximize power generation. The specific components and connections in the circuit diagram are as follows:

  1. Solar Panels: These are the primary means of capturing solar energy. The panels are not explicitly shown in the diagram but are essential components of the system.
  2. LDRs (Light Dependent Resistors): Two LDRs are incorporated to measure the intensity of light. These sensors are crucial for detecting the sun’s position and guiding the movement of the solar panels. The LDRs are connected to the microcontroller for processing the light-intensity data.
  3. PIC16F877A Microcontroller: This microcontroller serves as the central processing unit for the system. It receives input from the LDRs and controls the stepper motor based on the light intensity readings. The microcontroller also facilitates the interaction between various components.
  4. Stepper Motor: The stepper motor is responsible for adjusting the position of the solar panels. Its rotation is controlled by the microcontroller based on the input from the LDRs. The ULN2003 is used as a driver for the stepper motor to amplify the current and protect the microcontroller pins.
  5. ULN2003: The ULN2003 is an integrated circuit used to drive the bipolar stepper motor. It acts as a current amplifier and relay for the signals from the microcontroller to the stepper motor.

The overall functionality of the circuit involves the LDRs measuring the light intensity, and then the PIC16F877A microcontroller processes this data. Based on this analysis, the microcontroller controls the stepper motor via the ULN2003 driver to adjust the orientation of the solar panels, ensuring they are positioned optimally to capture sunlight. This continuous adjustment results in efficient power generation from the solar panels throughout the day.

sun solar tracking system using pic microcontroller
sun solar tracking system using pic microcontroller

MikroC for Pic Code Solar Sun Tracking System

The code for this project is written in the MIKROC compiler and 8Mhz crystal is used in this project. If you do not know how to use MikroC for Pic, you can refer to these tutorials:

The provided code is written in MikroC for PIC and is designed for a sun-tracking system using a PIC microcontroller, LDRs (Light Dependent Resistors), and a stepper motor controlled by a ULN2003 driver. The program initializes the necessary configurations, setting up analog inputs for LDRs (connected to AN0 and AN1) and configuring PORTC as output for controlling the stepper motor through the ULN2003 driver.

// Include necessary libraries

// Define connections
#define LDR_LEFT    AN0
#define LDR_RIGHT   AN1
#define IN1         PORTC0_bit
#define IN2         PORTC1_bit
#define IN3         PORTC2_bit

// Function prototypes
void initialize();
void trackSun();

// Main function
void main() {

    while (1) {

// Initialize function
void initialize() {
    // Configure ports
    TRISA = 0b00000011; // RA0 and RA1 as inputs (LDRs)
    TRISC = 0;          // Set PORTC as output for stepper motor control

    // Initialize ADC
    Delay_ms(10); // Delay for voltage stabilization

    // Additional initialization code as needed

// Track the sun function
void trackSun() {
    // Read light intensity from LDRs
    unsigned int leftIntensity, rightIntensity;

    leftIntensity = ADC_Read(0); // Read from AN0
    rightIntensity = ADC_Read(1); // Read from AN1

    // Determine the direction to move the solar panels
    if (leftIntensity > rightIntensity) {
        // Move panels to the left
        IN1 = 1;
        IN2 = 0;
        IN3 = 1;
        Delay_ms(100); // Adjust delay as needed
    } else if (leftIntensity < rightIntensity) {
        // Move panels to the right
        IN1 = 0;
        IN2 = 1;
        IN3 = 1;
        Delay_ms(100); // Adjust delay as needed

    // Turn off all control lines to stop the motor
    IN1 = 0;
    IN2 = 0;
    IN3 = 0;

    // Add additional logic or control algorithms as needed

How Does Code Work?

The main functionality of the program lies in the trackSun() function, where it reads the intensity of light from the LDRs using the built-in ADC functions provided by MikroC. Based on the light intensity readings, the program determines the optimal position for the solar panels to track the sun. It then controls the stepper motor by activating specific control lines (IN1, IN2, IN3) to adjust the solar panels’ orientation. Delays are included to ensure smooth motor operation, and after the adjustment, all control lines are turned off to stop the motor.

In the initialize() function, the program sets up the initial configurations for ADC and port settings. The main() function initializes these settings and enters a continuous loop where it calls the trackSun() function repeatedly, allowing the solar tracking system to continuously monitor and adjust the panels based on the changing light conditions. This code serves as a foundation for a sun-tracking application, and you can incorporate additional features or modifications based on specific project requirements and hardware characteristics.

If you don’t know how to interface a stepper motor with a PIC16F877A microcontroller and its working, check the following article:


This concludes the discussion on the sun solar tracking system project. We have covered all the essential aspects and topics you need to understand before undertaking this project. Additionally, we have provided separate articles on interfacing light sensors and stepper motors with the PIC16F877A microcontroller. After reading this article, you should be equipped to write the code and assemble the hardware for your project.

You may also like to read:

53 thoughts on “Solar Tracking System using Pic Microcontroller”

  1. Hi sir, can you send solar tracking system using pic16f877A microcontroller source code?
    Your helping hand is appreciate. thank you.

  2. sir can you send me the source code of this solar tracking system usinc pic16f877a microcontroller source code?.. thank you for the help

  3. sir can you send me the source code of this solar tracking system usinc pic16f877a microcontroller source code?.. thank you for the help

    • Dear sir, can you please send me the solar tracking system using pic16f877A microcontroller source code?
      Your helping hand is appreciate. Thank you for your kind attention and I do appraise your helpful hand.

  4. Hi sir. I really need this code for my fyp project. This project is almost the same as my project Will u please email me sir… Your help is really really appreciated.

  5. your site is very good and i follow you on line i greatly appreciate what you have done on the solar power tracking using pic micro-controller,could you help me please i have the solar tracking using pic micro-controller project so sir,send me the code and the circuit diagram and the necessary document with the code that you ha developed,thank you for you helping


Leave a Comment