Chasing the sun

Adrian Leal

Overview

The following project is a solar tracking system that is powered with 4xAA batteries. The device can also work when powered via micro USB, but this would require the system to be connected to something at all times, which is inconvenient for the purpose of the project. Everything is mounted on a wooden board. There are two servo motors connected to the microcontroller board, which are the responsible for the movement motion. On the top of the servo motors, there are 4 photovoltaic sensors that respond to the light, making a "follow" motion towards it.

Side view Top view Video

Hardware

Here is a list of the main components used for the project:

Silicon Labs EFM32ZG210F32-QFN32
This is the microcontroller used for the project. A microcontroller that minimizes energy consumption while maximizing performance, therefore, a great combination of qualities for the purpose of the project.
Battery Holder 4xAA
The battery holder holds the four AA batteries that power the system. Since we want the application to work for a long period in order to track the motion of the Sun throughout the day, it was necessary to find an external power source.
Servo Kit
This kit consists of two servo motors. Having two servos allows the solar cells to move in ±90 degrees. One of the servos does the horizontal movement while the other one is in charge for the vertical movement.
Photo Cells
There are four photo cells placed on top of the servo motor. These cells measure the value of voltage at any given time. These values can be stored and use to evaluate which movement the servo should do. Also, a piece of wood with the form of a cross was placed to optically isolate the photo cells from each other to get a more unique and precise value.
Schematic Assembly

Software

All the code for the project was developed using Keil μVision5 in C. The software consists of a series of hardware instructions that activate the main component, for example, reading the values of the photo cells. The RTC is configured to enable interrupt every 0.0625 seconds, in other words, the light intensity is measured every 0.0625. After obtaining the reading from the four cells, the program determines if it needs to move the servo motor or not. To determine if the servo motors need to be moved or not, a vertical tolerance and a horizontal value was established.

The readings from the sensors are normalized to address variance in sensor's sensitivity. For this we measured the sensor response in the dark and at full light and scaled it to the range 0 - 4095. Without this the code was not working well. The normalized values are used to compose 4 variables: the average of the top sensors, the average of the bottom sensors, the average of the right sensors, and the average of the left sensors. Then the vertical values are subtracted (top-bottom) as well as the horizontal values (right-left). If the difference of these values was greater than the specific tolerance value, the servo motors will activate; if no movement is needed they will not start. If the servo needs to be moved, the direction was determined by looking at which horizontal/vertical value was greater.

For example, if the difference between the average of the top and the bottom sensors is greater than the vertical tolerance the corresponding servo will activate by starting its PWM generation. Now, it will look at which value is greater, if the average from the top sensors or the average from the bottom sensors. If the average of the top sensors is greater, it means that the brightness of the light hitting those two sensors is greater, so it will move "up" until the brightness is "equal" or in tolerance range. Once the movement is finalized, the PWM generation is turned off until a new movement is needed. Turning PWM on and off halps to reduce sensor noise when they are idle.

Final Thoughts

I wish I would have realized that each sensor has a different maximum and minimum value. That caused several problems as, even though it was clear than one side was brighter than the other, the servo would not move. Also, it was complicated to understand all the hardware section code as the manual and the data sheet for the microcontrollers contain a lot of information; it was hard to find what I was looking for. So, I feel like having some previous knowledge or putting more time into that would have helped in the early steps of the projects. In addition, it was fun to work on it once I saw some results. Although it was not working perfectly the first time, it felt good to see some progress and it was very useful to see where the problems might have been coming from.

Downloads


Last modified:Mon, Jan 23, 2023.

00120