You are on page 1of 15

A Digital Microcontroller Implementation for Solar Tracking

Leah Chowenhill, Savith Weligama Arachchige

Milestone 4
June 2018

In the following project, we designed and built a solar tracker which senses ambient light and
rotates to maintain direct alignment with the sun as it moves across the sky. The system is composed
of four light dependent resistors, an Arduino Due, a motor control shield, and two motors. The
resistance of each LDR varies based on the ambient light level, and the voltage across each of these
components acts as an analog input to the Arduino Due. By comparing the voltage from opposing
LDRs, the direction in which the tracker should rotate is computed. The motor shield then outputs a
voltage signal to start the motors. The system constantly polls the voltage difference between
opposing LDRs until it is zero, at which point the motors stop. The solar tracker also utilizes a Seeed
bluetooth shield to send data regarding system functioning to an Android phone. Dummy solar data
for system performance and energy production is also logged. This data is determined based on the
average kilowatt hour generation from a 6 kW solar system in Sydney, assuming 7 hours of direct
sunlight. The solar tracker was successfully tested first using a flashlight and then with ambient light.
Further work that could have been done to the system include mechanical design changes to decrease
gear belt failure, as well as the addition of a miniature solar array on the tilting panel to log real time
energy data.

1. Project Aims
The aim of this project was to design and build a mechanical device which uses a digital
microcontroller and light dependent resistors to track the movement of the sun across the sky, while
simultaneously rotating to directly face the sun [1]. It was also required that data regarding system
functioning be logged using bluetooth connection to a mobile device. It was chosen that motor angle,
number of rotations, north-south voltage, east-west voltage, response time, performance, and
projected energy generation data would be sent from the microcontroller when requested by a slave
device. Therefore, the solar tracker had both a considerable software and hardware component.

2. Performance Goals
The initial goal of this project is to build a sensor that would track changes in the direction
and angle of the sun. This was done by placing four light dependent resistors around a rectangular
opaque object, evenly spaced from one another [1]. As the sun rotates around this stationary sensor,
the ambient light casts a shadow from the opaque object across one or more of the light dependent
resistors. A light dependent resistor is comprised of an exposed semiconductor that alters its resistance
based on the amount of light it is exposed to. The resistance of one such resistor will be much greater
when it is placed in darkness, as compared to when it is in light due to the creation of electron-hole
pairs in the semiconductor material [2]. By placing a regular resistor in series with each light
dependent resistor and applying a single DC voltage across the two, the change in electrical resistance
will be converted to a voltage value. This voltage value will then change for different levels of light
along with the resistance. Thereby, a voltage divider is created. The voltage levels from the shaded
LDR and its opposite LDR are compared to find a difference, indicating the current direction of the
The next goal of this project was to use a digital microcontroller, the Arduino Due. The
Arduino Due possesses several analog input pins. Using these, the four sensor outputs were connected
to the Due. The program written for the Due then converted the analog inputs to a voltage difference
for the two pairs of opposing resistors. The Arduino program will maintain constant rotation of both
motors whilst the absolute value of the calculated voltage difference is greater than 0.1 Volts. The
direction of the rotations is dependent on the polarity of the voltage difference. To prevent the motors
from exceeding the rotational limit and the belts from slipping, a maximum and minimum angle was
created. When these thresholds are reached, the servo returns to the centre position and continues
The third goal was to build the mechanical device to rotate the sensor according to the
calculated voltage difference so that the sensor is consistently facing the sun directly. When the
voltage difference is nonzero, an voltage signal is output by the motor shield to rotate the motors in a
specified direction. The device stops rotating, or is delayed, when no shadow is cast by the opaque
object across the four light dependent resistors. Tilting of the sensor panel is primarily dependent
upon a ball-and-socket joint, as well as a set of drive belts and two motors that move the top panel in
either a north-south direction or an east-west one.
After testing both the sensor and mechanical device separately, the two were integrated.
Successful integration of the hardware and software components of this project was the final goal of
this project. Once these two portions were successfully tested, a bluetooth shield could be used to send
system performance data to a mobile device. Dummy solar production data, based off of average solar
production for 6 kW home arrays in Sydney and the responsiveness of the tracker to the sun’s
movement across the sky, is calculated by the Arduino Due. An Android phone can connect then to
the Arduino Due master and send the character ‘s’ to receive this data as well as information regarding

