Project tutorial
Internet of things (IoT)-based solar tracker

Internet of things (IoT)-based solar tracker © MIT

The proposed IoT solution can be employed in various fields to connect devices or things to the internet.

  • 5 views
  • 0 comments
  • 0 respects

Components and supplies

Apps and online services

About this project

This project presents a simple and low-cost IoT solution to monitor and control a smart dual-axis solar tracker system for performance evaluation.

Internet of Things (IoT)-based solar tracker

The proposed IoT-based solar tracker system is depicted in Fig. 1. It is a dual-axis solar tracker that can rotate automatically to track the sun's position using LDR sensors, or manually by the user through the dashboard of an IoT application. The system starts with detects the sun position (intensity of light) by LDR sensors and sends the data to the controller (Arduino Mega board). This latter then processes these data to command servomotors (SM1 and SM2) that hold the PV panel to rotate toward the sun. The values of the generated PV voltage and current, temperature and humidity are also sent to the Arduino through associated sensors. Next, the Ethernet shield, which is mounted with Arduino and allows it to be connected to the Internet, will send the data that have been taking and/or processed by Arduino to the cloud (webserver). Lastly, the solar tracker data, including LDR sensors, PV power, temperature and humidity, are displayed in real-time in the IoT monitoring application via pre-created widgets. The IoT monitoring application is designed using Cayenne myDevicesplatform. Once the user is connected to the internet from his computer or smartphone, he can visualize, in the dashboard of the IoT application, all solar tracker data in their associated widgets. Therefore, the user has the necessary data linked to the environment and performance of the PV panel. In addition, in the manual mode, the servomotors will take angle directions from their associated widgets in the dashboard. Hence, the user can control his system to seek the best environmental conditions and extract the maximum energy from the PV panel. The IoT application is also programmed to send notification alerts (SMS or Email) when a senor reaches a predefined threshold value.

Hardware design

As shown in Fig. 2, the IoT solar tracker system consists of a PV panel, two servo motors, four LDR sensors, a voltage divider circuit, a temperature and humidity sensor, a Led and the Arduino Mega board.

The used PV panel is 115 mm by 85mm in size with a 1.6 W output and can generates a voltage up to 6 V. Two 180 degrees servomotors are used to motorize the solar tracker and they are controlled by the Arduino board through PWM pins 5 and 6. The left-right (L-R) servo motor (MG996R) rotates the solar tracker on the vertical axis (East/West), while the Up-down (U-D) servo motor (SG90) rotates the solar tracker on the horizontal axis (South/North).

Four LDRs (Cds GL5528) are used to sense the sun's position and which have been fixed in the four corners of the panel. The LDR sensors are connected to the Arduino through analog pins fromA0 to A3. The LDR is a resistor whose value decreases with increasing light intensity incident on its surface. The LDR sensor is designed as a voltage divider circuit as can be seen in Fig. 2. The divider output voltage is converted by the microcontroller of the Arduino Mega from the analog value into a digital value between 0 and 1023. Because the Analog to Digital Converter(ADC) of the microcontroller is coded in 10 bits. The value of the series resistor in the LDR sensor circuit is 330 Ω.

The temperature and humidity are measured through the DHT22 sensor. DHT22 has a thermistor and a capacitive humidity sensor embedded in it to measure temperature and relative humidity. Its temperature range is from -40 to 80 °Cwith < ±0.5°C of accuracy, and its humidity range is from 0 to 100 % with±2% (Max ±5%) of accuracy. This sensor uses one signal wire to transmit data to Arduino (digital pin 2), and two wires for the power supply.

The PV voltage and current are measured through a voltage divider circuit that acts also as a load and which consists of two series resistors of 10 Ohms. The divider circuit output is connected to the Arduino's analog pin A4. Furthermore, a LED, which is connected to digital pin 3, reflects in the system circuit the mode state of the solar tracker (manual or automatic).

The Arduino Mega withATmega2560 microcontroller is used as the embedded controller that interacts with the Arduino Ethernet shield along with the monitoring platform. The TheEthernet shield, which is mounted above the Arduino board, must be connected with a Wi-Fi router (or PC) through an RJ45 cable as shown in Fig. 3. The Ethernet Shield is based on the Wiznet W5100 Ethernet chip that provides a network(IP) stack for TCP and UDP protocols.

Software design

a. Arduino IDE

Arduino is an open-source electronics prototyping platform with easy-to-use hardware and software. The Arduino platform provides an integrated development environment (IDE), which includes support for C and C++ programming languages. The used Arduino board in this work is programmed by the IDE that serves as a code editor and from which the program code can be uploaded to the microcontroller through a USB cable, as can be shown in Fig. 3. The Arduino Mega board is utilized to implement all software requirements of the IoT-based solar tracker.

