Solar Tracker (ESP32 & MicroPython)

by youssef alaoui in Teachers > University+

7081 Views, 11 Favorites, 0 Comments

Solar Tracker (ESP32 & MicroPython)

micropython (1).png

buy complete kit

The energy extracted from solar radiation is an inexhaustible resource that is available in large quantities, provided that we have the means to exploit it efficiently. Therefore, the solar tracker plays a major role in raising the efficiency of solar panels.

Objective :

Our goal is to create, design and realize a simple, low-cost, dual-axis intelligent solar tracking system using a photoresistors (L.D.R.),a solar panel and an electronic circuit allow the system to rotate both vertically and horizontally, based on a tracking technique to actively follow the solar radiation and adjust the panel accordingly to maximize energy production and provide better performance.

Who can benefit from this prototype?

The simple design of our system allows it to be used in a science project or as a classroom demonstration, it is dedicated also for students and hobbyists.

To make it simple, we divided this project into several steps to make it easy to be understood and built.

How Does a Dual Axis Solar Tracker Work?

Let's start by Functional principle of the dual axis solar tracker:

Solar trackers are used to continuously direct the solar panel towards the sun's rays, thus maximizing the expectations from this system.

This system effectively tracks the position of the sun and generates more electricity than its counterparts due to the increased direct exposure to sunlight.

This design consists of a model that focuses on the use of a solar panel that would follow the movement of the sun, i.e. azimuthal altitude, automatically adjusting itself each time without human intervention.

To do this, we use photoresistors (L.D.Rs) which will follow the sunlight at each moment and give a signal to the main circuit for the movement of the panel. The movement of the panel will be done by means of two direct current servo motors. All electrical components will be controlled by developed electronic circuitry. The two-axis tracking ensures that the panel is always in the most accurate position for best performance.

In a dual-axis tracker, the panel consists of four LDRs which are used to track the exact position of the sun along the tilt axis and the azimuth axis.

These LDRs are divided into: Top, Bottom, Right and Left, the program works by comparing the resistance of the four LDRs two by two this information is sent to the comparison unit, which is the main control unit for the entire system and determines the direction of movement of the motors in the horizontal and vertical axes.

Why did we use ESP32 ?

The ability to connect to the Internet without any additions, as well as the ability to send information via Bluetooth Low Energy to the phone application, and this facilitates the collection of information about efficiency. We will add the application soon, as well as the possibility of programming via MicroPython.

The difference between Arduino and ESP32 is given by this link : https://all3dp.com/2/esp32-vs-arduino-differences/

What will you need?

The beautiful thing is that there is a complete kit that you only need to assemble with a screwdriver

If you want to design it by yourself, you can take advantage of laser cutting through the laser cutting service, as well as 3D printing through the 3D printing service, In case you need to manufacture and assemble electronic cards, you can enter from here, In case you need a rapid prototyping service, you can take advantage of here LAB360.

Supplies

tracker_solar_cutter_file_2022-May-18_08-14-36AM-000_CustomizedView21792447649 (1).png

The complete kit parts

buy complete kit

  • ESP32
  • Dual axis solar tracker support
  • 1 Solar panel
  • Dual axis sensor
  • PWM Servo Motors
  • Universal prototype board
  • Headers
  • Box for 4 batteries with interrupter on/off
  • Wood parts
  • Ball bearing
  • Bolts and nuts
  • Jumper wires (female to female)

Electronic Part


1 sensor


1 controller Esp32 (Vcc 6v battery —> Vin Esp32 and Vcc servo motor (V and H))

2 servo motors


1 solar panel Dimensions : 110x60mm ,Puissance 6V,1W


1 Box for 4 batteries with interrupteur on/off

7 Female to Female Jumper 


Mechanical Parts


1 Ball Bearing 42x30x7mm & 2 Ball Bearing 10x4x3mm


4 Bolts M4x30 & 5 Bolt M4x25 & 4 Bolts M2x10 & 10 Bolts M4x15 & 23 Nuts

Assembling

Assemblage du modèle de suiveur solaire

If you have any questions, please puts them in comments.

Preparing Esp32 for Programming With Micropython

 This part shows how to flash MicroPython firmware to ESP32 boards using the thonny IDE software. It works on Windows, Linux, and Mac OS X.

1- download and install driver (The ESP32 DEVKIT V1 DOIT board uses the CP2102 chip)

link : https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers 

2- download and install IDE thonny

link : https://thonny.org/

3- download the latest version of MicroPython firmware for the ESP32

link : https://micropython.org/download/esp32/



4- Flashing the MicroPython Firmware on ESP32

-open thonny IDE and Go to Run → Select interpreter


-in Which interpreter or device should thonny use for running your code select Micropython(Esp32)