the tracker’s functioning like motor angle and analog voltage readings. An summary of the
implementation of the solar tracker can be found in Appendix 2.

3. Design

3.1 Light Dependent Resistors

The output of the voltage divider created by placing one light dependent resistor and one
typical resistor in series is sent to the analog pins of the Arduino Due, which relies on the peripheral
input/output capabilities of the SAM3X processor. Each LDR was placed in series with a 10 kΩ
resistor, as was recommended in the datasheet [2]. The input voltage to these divider networks is 3.3
V from the Arduino Due. There are four analog inputs to the microcontroller. These analog voltages
are read as a value between 0 and 1023, which maps to a voltage reading from 0V to 3.3V, the
maximum voltage rating for the Arduino Due pins. The voltage reading from each light dependent
resistor is then recorded. The voltages of opposing LDRs, such as north and south, are compared by
the Arduino Due. The voltage difference between these LDR pairs is proportional to the difference in
ambient light level; this data is also recorded. The LDRs have a higher resistance when in darkness. In
complete darkness the LDRs are rated to have a resistance of 0.5 MΩ whereas, in direct light, the
LDRs are rated to have a resistance of 5 to 10 kΩ [2].
Initially, voltage comparison was performed by a comparator circuit which was composed of
a voltage buffer and two differential amplifiers. As the differential amplifiers were powered by a
single supply of 5 V from the Arduino Due, rather than a bipolar supply, the voltage buffer was used
to establish a 2.5 V for reference. In other words, this buffer created a virtual ground. Typically, when
supplying an op-amp with both a positive and negative power rail, the reference voltage is 0 V. The
voltage drop across the north LDR and that of the south LDR were fed into one differential amp,
while the voltage drop across the east LDR and that of the west LDR were fed into the other.
Furthermore, each differential amplifier had a gain of -0.33 to be compliant with the Arduino
maximum input voltage of 3.3 V. Each differential amp output a voltage corresponding to the
difference between the light levels of opposing LDRs, which were read as analog inputs by the
Arduino Due. The comparator circuit, as well as the respective analysis performed in designing it, is
shown Appendix 4 below.
When the solar tracker was initially tested using flashlights, the comparator circuit accurately
produced two voltage levels to dictate the difference in light level between the north-south LDRs and
the east-west LDRs. However, once the tracker was tested in ambient light, it was found that light to
moderate shading did not produce a high enough voltage drops across the LDRs to drive the
differential amplifiers. Therefore, due to unreliability, the comparator circuit was removed and the
voltage comparison between the four LDRs was done in software. In doing so, the number of analog
inputs to the Arduino Due increased from two to four. While substantial, this change made the tracker
more efficient, and it also guarantees that the device design does not use any unnecessary components.

3.2 Arduino Due

The Arduino Due was chosen as the microcontroller for this project because it was familiar
and has reliable documentation. The Arduino Due serves four main functions in this project which are
as follows: read analog voltage inputs, perform voltage comparison calculations, establish USART
connectivity, and compute system performance data. The Arduino Due has four serial ports. The solar
tracker utilizes Serial2, or USART1, which is connected to digital pin 16 and 17.

The sensor circuit was connected to the Arduino’s analog pins. The values read by the pins
range from 0 to 1023, which corresponds to a floating point voltage value between 0 and 3.3. The
Arduino program compares the east and west voltages with each other and the north and south
voltages. The resulting comparison values inform the behaviour of the servo motors. The motors
rotate towards to light dependent resistor with the higher voltage value. If both values are equal, the
rotation is delayed. The Arduino library possesses a digitalWrite function which is used to control the
motor’s direction and whether or not the servo is rotating.
The Arduino Due possesses multiple UART’s. This allows the Due to maintain a serial
connection with a connected PC and a bluetooth device. The implemented embedded system writes
data to the connected system, and when toggled, sends the data to a connected master bluetooth
device. The program keeps track of the voltage values, the position of the servo, number of rotations
and estimated power generated.

3.3 DFRobot Motor Shield L293D