b. myDevices Cayenne

MyDevices is a company that offers IoT solutions. It offers an end-to-end platform for the IoT. In our project, we will focus on Cayenne, one of the solutions from myDevices. This tool allows developers, designers and engineers to build prototypes of the IoT. Cayenne uses the Message QueuingTelemetry Transport (MQTT) protocol to connect any device with Cayennecloud. Once connected, the user can send and receive data from the device to the Cayenne dashboard via the Widgets created. MQTT is a publish-subscribe messaging protocol based on the TCP/IP protocol. The publish-subscribe methodology uses a message agent that is responsible for delivering messages to the client. MQTT is the API for sending information to the Cayenne cloud or devices controlled by Cayenne. The message agent in this connection is the cloud, it manages the different clients (sensors and actuators) that send and receive the data.

To use MQTT with Cayenne, we need to use the Cayenne libraries. For Arduino, the CayenneMQTT library can be installed from the IDE's Library Manager. To program our Cayenne IoT platform-based IoT application, we will take advantage of the predefined functions. For example, to establish the connection between Cayenne cloud and Arduino Mega equipped with the Ethernet module, we call the CayenneMQTTEthernet library where we declare our authentication information (the username, password and the Client ID)which should be obtained from the Cayenne Dashboard. Then, in the setup part of the program, we call Cayenne.begin ()function to establish the connection with Cayenne dashboard. For each actuator, we create a function with an integer parameter between 0 and 31 imperatively called CAYENNE IN (VIRTUAL CHANNEL). For each sensor, we create a function with an integer parameter between 0 and 31imperatively called CAYENNE_OUT (VIRTUAL_CHANNEL). In the loop part of the program, we call the predefined function Cayenne.loop (), this function itself calls the functions CAYENNE_OUT and CAYENNE_IN. The virtual channel as its name suggests is a channel that does not physically exist, it characterizes visualization or command widgets. It allows them to be linked with the corresponding sensor or actuator.

c.The embeddedsoftware design

The embedded software is the piece that will be embedded in the Arduino Mega to interact between the Ethernet module and Cayenne cloud (see Appendix). It is designed as follow:

(i) The IoT-based solar tracker has two function modes:manual and automatic. A button created in the Cayenne dashboard has a role to switch between the two modes. When it is inactive, the manual mode is selected, otherwise automatic mode. Besides, a function is established in the Arduino code that allows recovering the state of the button. The LED in the system circuit reflects the state of this switch.

Therefore, for the controller to know the selected operating mode, we just need to test the state of the pin in which the LED is connected. For example, if the LED state is low, the controller will call the manual mode function to execute, otherwise, it will call the automatic function.

(ii) If the manual mode is selected, the user can directly control the positions of the servomotors to orient the PV panel from east to west by L-R servomotor or from south to north by the U-D servomotor. The control is made from the associated widgets of servomotors in the dashboard of the IoT application.

In this mode, the controller calls Cayenne.loop() function which itself calls all the functions CAYENNE_IN, including those related to servomotors, to execute. The Cayenne.loop() function will also call all the functions CAYENNE_OUT, linked to the sensors, to execute. Where the data related to LDR sensors, PV current, voltage and power, temperature and humidity would be sent to the server so that they can be visualized in their associated widgets in the IoT application.

(iii) If the automatic mode is selected, the algorithm shown in Fig. 4 will be executed. The algorithm starts by reading the analog values returned by LDR sensors. Then, it processes these data to command servomotors that move the PV panel toward the sun position. Considering the vertical axis-based solar tracker movement, the average values ​​of the two LDRs on the left and the two LDRs on the right are compared and If the lefts receive more light, the PV panel will move in that direction (clockwise) through the L-R servomotor. The latter will stop when the difference result is between -10 and 10. This range is used to stabilize the controller and to reduce the power consumption of servomotors. Otherwise, if the right set of LDRs receive more light, the PV panel will move in that direction (Counterclockwise) through the L-R servomotor and will continue to rotate until the difference result is in the range [−10, 10]. The same approach is used for the horizontal axis-based solar tracker movement where the average values ​​of the two LDRs on the top and the two LDRs on the bottom are compared.

As well as in the automatic mode, the controller will also call the Cayenne.loop() function to send the solar tracker data to the IoT application.

d.Development of the IoT monitoring application

(i) Hardwareinterfacing with Cayenne IoT platform

To interface the hardware, including sensors and actuators, with the IoT platform, we need to follow the next steps:

+ Log in on Cayenne myDevice website after creating an account(Fig. 5(a)).

+ Then, click on “Bring Your Own Things” from Cayenne API (Fig. 5(b)).

