Skip to content

Repository files navigation

Solar Tracker image

Solar tracker with ARDUINO or ESP32 and soltrack-2.2 library

Warning: This project is still in development.

CAD files: The SolidWorks files are available in the provided zip file. You can use them to simulate the panel's movement and 3D print the required parts. The software is designed to be adaptable to any solar panel, so feel free to modify it to suit your specific needs.

This Solar Tracker is an embedded system that uses an Arduino or ESP32 microcontroller to track the sun's position and adjust the angle of a solar panel accordingly. By tracking the sun’s movement throughout the day, the Solar Tracker ensures the solar panel is always optimally positioned for maximum energy production.

The system computes the sun’s position using the SolTrack 2.2 library. This project supports two microcontrollers: Arduino and ESP32.

Features

FeatureArduinoESP32
MicrocontrollerArduino UNO/MEGA2560ESP32
Time Management (RTC)Manual adjustment of date and timeAutomatic adjustment via Wi-Fi
Wi-Fi ConnectivityNot availableAvailable
MQTT SupportNot availableFully supported for Home Assistant
Motor Control (Azimuth/Elevation)SupportedSupported
Joystick ControlSupportedSupported
AnemometerSupportedSupported
Solar Position CalculationSupportedSupported
OTA UpdatesNot availableSupported
Web ServerNot availableSupported

how it works

Azimuth Control Overview

Azimuth control

The azimuth controller manages the solar panel's horizontal movement, powered by a motor controlled via a BTS7960 driver. A southward limit switch acts as a reference to stop the motor when the panel reaches the defined position, preventing excessive rotation.

Pin Configurations

ComponentArduinoESP32
Motor Enable PinPin 4GPIO 19
PWM Left (Move Left)Pin 6GPIO 18
PWM Right (Move Right)Pin 5GPIO 17
Limit SwitchPin 7GPIO 16

Calibration and Movement

At startup, the solar tracker goes through a calibration process to measure how long it takes for the panel to rotate fully from one side to the other (from 0° to 360° azimuth). Once calibrated, the tracker is able to adjust the azimuth angle by calculating the time needed to reach the desired position. The system also checks if the target azimuth angle is within the allowed range (AZIMUTH_DEG_MIN to AZIMUTH_DEG_MAX). If outside, the movement is canceled.

Limit Switch

The limit switch ensures the panel doesn’t exceed its bounds, defining 0° (or 360°) when pressed. If triggered during operation, the motor stops immediately. It also acts as a reference point to determine the panel's azimuth angle.

Here is a summary of the azimuth control parameters, as defined in config.h:

ParameterValue
AZIMUTH_MOTOR_PIN_ENMotor enable pin
AZIMUTH_MOTOR_PWM_PIN_LMotor PWM pin for left
AZIMUTH_MOTOR_PWM_PIN_RMotor PWM pin for right
AZIMUTH_LIMIT_SWITCH_PINLimit switch pin
AZIMUTH_DEG_MAX275.0° (maximum azimuth allowed)
AZIMUTH_DEG_MIN90.0° (minimum azimuth allowed)
AZIMUTH_TIME_THRESHOLDMinimum time threshold (optional)

Elevation Control Overview

Elevation control

The elevation controller manages the solar panel’s vertical tilt, tracking the sun's altitude. This is done via an actuator controlled by a BTS7960 motor driver.

Note: Relay or H-Bridge could work, I used a BTS7960 cause i had one laying around.

Pin Configurations for Arduino and ESP32

ComponentArduinoESP32
Motor Enable PinPin 8GPIO 26
PWM Up (Extend)Pin 10GPIO 27
PWM Down (Retract)Pin 9GPIO 14

Calibration and Movement

To ensure correct actuator operation, use the datasheet to configure ELEVATION_ACTUATOR_SPEED and ELEVATION_ACTUATOR_LENGTH. These parameters calculate the time required to fully extend or retract the actuator. If real-world conditions vary, override this time using the FORCE_TIME_FULL_TRAVEL parameter.

Warning: Keep the PWM speed at 255 (maximum) for accurate time calculations during extension and retraction.