The DFRobot Motor Shield is composed of a L293D integrated circuit chip and controls the
two 12 V, 1 A motors that are used to tilt the top panel of the solar tracker. The shield powers the
motors using an external 12 V battery which is plugged into the power jack of the Arduino Due.
Furthermore, the motors connect directly to this shield by four screw terminals. The acquisition of a
motor shield was necessary because the Arduino Due alone can only control one motor.
While this motor shield is compatible with the Arduino Due, the variables which it can
control are different than those which can be programmed when controlling a motor using only the
Arduino Due board. For example, the Arduino offers users the ability to set motor position in degrees
while the DFRobot shield does not. Therefore, only a portion on the Arduino motor library was
compatible with the shield, as was found by trial and error. This also meant that a new method for
tracking motor position had to be derived. It was crucial to track motor position, as the tracker could
tilt in two different directions at any given time. Over-rotation could break the top panel or dislodge
the ball-and-socket joint. The two variables that the DFRobot shield can control are speed and
direction. The rotation speed is denoted by a number ranging from 0 to 255, with 255 being the
fastest, parsed to the analogWrite function. However, when implementing the the code, it was found
that the Arduino library ‘analogWrite’ function caused the motor to stall. Hence, the digitalWrite
function was used, with ‘high’ denoting rotation and ‘low’ denoting a delay in rotation.

3.4 Seeed Bluetooth Shield

The Seeed Bluetooth shield allows the Arduino Due to communicate with a mobile device
which, in this application, is an Android phone. A smartphone user can request solar tracker data by
sending the character ‘s’. The Arduino master then sends the current north-south voltage, east-west
voltage, motor angles, number of rotations, response time, performance percentage, and projected
energy generation in return. In addition, sending the character ‘p’ initiates a five second pause in the
rotation. To initialize the Bluetooth module, digital pin 16 must be connected to pin 2 on the shield
and digital pin 17 must be connected to pin 3 on the shield. Initialization was successful when the red
and green LEDs on the shield are flashing. A Bluetooth terminal must be installed on the Android
phone for the user to be able to request and receive data from the solar tracker.
The digital pins on the Arduino were initially connected to pins 6 and 7 on the shield,
respectively, but it was found that the DFRobot shield reserves these pins for motor control. Hence,
the Rx and Tx connectors on the bluetooth shield were moved to digital pin 2 and 3. These pins were
chosen as they were the only pins unused by the motor shield or UART0.

3.5 12 V 1 A Motors
The solar tracker uses two motors for adjusting the top panel. Each motor has a positive and a
negative pole, which connect to the DFRobot motor shield through screw terminals. One motor
controls tilting in the north-south direction, while another motor controls tilting in the east-west
direction. When the voltage difference between two opposing LDRs is nonzero, the corresponding
motor will rotate to equalize the ambient light across the two LDRs. Once the voltage difference
becomes zero, the rotation will stop. For example, if the north LDR is more shaded than the south
LDR, the north-south motor will rotate counterclockwise until both LDRs are experiencing the same
light level. The opposite would occur if the south LDR was experiencing more shading.
At the end of each motor shaft is a large plastic gear with a tooth ratio and sizing which
matches the kinks in the gear belt attached to it. Therefore, when a motor rotates, the gear teeth pull
the gear belt more taught in the direction of rotation.
Rotation was achieved using the Arduino library digitalWrite function. Parsing ‘high’ to the
function initiated rotation. The servo rotates until it receives a ‘low’ signal. Hence, with the use of a
delay, it is possible to track the angle the servo has rotated. After trialling the servo’s rotational
velocity, it was found that it takes 345ms for the servo to rotate 15 degrees, with the speed control set
to ‘high’ using the digitalWrite function. Hence, after rotating the servo for 345ms, we can increment
a variable keeping track of the servo motor angle. Using this added functionality, it is possible to
prevent the motor from exceeding 180 degrees in rotation. When the servo reaches 180 degrees, it
rotates in the opposite direction for 4140 ms, which corresponds to 180 degrees of rotation, thus
returning to the central position.

3.6 Physical Device