+ Copy the MQTT credentials (username, password and client ID) from Crete App (Fig. 6), and paste them in Arduino source code as described previously. After successfully compiling and uploading the entire code to Arduino Mega, open Serial Monitor in Arduino IDE to get the Cayenne log prints(Fig. 7). As soon as our device comes online and connects to Cayenne, the previous page (Fig. 6) is automatically updated and we will see our device in the online dashboard as can be seen in Fig. 8.

+ Then, to interface sensors and actuators, i.e. create their widgets, click on "Add new…”, select "Device/Widget" and clickon "Custom Widgets" (Fig. 9). Then, select a widget and populate allits associated settings (the channel number must be the same as in code), and finally, click on "Add Widget" to add it to the dashboard of your device. For us, we chose the "value" widget for all sensors, "Button" widget for mode switch and the "Slider" widget for servomotor.

Finally, Fig. 10 illustrates the designed IoT application for monitoring solar tracker data. Once the connection with the solar tracker system is established, sensor data can be visualized on their associated widgets, the tracking mode (automatic or manual) can beselected from the switch button, as well as controlling servomotors' angles through their widgets. Sensor data can also be obtained in graphical form by modifying the representation type in their settings, or just by clicking on thegraph icon above the widget.

(ii) Alerts creation

One of the most important criteria in a monitoring system is its ability to send notification alerts to inform users when an event, related to their monitored devices, occurs. To this end, we take advantage of one of Cayenne'sfeatures to add alerts to our IoT application, where we can preprogram our application to send a notification alert (SMS, Email, or both) or to perform a specified action. For example, a temperature alert is created to send an email notification to the user (or recipients) when the monitored temperature is reached a threshold value, as can be shown in Fig. 11. To create an alert, click on "Add new..." and select "Trigger", then set the event and its action and finally click on “save” to add it to the dashboard.

Prototype

Fig. 12 presents the solar tracker prototype in its detached and assembled state. It consists of the PV panel, the-R and U-D servomotors and LDR sensors. The panel is attached to the U-Dservomotor on one side and with a bearing on the other side to ensure better flexibility when the solar tracker rotates around the horizontal axis. The assembly is attached to the L-R servomotor. The LDR sensors are fixed in the four corners of the panel inside hollow cylinders. If the panel is not perpendicular to the sun, at least one LDR will be covered by shadow caused by the surrounding cylinder. Hence, there will be a difference in light intensity. The best orientation is when the light intensities are equal in all LDR sensors. Fig. 13 shows the entire prototype of the IoT-based solar tracker system, and it is clear that all reported components in the hardware part have been used to build it.

For more details on the results obtained, refer to the paper in this link : https://link.springer.com/chapter/10.1007%2F978-3-030-64565-6_4

Code

The embedded code of the IoT-based solar tracker systemArduino
/***************************************************************
 PROJECT: IoT based solar tracker system / the embedded software
 Aboubakr El Hammoumi/ aboubakr.elhammoumi@usmba.ac.ma
***************************************************************/

#define CAYENNE_PRINT Serial
#include <CayenneMQTTEthernet.h>    //CayenneMQTT library 
#include <Servo.h>                  //Servo motor library 
#include <DHT.h>                    //DHT library 
#define DHTTYPE DHT22
#define DHTPIN 2
DHT dht(DHTPIN,DHTTYPE);

//MQTT credentials   
char username[]="498d2d00-afe2-11ea-883c-638d8ce4c23d";
char password[]="ab4a8f92d94033c01f6e18ce1d8a84d8c304c9c4";
char clientID[]="17798a40-b968-11ea-93bf-d33a96695544";

Servo servo_x;                   //up-down servomotor  
int servoh = 0;
int servohLimitHigh = 170;     
int servohLimitLow = 10;       

Servo servo_z;                   //left-right servomotor 
int servov = 0; 
int servovLimitHigh = 170;
int servovLimitLow = 10;

int topl,topr,botl,botr;
int threshold_value=10;        
float Vout;

void setup()
{ Serial.begin(9600);
  Cayenne.begin(username, password, clientID);
  servo_x.attach(5);
  servo_z.attach(6);
  dht.begin();
  pinMode(3,OUTPUT);
  digitalWrite(3,LOW); 
}