At initialization, the system calibrates the actuator, setting the panel to a 90° (horizontal) position for safety. The elevation range is constrained by the actuator’s length and physical limits of the panel. Customize ELEVATION_DEG_MIN and ELEVATION_DEG_MAX based on your setup.

I used SolidWorks to simulate the panel’s movement and constraints.

Key Parameters in config.h

ParameterValue
ELEVATION_MOTOR_PIN_ENMotor enable pin
ELEVATION_MOTOR_PWM_PIN_UPWM pin for extension (up)
ELEVATION_MOTOR_PWM_PIN_DPWM pin for retraction (down)
ELEVATION_DEG_MAX90.0°
ELEVATION_DEG_MIN19.0°
ELEVATION_MOTOR_PWM_SPEED255 (maximum motor speed)
ELEVATION_ACTUATOR_SPEED5 mm/s
ELEVATION_ACTUATOR_LENGTH350 mm
FORCE_TIME_FULL_TRAVELForced full travel time (in seconds)

Anemometer Control Overview

Anemometer

The anemometer is a 3-wire sensor that operates independently from the solar tracker. It monitors wind speeds and ensures the safety of the solar panel during high wind conditions. When the wind speed exceeds 5 m/s, the anemometer activates a relay, sending an alarm signal to the solar tracker.

The solar tracker continuously monitors the alarm signal through a dedicated GPIO pin. If the wind speed exceeds 5 m/s, the tracker moves the solar panel to a safety position for 15 minutes. If the wind speed remains high and the alarm is triggered again during this countdown, the 15-minute timer resets. The panel remains in the safety position until wind conditions stabilize.

Pin Configuration for Anemometer

ComponentArduinoESP32
Wind Alarm Detection PinPin 11GPIO 13

Key Parameters in config.h

ParameterValue
ANEMOMETER_BUTTON_PINPin for alarm detection
ANEMOMETER_SAFE_DURATION15 minutes (900,000 ms)

Here’s an updated version of the Joystick Control Overview:


Joystick Control Overview

The joystick allows manual control of the solar panel's movement. By moving the joystick, the user can command the system to adjust the panel’s azimuth (horizontal) and elevation (vertical) angles, according to the inputs detected on the VRX and VRY pins. Additionally, user have to press the joystick button for 5 seconds to enable the joystick control. Same action to disable it.

Pin Configuration for Joystick

ComponentArduinoESP32
VRX Pin (Horizontal)A0GPIO 32
VRY Pin (Vertical)A1GPIO 33
Button Pin (Switch)Pin 2GPIO 25

MQTT Support Overview

The MQTT protocol is used to communicate with the Home Assistant platform. The solar tracker publishes data to the MQTT broker, which is then read by Home Assistant to display the solar panel’s information. The system has been made with automatic discovery, allowing Home Assistant to recognize the solar tracker and its entities.

MQTT

Web Server Overview

The ESP32 version of the solar tracker includes a web server that allows users to configure the system via a web interface.

Warning: Exercise caution when working with the web server, as it can permanently override default settings. For instance, you could lose the Wi-Fi connection and be unable to reconnect until the flash memory is erased.

Web Server

Hardware Used

This is a non-exhaustive list of the components used in this project:

ComponentLink
ESP32 Devkithttps://www.amazon.fr/dp/B0CLD28SHQ
ESP32 Expansion BoardDelivered with the ESP32 Devkit
2x BTS7960 Motor Drivershttps://www.amazon.fr/dp/B09MHNG2JS
RTC DS3231https://www.amazon.fr/dp/B077XN4LL4
Joystickhttps://amzn.eu/d/ecQA6IR
Anemometerhttps://amzn.eu/d/ea2Sudf
DC Motor 12Vhttps://amzn.eu/d/i2e7lmb
Linear Actuatorhttps://www.amazon.fr/dp/B0CWN28GFL
Limit Switch TZ-8122https://amzn.eu/d/7rvahQ4

Special thanks to the SolTrack library

Thanks to the soltrack-2.2 library. This library is used to calculate the sun's position based on the date, time, and location. The library provides the azimuth and elevation angles of the sun, which are used to adjust the solar panel's position.

About

Solar tracker system with ARDUINO or ESP32

Resources

Stars

15 stars

Watchers

2 watching

Forks

Contributors

Languages