Light tracker using LDR, stepper motor and AVR microcontroller

Introduction:

Electricity is the most necessary and important element of human life. We cannot imagine daily life without electricity. Electricity is generated using conventional (coal, diesel) and unconventional (water, wind, sunlight) energy sources. The latest and most recent trend is to generate electricity from solar energy. The solar panel (consisting of photovoltaic solar cells) converts solar energy into electricity. Hundreds or thousands of solar panels that gather generate electricity in terms of Mega Watt (MW). Only one solar panel can be used for any small unit (single street light, sunlight). Now, in order to get maximum electricity from the solar panel, the solar panel must always be sun-oriented. It should not be covered by any object (or obstacle) or should enter the shadow region. During the day the sun moves from east to west. If the solar panel is stationary, it may be covered for a while or be in the shaded region after a period. So a mechanism is needed to move the solar panel in the direction of the sun. Arrangement should be made so that the solar panel moves automatically as it detects the shadow region – which means less sun. Otherwise, the solar panel should follow the sunlight (daylight).

This project demonstrates how the solar panel moves in the direction of light. Uses two LDRs as a light sensor one for the left and one for the right and a passenger engine. The movement of the stepper motor indicates the movement of the solar panel. When the light falls on both LDRs, the engine is stationary. As the light falls on any LDR, it means that other LDRs are in the shaded region or are covered. So the stepper motor moves in the direction of a larger light. The engine rotates until the light falling on both LDRs becomes the same. This makes the engine rotate in both directions as the light on any LDR increases. The project uses the ATMega32 AVR microcontroller which will take control measures to rotate the motor step by step (solar panel) in the direction of maximum light.

Hardware

Circuit connection:

The figure shown below shows the different components used and their connections. Major components are LDR-for light sensor, ATMega32 micro-controller, UNL2003A stepper motor driver and several LEDs – for guidance. As shown in the figure

  • The LDRs are connected between Vcc and Gnd with 10 K pots which give prejudice to the LDRs. The pots are used to set / change / adjust the level of the light threshold that falls on the LDR.
  • The LDR junction outputs are powered by the ADC0 and ADC1 input pins of the AVR micro controller
  • Four different color LEDs are connected to the PORTD pins with current limiting resistors. They are used to give different directions
  • The PORTC PC0 – PC3 PINs are connected to the UNL2003A input.
  • Four outputs of the UNL2003A are connected to four coils of the stepper motor.
  • The common terminals (terminals) of the coil of the stepper motor are connected to the Vcc supply
  • A 16 MHz crystal with two 22 pf capacitors is connected to the crystal input pins

Circuit operation:

  • When the light falling on both LDRs is the same, the voltage at both ADC inputs is lower or higher than the threshold level. So the engine is stopped. This is indicated by the RED LED. This is possible in two cases. 1 when both LDRs are exposed to maximum light (below the threshold level) and the second when both LDRs get less light (more than the threshold level)
  • Suppose now that the light decreasing on LDR1 increases than LDR2. So the input voltage at ADC0 increases the threshold level. But at ADC1 it is still below the threshold. (this means that LDR2 can be in the shadow region) So the engine rotates clockwise to rotate the panel in the LDR1 direction to get maximum light on both LDRs. This is indicated by the GREEN LED
  • The engine rotates until both ADC inputs become below the threshold level
  • Similarly, when the light falling on the LDR2 increases, the engine rotates clockwise. This is indicated by the GALBEN LED
  • The ATMega32 microcontroller reads the analog voltage values ​​of LDR1 and LDR2 after every 500 ms. This is indicated by the blinking of the BLUE LED. Therefore, light loss on both LDRs is detected at a rate of 2 samples / second.

Software:

The software program incorporated in the AVR microcontroller is responsible for the complete functionality. Performs the following tasks

  1. It reads the analog voltage values ​​and converts it into digital equivalent
  2. Converts this digital value to equivalent decimal value
  3. Compare these decimal values ​​with the threshold levels to make the decision to rotate the engine
  4. Push the motor step by step to rotate it clockwise or clockwise
  5. Give different directions on LEDs

The program is written in C language. It is compiled using the GCC AVR compiler and simulated using the AVR simulator for the ATMega32 microcontroller. Both the GCC AVR compiler and AVR simulator are available in an AVR (V4) software tool. When the program is successfully compiled, it generates a HEX file. This file can be uploaded to the ATMege32 target device using any suitable programmer (such as ponyprog). Here is the full program code with the necessary comments.

/*54745756836*/

Leave a Comment