While the software and microcontroller are the main focus of this project, constructing the
mount and top panel of the solar tracker was just as time-intensive. The initial design of the solar
tracker mechanism is shown below in Figure 1, and the final construction of the device does not vary
much in appearance from what was originally proposed. The top panel, as well as the base, of the
tracker are made of cardboard sheets. A small wooden post is placed in the center of the four equally
spaced light dependent resistors to produce shade depending on the direction of the sun, as shown in
Figure 2. The post of the tracker is composed of PVC piping, the top end of which is open. A
pre-manufactured ball-and-socket joint could not be obtained, so one was fashioned by placing a
bouncy ball in the open end of piping and placing an additional ring of PVC pipe on the underside of
the top panel. Furthermore, the motors are attached to the side of the post using metal pipe saddle
clips. All of these objects were adhered together using a quick setting epoxy. Additionally, a rubber
gear belt with the game tooth sizing as the motor gears could not be found, so properly sized gear
belts were made by bending kinks into a stiff aluminum wire. Finally, to enable fluid tilting, the wires
which connect the legs of each LDR to the voltage divider network on the breadboard at the base of
the tracker were kept long around the ball-and-socket joint. These wires were only adhered to the post
of the tracker around the motors as not to get stuck in the drive belts.

Figure 1.​ Illustrated model of solar tracker.

Figure 2.​ Illustrated model of light sensor for top panel.

4. Function Analysis
The designed embedded system successfully combined the implemented hardware and
software components. The design relies on the voltage divider created by the LDR’s. The voltage
across each light dependent resistor is compared using the Arduino Due. Using the comparison values,
the servos are either rotated clockwise, counter-clockwise or delayed, with the DFRobot Motor Shield
and the Due. Each servo’s position and the number of successful rotations were recorded. In addition,
dummy data was used to estimate the power generated should a solar panel be affixed to the tracker.
This data is transmitted to a paired master device using a bluetooth shield and the Arduino’s UART
capability. Thus, the solar tracker fulfilled the design objectives, with the software and hardware
working in tandem.

5. Testing Methodology
The solar tracker was tested rigorously. Various testing procedures were implemented for
both the hardware and software. Each motor was tested independently to ensure they worked and were
compatible with the motor shield. The program which was initially written simply rotated the motors
in various directions. It was found that using the analogWrite function, as recommended by the motor
shield documentation caused the motors to stall. Further functionality was added to the initial program
to test motor delays. The sensor circuit was tested using the Analog Discovery 2, in particular the
multimeter and oscilloscope. Theoretical voltage values were determined for nodes in the sensor
circuit using DC circuit analysis. These values were compared to the actual values read using the
multimeter to ensure the circuit was working correctly. Once it was confirmed that the sensor circuit
and servo motors were working correctly, the two were combined. Print statements were used to

verify that voltage values being read by the Arduino correctly corresponded to current the ambient
light levels. Similarly, the assert.h library was used to verify that values such as the servo position and
number of rotations were being incremented correctly.

6. Results
The design worked as expected. Using the Analog Discovery 2, it was verified that the servo
motors rotate towards the LDR with the highest voltage, under both ambient light and a flashlight.
The measured voltage values also corresponded to the theoretical values calculated using LTSpice, as
seen in Appendix 3. The Analog Discovery 2 was also utilised to ensure that the voltage mapping
equation used to ensure that analog inputs were correctly converted to a voltage value. As expected,
each servo only rotated a maximum of 180 degrees. The tracker successfully paired with a master
bluetooth device. An Android phone, using ‘Serial Bluetooth Terminal’ was able to receive the
computed data from the solar tracker, as seen in Figure 3. The complete labor and parts costs for the
solar tracker are described in Appendix 5. The final solar tracker looks very similar to what was
initially proposed, as there were no design changes made to the physical structure. The completed
solar tracker is shown in Figure 4 below.

Figure 3. ​Bluetooth data received by paired Android phone.


Figure 4.​ Completed solar tracker.