-press Install or update firmware 


-       select the port and presse Browse.

-       After pressing the “Browse” button, navigate to your Downloads folder and select the esp32-20220618-v1.19.1.bin that you downloaded before.

-       presse install (And make sure that the checkbox Erase flash before installing is checked).

-       Wait for a few minutes for the memory to finish erasing and loading the Firmware.

Upload Code to Esp32

-Go to Run In thonny IDE

-Select in (Port or WebREPL) your port (COM3,COM5....) and presse OK

-Go to file and select Save as

Press Micropython device

In file name tape main.py and presse OK

paste your code in editor

Go to Run and select Run current script


Code Interpretation


To read analog inputs, import the ADC class in addition to the Pin class from the machine module. We also import the sleep method.

To create a PWM pin, import the PWM class from the machine module.

for mathematical functions import math module

from machine import Pin, ADC
from time import sleep
import machine
from machine import PWM
import math


Create a PWM object associated with a set pin and frequency

PIN_H = machine.Pin(13)
servoH = machine.PWM(PIN_H,freq=50)
PIN_V = machine.Pin(12)
servoV = machine.PWM(PIN_V,freq=50)


Create an ADC (Analog to Digital Converter) object called Cellul solar, LDR_BR( Ldr Bottom Right), LDR_TR(LDR Top Right), LDR_TL( LDR Top Left), LDR_BL(LDR Bottom Left) on GPIO 33, 32, 34, 35, 39 respectively.

Cellul_solar = ADC(Pin(33))
LDR_BR = ADC(Pin(32))
LDR_TR = ADC(Pin(34))
LDR_TL = ADC(Pin(35))
LDR_BL = ADC(Pin(39))


Initialization of the horizontal and vertical positions (these values are obtained by experience tests):

Configuration for Horizontal servo.

The Servo Horizontal is set to 100 degrees.

Servo Horizontal Limit When Signal is High is set to 130 degrees.

Again, Servo Horizontal Limit when Signal value is low is set to 10 degrees.

The Servo Configuration for Vertical:

The Servo Vertical is set to 100 degrees.

Servo Vertical Limit When Signal is High is set to 130 degrees.

Also, Servo Vertical Limit when Signal value is low is set to 83 degree.

Tolerance = 100
position_V = 100
position_H = 100
position_V_MIN = 83
position_H_MIN = 10
position_V_MAX = 130
position_H_MAX = 130
servoV.duty(position_V)
servoH.duty(position_H)
sleep(3)


The following line defines that we want to be able to read voltage in full range.

This means we want to read voltage from 0 to 3.3V. This corresponds to setting the attenuation ratio of 11db. For that, we use the atten() method and pass as argument: ADC.ATTN_11DB.

Cellul_solar.atten(ADC.ATTN_11DB)
LDR_BR.atten(ADC.ATTN_11DB)
LDR_TR.atten(ADC.ATTN_11DB)
LDR_TL.atten(ADC.ATTN_11DB)
LDR_BL.atten(ADC.ATTN_11DB)


These lines are about reading and printing the read values of cellular solar and LDRs, and calculation of the average of light received by each pair of LDRs (ex:Top_Light = (LDR_TR_value+LDR_TL_value)/2, Means: the top light is obtained by the average of top right and top left LDRs).

As well as the calculation of the difference between the top light and bottom light, the right light and left light in order to conclude the sense of movement.(V_Mvt: vertical movement; H_Mvt: Horizontal movement)

while True:
    Cellul_solar_value = Cellul_solar.read()
    LDR_BR_value = LDR_BR.read()
    LDR_BL_value = LDR_BL.read()
    LDR_TR_value = LDR_TR.read()
    LDR_TL_value = LDR_TL.read()
    Top_Light = (LDR_TR_value+LDR_TL_value)/2
    Bottom_Light = (LDR_BR_value+LDR_BL_value)/2
    Right_Light = (LDR_TR_value+LDR_BR_value)/2
    Lifet_Light = (LDR_TL_value+LDR_BL_value)/2
    V_Mvt = Top_Light - Bottom_Light
    H_Mvt = Right_Light - Lifet_Light


IF statements are defined to loop the program and calculate the average values of the respective LDR’s. Finally, this code helps to change the degree of the servo motor. So that it can be more effective.

(Fabs returns the absolute value, that must be compared to tolerance value)

    if(math.fabs(V_Mvt) > Tolerance):
        if(V_Mvt<0 and position_V>position_V_MIN ):
            position_V=position_V-1
            servoV.duty(position_V)
        if(V_Mvt>0 and position_V Tolerance):
        if(H_Mvt<0 and position_H0 and position_H>position_H_MIN) :
            position_H=position_H-1
            servoH.duty(position_H)
  sleep(0.03)

.