Categories
TUTORIALS

Using photoresistors and a servo motor to make a single axis solar tracker

Overview

This tutorial is the second one in the series corresponding to the Sunbrella project for the Sensing the City course taught by Allison Lassiter for students in University of Pennsylvania’s Department of City and Regional Planning.

This tutorial will focus on how to use photoresistors and a servo motor to make a single axis solar tracker. The mechanism aims to adjust the angle of a solar panel throughout the day (from East to West) to maximize energy production. The intention is for the device to work autonomously and be powered by a battery fed by the panel. This tutorial does not cover the use of the solar panel itself, just how to adjust its position. For instructions on how to charge the battery using the solar panel please see the tutorial by Laura Frances: Using a solar cell and rechargeable battery to power a servo motor

Acknowledgements and sources

This tutorial is based on the following resources: 

Arduino Solar Tracker: Open hardware/software test bench for solar tracker with virtual instrumentation, by Aboubakr_Elhammoumi and motahhir, published on April 10, 2020; available at https://projecthub.arduino.cc/Aboubakr_Elhammoumi/77347b69-2ade-4a44-b724-3bb91e954188 

How to Make Solar Tracker with Arduino Uno R3, by ICV Creative, published on April 7, 2021; available at https://www.youtube.com/watch?v=dP6gO19t2pk 

ChatGPT version Match 14, 2023 was also used to modify the code.

Parts

Arduino Uno 

Resistor 220 ohm

SG90 Micro-servo motor

Photoresistor (light dependent resistor – LDR), 5 Mohm (verify) – 2 pieces

Wires & connectors

Power source (could be a battery, I powered this with my laptop).

Software

Arduino IDE (version 2.0.3)

Libraries: Servo.h

Mechanical design

The solar panel is mounted on an horizontal axis and attached to a servomotor that adjusts the panel’s angle. (When the device is placed in the sunlight the axis supporting the panel should have a North-South orientation, so that by rotating in place it will cause the panel to turn from East to West). LDRs are mounted on opposing panel edges, along the servo’s range of movement. For our project is it also preferable to constrain the panel’s range of movement to 90 degrees. 

Function

The LDRs and the servo are wired to the Arduino Uno board, which can be powered either by a battery or by other energy sources. Each LDR sends analog signals to the arduino board, feeding information about the intensity of the light being measured. LDRs act like resistors but the resistance changes depending on how much light they receive. This information is conveyed to the arduino board as an analog signal. The board compares the analog signals being received and the difference in the intensity of light being measured by each LDR. Based on that it instructs the servo to move in the direction of the LDR that is receiving less light. Once the servo has adjusted the panel’s angle to a sufficient degree, both LDRs will be similarly exposed to sunlight and this will be reflected in the information being fed to the board. When the information being fed to the board indicates that both LDRs receive the same light intensity the servo no longer has instructions to move, and the position will be maintained until new adjustments are needed based on the sun’s movement. 

A default fully horizontal position and average ranges of light radiation are determined, so that when the LDRs are exposed to light below this minimum (basically, at night when it is dark), the servos will be instructed to move the panel back to its default position. (We find it preferable to set the default position as fully horizontal because for our main project there are more situations where it is preferable for the panel to be in a fully horizontal position rather than tilted toward the East.)

Wiring diagram

Wiring diagram made using www.cirkitstudio.com

Wiring

  1. Set up the breadboard with a connection to a ground pin and teh 5 V pin.
  2. For each photoresistor, set a line of the breadboard with the wire connecting to the ground, a 220 Ohm resistor, and a wire connecting to pin A0 or A1 accordingly
  3. Use male-female wires to wire the 2 photoresistors. Attach at opposite ends of the photovoltaic panel (in this case, this is a smaller model and I did not have small photovoltaic cells, so this is replaced by the piece of cardboard). Consider how you will mount this later on so that the wires will not obstruct the movement or come loose.
  4. Attach your photovoltaic panel or replacement to the arms of the servo at the end of the axis of rotation (in my case, along the middle) mount the servo on the mechanical support structure you are using. This could be a proper support with bearings, in my case I balanced it on a metal frame.
  5. Connect the servo’s 5 V and ground cables to the breadboard. Connect the other wire directly to the Arduino board pin 6.
  6. Connect the photoresistors to the breadboard (one cable to the 5V row and the other to the line selected for that photoresistor, next to the wires connecting to pin A0 or A1 accordingly).
  7. Now all parts are wired, connect the Arduino to the laptop.
  8. Time to upload the code and test different lighting conditions. 🙂

Picture of the testing prototype

Code

The code below is used to process the information from the LDRs and control de servo. The code initializes a variable for a pin and assigns the value 6. The setup initializes pin 6 as an output. The loop then sends and stops voltage from pin 6 with breaks before repeating.

Connect the hardware components before uploading the code to the arduino board. You can test the functionality by using a lamp to shine a light on your model from different angles and activating the servo.

Video

This short clip shows the panel moving to its initial position and then slowly adjusting its angle in response to the feedback from the photoresistors.

Leave a Reply

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