7. Proposed Improvements
If another iteration of the solar tracker were to be built, there are three main improvements
that would be made. First, in addition to the Bluetooth connectivity, the solar and performance data
would be stored in a cloud-based server. This way, users could not only receive real-time data from
the Arduino, but they could also analyse historical data. It would also be interesting to feed that
historical data back to the Arduino Due and use it in conjunction with an algorithm to optimize
efficiency. For example, the solar tracker could use rotation data from previous days with similar
weather conditions as the current day and use it to rotate proactively rather than responsively. In
theory, this would greatly improve performance as well as energy generation.
Additionally, a proper ball-and-socket joint as well as rubber gear belts to accurately match
the motor gear teeth would be made. The ball-and-socket joint could be 3D printed, whereas the gear
belts could be molded or purchased from a wholesaler. While the improvised ball-and-socket joint
rarely failed, it would be replaced for aesthetic reasons. The wire gear belts, on the other hand, failed
quite frequently due to bending or slipping. Rubber is a preferred material because of its elasticity; it
will stretch but not deform. It would also provide greater friction than the aluminum wire, which
should decrease the chances of slipping. However, it may still be necessary to rim the gears in some
way as to hold the rubber gear belts in place if slipping continues to occur.
Finally, solar panels would be added to the top panel of the tracker so that actual solar power
could be generated. This way, dummy solar data would not need to be used in Arduino computations.
An actual performance rating and daily energy generation could be computed based on real time light
levels. The addition of a solar array was tentatively proposed at the start of this project, but it was
always meant to be implemented in further iterations. The eventual installation of solar panels was
kept in mind when designing the tracker, however, so no changes would need to be made to the top
plane for it to accommodate panels. Putting solar panels on the solar tracker and beginning to generate
energy is the only thing initially proposed for this project that was not accomplished.

8. Conclusion
The purpose of the designed embedded system was to build a functional solar tracker using
easily obtainable materials. The design objectives were all achieved, with the tracker successfully
maintaining rotation to minimise it’s angle with sun. Whilst further improvements can be made, the
embedded system is self contained, and with a reliable power source, can be implemented in the real

9. References
[1] ‘Solar Tracker’ 20 March 2018
[2] ‘Light Dependent Resistors’ 20 March 2018
[3] ‘Arduino DUE Documentation’ 7 April 2018
[4] ‘Arduino Motor Shield Documentation’ 7 April 2018
[5] ‘SAM3X-Arduino Pin Mapping’ 7 April 2018
[6] ‘Design and Construction of an Automatic Solar Tracking System’ 29 May 2018
[7] ‘Position of the Sun’ 6 April 2018
[8] ‘Design and Implementation of a Sun Tracker with a Dual-Axis Single Motor for an Optical
Sensor-Based Photovoltaic System’ 29 May 2018
[9] ‘Sunshine Hours for Australian Cities’ 2 June 2018
[10] ‘6kW Power System Production’ 2 June 2018

10. Appendix 1 - Block Diagram

Figure 5.​ Block diagram of solar tracker.

Block Descriptions:
1. Input to system was ambient light from the sun that affected the resistance of four light
dependent resistors.
2. Voltage divider composed of one light dependent resistor and a 10 kΩ resistor, with one
divider for each direction (north, south, east, west).
3. Motor shield for controlling and driving the two motors.
4. Main code, responsible for comparing LDR voltages, tracking motor rotation, and generating
system performance data.
5. Bluetooth shield which connects android phone as slave to send and receive tracker data.
6. Digital microcontroller for running main code and performing computations.
7. Two 12 V, 1 A motors used to tilt the main panel in two directions, north-south and east-west.
8. 12 V external battery plugged into power jack on Arduino Due to supply motors.
9. Android phone which acts as slave to Arduino due master, sends character ‘s’ to receive
tracker data over bluetooth connection.

11. Appendix 2 - Project Implementation Summary Table

Category List of items, with web link or page number where item is

Open source compliance We are not publishing our code as open source. However, various
iterations of our project code are visible on GitHub through the
following link:
Are you publishing your code as open
source? Explain what license you are
using, or link to where you have
published your project.

Platforms Our solar tracker uses the ARM processing architecture on the
Arduino Due. The system code is written in C and uses the
Arduino library, as well as the DFRobot motor shield library. The
List the platforms you have used,
Arduino compiler and IDE was also used for this project. The
including processor architecture (ARM,
Arduino Due platform was chosen because it was familiar and we
AVR, x86, etc.), programming languages
were most comfortable using it after completing the ELEC3607
(Python, C, C++, etc.), and IDEs. If you
are not using Arduino Due, justify your
choice of platform.

Sensors and inputs The solar tracker utilizes four light dependent resistors to sense
ambient light levels (i.e. brightness and darkness). Each of these
forms a voltage divider with a regular resistor, and the voltage
List your hardware inputs (push buttons,
drop across each LDR is an analog input to the Arduino Due.
analog sensors, I2C or SPI sensors
These inputs are discussed on page 4 of the report under
including accelerometers, etc.) and
subsection 3.1 Light Dependent Resistors.
mention on which page each input is