void loop()
{ topr= analogRead(A2);       
  topl= analogRead(A3);         
  botl= analogRead(A4);         
  botr= analogRead(A5);        
  Vout=(analogRead(A1) * 5.0) / 1023;
  Serial.println(" Manual-mode");
  Cayenne.loop();
  
  if (digitalRead(3)==HIGH){
    Serial.println(" Automatic-mode");
    servoh = servo_x.read();
    servov = servo_z.read();
    int avgtop = (topr + topl) / 2;     
    int avgbot = (botr + botl) / 2;   
    int avgright = (topr + botr) / 2;   
    int avgleft = (topl + botl) / 2;    
    int diffhori= avgtop - avgbot;      
    int diffverti= avgleft - avgright;    
    
    /*tracking according to horizontal axis*/ 
    if (abs(diffhori) <= threshold_value)
    {
     servo_x.write(servoh);            //stop the servo up-down
    }else {
       if (diffhori > threshold_value)
          { Serial.println(" x - 2 ");
          servo_x.write(servoh -2);    //Clockwise rotation CW
          if (servoh > servohLimitHigh)
          {
           servoh = servohLimitHigh;
          }
          delay(10);
          }else {
           servo_x.write(servoh +2);   //CCW
           if (servoh < servohLimitLow)
           {
           servoh = servohLimitLow;
           }
           delay(10);
           }
      }      
    /*tracking according to vertical axis*/ 
    if (abs(diffverti) <= threshold_value)
    {     
     servo_z.write(servov);       //stop the servo left-right
    }else{
       if (diffverti > threshold_value)
       { 
       servo_z.write(servov -2);  //CW
       if (servov > servovLimitHigh) 
       { 
       servov = servovLimitHigh;
       }
       delay(10);
       }else{ 
        servo_z.write(servov +2);  //CCW
        if (servov < servovLimitLow) 
        {
        servov = servovLimitLow;
        }
        delay(10);
        }
     }
  }
}
// Cayenne Functions
CAYENNE_IN(8){
  int value = getValue.asInt();
  CAYENNE_LOG("Channel %d, pin %d, value %d", 8, 3, value);
  digitalWrite(3,value);
}
CAYENNE_IN(7){ //up-down servo motor
  if (digitalRead(3)==HIGH){ //Automatic_mode
  }
  else{ //Manual_mode
  servo_x.write(getValue.asDouble() * 180);
  }
}
CAYENNE_IN(6){ //left-right servo motor
  if (digitalRead(3)==HIGH){
  }  
  else{
  servo_z.write(getValue.asDouble() * 180);
  }
}

CAYENNE_OUT(0) { //Current
  float current = Vout/10;
  Cayenne.virtualWrite(0, current);
  Serial.print("Current: ");
  Serial.println(current);
}
CAYENNE_OUT(1) { //Voltage
  float voltage = Vout * 2;
  Cayenne.virtualWrite(1, voltage);
  Serial.print("Voltage: ");
  Serial.println(voltage);
}
CAYENNE_OUT(2){ //LDR Top-right
  Cayenne.virtualWrite(2, topr);
}
CAYENNE_OUT(3){ //LDR Top-left
  Cayenne.virtualWrite(3,topl);
}
CAYENNE_OUT(4){ //LDR Bot-left
  Cayenne.virtualWrite(4,botl);
}
CAYENNE_OUT(5){ //LDR Bot-right
  Cayenne.virtualWrite(5,botr);
}
CAYENNE_OUT(10) { //Power
  float power = (Vout * 2 * Vout)/10 ;
  Cayenne.virtualWrite(10, power);
  Serial.print("Power: ");
  Serial.println(power);
}
CAYENNE_OUT(11){ //Temperature
  float t = dht.readTemperature();
  //int chk = dht.read(DHT11PIN);
  Cayenne.virtualWrite(11, t, TYPE_TEMPERATURE, UNIT_CELSIUS);
  Serial.print("temperature: ");
  Serial.println(t);
}
CAYENNE_OUT(12){ //Huidity
  float h = dht.readHumidity();
  //int chk = dht.read(DHT11PIN);
  Cayenne.virtualWrite(12, h);
  Serial.print("  humidity: ");
  Serial.println(h);
}

Schematics

The electronic circuit of the IoT-based solar tracker
Electronic circuit of the iot based solar tracker system 1mfwhk4idy

Comments

Similar projects you might like

Arduino Solar Tracker

Project tutorial by Saad Motahhir and Aboubakr_El Hammoumi

  • 28,840 views
  • 11 comments
  • 22 respects

Mega Solar Tracker

Project in progress by Team Trouble

  • 15,357 views
  • 15 comments
  • 67 respects

DIY Solar Tracker Arduino Project ITA

Project tutorial by Ingeimaks Ingeimaks

  • 39,552 views
  • 6 comments
  • 37 respects

Home Automation and Internet of Things

Project showcase by IETI_Robert

  • 5,993 views
  • 5 comments
  • 20 respects

Solar Tracker V2.0

Project tutorial by Brown Dog Gadgets

  • 33,410 views
  • 4 comments
  • 96 respects

Solar Panel Sun Tracker - Phone Charger

Project tutorial by FIELDING

  • 82,774 views
  • 22 comments
  • 247 respects
Add projectSign up / Login