Home / Home made Projects / Microcontroller Projects / Uni directional Solar Tracker using microcontroller

Uni directional Solar Tracker using microcontroller

In this article we will discuss about designing of unidirectional solar tracker using Microcontroller. This article also covers the required details like design calculation, labelled diagram, code and software simulation of the designed tracker.


What is solar tracker and why it is needed?

It is a device which is used to track the sun light. It is usually installed with the solar panels to rotate them in the direction of sun. The purpose of solar tracker is to ensure that solar panels catch maximum sun light.

Due to the increase in demand of energy, renewable power sources are getting more attention among which  solar energy is the most promising. The goal of the scientists is to increase the efficiency and power output of solar panels.  To achieve maximum output from solar panels, it should be rotated along the sun ensuring that it faces the sun throughout the day.

There are mainly two types of solar tracker, Unidirectional and bidirectional. In uni-directional the tracker tracks the sun only in one direction that is from east to west. However in bi directional tracker, the tracker tilts the panel in north and south direction towards sun along with east and west.

Block diagram of Solar tracker using microcontroller

Following figure shows the block diagram of unidirectional solar tracker

block diagram of solar tracker using microcontroller

Above figure shows the electrical portion of uni-dimensional simplest solar tracker. Mechanical portion of tracker is not the scope of this project. The basic requirements (electrical) for solar tracker are light sensor, a controller and a motor. This project uses microcontroller and servo motor for precise movement.  For unidirectional solar tracker only two light sensors are required which will be installed as shown in the following figure

sensor design for solar tracker

Sensors are installed on a sheet having a solid compartment in between. As shown in the above figure, if the sun has rotated towards sensor on right side,  right will catch more light than sensor on the left side. Based on the difference of the reading of two sensors, the direction of sun can be determined. So when the microcontroller finds the difference in the output of two sensors, it will rotate the solar panel (and sensors) such that the difference in their output becomes zero.


The electrical & electronics components required to construct solar tracker using microcontroller are

  • Resistor
  • Microcontroller
  • LDR or photo diodes
  • Servo motor
  • Power supply.

The given components are connected in as shown in the figure.

schematic diagram of solar tracker using microcontroller

As it can be seen in the above figure that two LDRs (light sensors) are connected with two analogue pins of the 18f4220 PIC microcontroller. The light caught by each sensor is determined by controller using Analogue to digital (A/D) converter and the difference is calculated. If the light caught by sensor at the right is more than sensor at the left, the motor will rotate the servo motor slightly towards right side and check the reading again. The motor will be rotated until the reading of both sensors becomes equal.

Simulation results

The given circuit is simulated in ISIS Proteus will be tested for different conditions and the response of the motor will be checked.

simulation result 1

It can be seen from the above figure that initially the both the sensors are at same light level therefore the motor is static at its initial position.

simulation result 2

Now when the top sensor is catching more light than the bottom one, the motor started rotation which be seen by the motor angle. The width of PWM wave has also altered which shows that motor has rotated from its initial position. The motor will continuously rotate until both sensor are under same light level.

simulation result 3

It can be seen from above figure that after rotating 61 deg, the both light sensor are at same lux level as a result the motor stopped rotating and retained that position at which both sensors  catching equal light. It means the solar panel and sensors are exactly facing the sun.


The program is written in MIKRO C compiler in C language. Comments are written against syntax which makes it self-explanatory.

void main() {
float x,y;
float dutycycle=12.5;
float sensor1, sensor2;
TRISC = 0;                          // designate PORTC pins as output
TRISA = 0xFF;                        // designate PORTC pins as input
ADC_Init();  // Initialize ADC module with default settings
PWM1_Init(50);                    // Initialize PWM1 module at 5KHz
while (1) {
sensor1= ADC_Read(0); // Get results of AD conversion
sensor1=(sensor1*4.88)/1000;  // to understand how to convert analogue to digital please refer to this article
sensor2= ADC_Read(1); // Get results of AD conversion
if(sensor1>sensor2)    // if sensor 1 catches more light than sensor 2
{  x= sensor1-sensor2;   // find the difference
   if (x>0.1)   // if the difference between the two sensors’s output is greater than 0.1
  { dutycycle= dutycycle+0.2;   }   // increase the duty cycle to rotate the motor
   else                             // if difference between two sensor’s is not greater than 0.1
  { dutycycle= dutycycle*1;     }   // retian value of duty cycle
else if(sensor1<sensor2)      // similarly if sensor 2 value is greater than sensor 1, do same as in above case
{  y= sensor2-sensor1;
   if (y>0.1)
 { dutycycle= dutycycle-0.2;   }
 { dutycycle= dutycycle*1;     }
else if(sensor2=sensor1)    // if sensor 1 catching same light as sensor 2
{dutycycle= dutycycle*1; }   // put the duty cycle on its previous value so that motor stays at its position
  // duty cycle of 12.5 corresponds to 0deg of position of servo motor
  //duty cycle of 52 corresponds to 180deg position of servo motor
  // in one day the sun moves by 180deg from east to west
if (dutycycle <12.5)      //  if duty cycle becoming less than 12.5
{dutycycle=12.5; }   //  not to reduce duty cycle from 12.5 so that motor does not cross its one extreme limit which is 0deg
else if (dutycycle >52)   // if duty cycle is increasing more than 52
{dutycycle=52; }          //  not to increase duty cycle from 52 so that motor does not cross its second extreme limit which is 180deg
PWM1_Set_Duty(dutycycle);        // Set current duty for PWM1
PWM1_Start();                       // start PWM
Delay_ms(100);                       // slow down change pace a little

If you have any questions please ask in comments

About Syed Noman ud din

Syed Noman ud din is an Electrical Engineer and working in Industry from last 3 years. He writes technical articles for electrical and electronic engineers. He has also published several research publications in renowned international journals.

Check Also

Power Factor measurement using Microcontroller

The article will help the readers to use microcontroller for power factor measurement using a …

Leave a Reply

Your email address will not be published. Required fields are marked *