Outputs The solar tracker uses a DFRobot L293 motor shield to output a
voltage to two 12 V, 1 A motors. These motors, and the
corresponding drive belts, rotate to tilt the top panel of the
List any mechanical, visual or other type
tracker. A Seeed Bluetooth shield is also connected to the
of outputs controlled by your hardware
Arduino Due and used to connect an Android phone as a slave
(motors, magnets, LED, 7-Segs, LCD,
device. Data is then sent to the phone upon request. These outputs
etc.) and mention on which page each
are discussed on pages 4 and 5 of the report under subsections
input is described.
3.3, 3.4, and 3.5 respectively.

Connectivity There are two protocols used for communicating between the
main microcontroller, the Arduino Due, and external
devices/actuators. First, USART is used to connect the Arduino
List any protocols used for
Due to the Seeed Bluetooth shield. Next, this same shield is used
communicating between your main
to establish a Bluetooth connection to an Android phone for
controller and any other microcontroller
sending data. The use of Bluetooth for this project is described on
excluding sensors or actuators (USART,
page 5 of the report in subsection 3.4. The serial monitor was also
UART over USB, Bluetooth 2,
used for testing the solar tracker before Bluetooth connectivity
Bluetooth 4, Wi-Fi, ZigBee, etc.) and
was implemented, as described on page 8 of the report under
mention on which page each input is
section 5. Testing Methodology.

Graphical User Interface A Bluetooth terminal phone app is used for sending data requests
to the Arduino Due master and for receiving data. This GUI is
described on page 5 of the report in subsection 3.4.
List any GUI used for interfacing users
(local LCD, Phone app, Desktop app,
Web app, Web dashboard, etc.) and
mention on which page each input is

Algorithms / Logic The value read by the analog pins maps to a voltage using the
following formula:
V oltage = analogRead(P IN ) × 1023
List substantial control algorithms
(state-machines, real-time operating The east and west and north and south voltage were subtracted
system, filesystems, feedback from each other respective. If the resulting voltage was positive,
algorithms, mathematical the variable parsed to the servo’s digitalWrite function was set to
transformations, etc.) and mention on ‘high’. Conversely, if the resulting voltage was negative, the
which page each input is described. variable was set to low.

Physical case and other The solar tracker is composed of cardboard for the base, the
tilting top panel, and the opaque object. The post of the tracker is
mechanical consideration made of PVC pipe, with two metal pipe saddle clips for holding
the motors. Additionally, the ball-and-socket joint is made of the
List what casing or mechanical systems open end of a PVC pipe and a bouncy ball. All of these objects
have been used in your project (3d were bonded together using a quick-setting epoxy. The gear belts
prints, pipes, cardboard mechanics, etc.) are each made of a wire that was bent to fit the tooth sizing of the
and mention on which page each input is plastic gear on each motor. The belts were attached to the top
described. panel using tape. The physical composition of the tracker is
described on page 7 of the report under subsection 3.6 Physical

12. Appendix 3 - Schematic Diagram

13. Appendix 4 - Comparator Circuit


Figure 6.​ Comparator circuit schematic; not used in final implementation of solar tracker.

14. Appendix 5 - Costs

Part Quantity Cost

12 V Alkaline Battery 2 3.90

DFRobot Motor Shield 1 14.13

Arduino Due 1 37.40

Seeed Bluetooth Shield 1 30.10

LDR Photoresistor 4 3.20

10 kΩ Resistor 4 0.80

12 V, 1 A Motor 2 29.90

PVC Piping 4 7.00

Pipe Saddle Clip 2 6.45

Aluminum Wire Roll 1 2.30

Gear 2 5.40

Arduino Power Jack Plug 1 5.20

Epoxy 2 8.40

Total Cost $153.18

Figure 7.​ Table of part costs.

Name Hourly Rate Number of Hours per Total Hours Total

Weeks Week Invested

Leah Schottin $20 5 6 30 $600

Savith Weligama $20 5 6 30 $600

Figure 8.​ Table of labor costs.

15. Appendix 3 - Software Code