Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
walkingnewbieteddyyoonie
Published © GPL3+

Solar irradiance comparison fixed vs. tracking

Compares solar irradiance performance between fixed system and a tracking system

IntermediateFull instructions provided604
Solar irradiance comparison fixed vs. tracking

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
5.5V 80mA Solar Panel
×2
Resistor 10k ohm
Resistor 10k ohm
×2
Resistor 22.1 ohm
Resistor 22.1 ohm
×2
Breadboard (generic)
Breadboard (generic)
×1
Nema 17 Stepper Motor
×1
Stepper motor driver board A4988
SparkFun Stepper motor driver board A4988
×1
12V 2A Power Supply AC Adapter
×1
MG995 servo motor
×1

Story

Read more

Custom parts and enclosures

Assembly of tracking panel

Schematics

Full Measurement system

Code

Stepper Motor test

Arduino
/*
 *12V motor: A4988 - orientation
*/

#include <Arduino.h>

#define DIR_PIN   2 //direction
#define STEP_PIN  3 //step

const int stepPause = 15; // micro seconds between step motor input pulses
const float stepAngle = 1.8;  //1.8deg/step
float orientation = 180.;  // current orientation

void setup()
{
  //set pin modes
  pinMode(DIR_PIN, OUTPUT);
  pinMode(STEP_PIN, OUTPUT);
  
  digitalWrite(DIR_PIN, LOW); //LOW = CW, HIGH = CCW
  digitalWrite(STEP_PIN, LOW);
  
  Serial.begin(9600);
  Serial.println("Booting");
}

void loop()
{
  Serial.print("Orientation: ");
  Serial.println(orientation);

  moveTo(90);
  delay(1000);
  Serial.print("Orientation: ");
  Serial.println(orientation);

  moveTo(135);
  delay(1000);
  Serial.print("Orientation: ");
  Serial.println(orientation);

  moveTo(180);
  delay(1000);
  Serial.print("Orientation: ");
  Serial.println(orientation);

  moveTo(225);
  delay(1000);
  Serial.print("Orientation: ");
  Serial.println(orientation);

  moveTo(270);
  delay(1000);
  Serial.print("Orientation: ");
  Serial.println(orientation);

  moveTo(180);
  delay(1000);
  Serial.print("Orientation: ");
  Serial.println(orientation);
}

void moveSteps(int steps)
{
  if (steps > 0)
    digitalWrite(DIR_PIN, LOW); //LOW or HIGH
  else
    digitalWrite(DIR_PIN, HIGH);
    
  for (int i = 0; i < abs(steps); i++)
  {
    digitalWrite(STEP_PIN, HIGH);    
    delay(stepPause);
    digitalWrite(STEP_PIN, LOW);      
    delay(stepPause);
  }
}

void moveTo(float angle)
{
  int steps = round((angle - orientation) / stepAngle);
  orientation += steps * stepAngle;
  moveSteps(steps);
}

Stepper Motor & Servo Motor Test

Arduino
/*
 *12V motor: A4988 - orientation
 * MG995 Servo motor - tilt angle
*/

#include <Arduino.h>
#include <Servo.h> // include servo library

#define DIR_PIN   2 //direction
#define STEP_PIN  3 //step
#define MG995_IN 6 // Name Digital D6 pin of Arduinol

Servo mg995Servo;  // Initialize a servo object

const int stepPause = 15; // micro seconds between step motor input pulses
const float stepAngle = 1.8;  //1.8deg/step
float orientation = 180.;  // current orientation
int count = 0; // int to count loop iteration

float orient[] = {77.8, 79.9, 81.9, 84.0, 86.1, 88.2, 90.5, 92.8, 95.3, 98.0, 
                  100.9, 104.0, 107.5, 111.5, 116.1, 121.5, 127.9, 135.7, 145.1, 156.3,
                   169.2, 183.0, 196.6, 208.8, 219.3, 227.9, 235.0, 241.0, 246.0, 250.3,
                   254.0, 257.4, 260.4, 263.2, 265.8, 268.2, 270.5, 272.7, 274.8, 276.9, 
                   279.0};
float tilt[] = {23.0, 25.9, 28.8, 31.8, 34.8, 37.7, 40.7, 43.7, 46.7, 49.6,
                52.6, 55.5, 58.4, 61.2, 63.9, 66.5, 69.0, 71.2, 73.1, 74.5,
                 75.4, 75.6, 75.1, 74.0, 72.3, 70.2, 67.9, 65.4, 62.7, 59.9,
                 57.1, 54.2, 51.3, 48.3, 45.4, 42.4, 39.4, 36.4, 33.5, 30.5, 
                 27.5};

void setup()
{
  //set pin modes
  pinMode(DIR_PIN, OUTPUT);
  pinMode(STEP_PIN, OUTPUT);
  
  digitalWrite(DIR_PIN, LOW); //LOW = CW, HIGH = CCW
  digitalWrite(STEP_PIN, LOW);
  
  Serial.begin(9600);
  mg995Servo.attach(MG995_IN);  // Attach signal pin of MG995 to D6 pin
  
}

void loop()
{
  int iter = count % 41;

  moveTo(orient[iter]);
  mg995Servo.write(tilt[iter]);
  Serial.print(count);
  Serial.print(",");
  Serial.print(orientation);
  Serial.print(",");
  Serial.println(tilt[iter]);

  delay(500); // sets the interval between orientations

  count++;

}

void moveSteps(int steps)
{
  if (steps > 0)
    digitalWrite(DIR_PIN, LOW); //LOW or HIGH
  else
    digitalWrite(DIR_PIN, HIGH);
    
  for (int i = 0; i < abs(steps); i++)
  {
    digitalWrite(STEP_PIN, HIGH);    
    delay(stepPause);
    digitalWrite(STEP_PIN, LOW);      
    delay(stepPause);
  }
}

void moveTo(float angle)
{
  int steps = round((angle - orientation) / stepAngle);
  orientation += steps * stepAngle;
  moveSteps(steps);
}

Main Test Program

Arduino
/*
 *12V motor: A4988 - orientation
 * MG995 Servo motor - tilt angle
 * 
 * Solar panel terminals to Arduino:
  analog in A0 -- panel 1 -- fixed
  analog in A1 -- panel 2 -- tracking

*/

#include <Arduino.h>
#include <Servo.h> // include servo library

#define DIR_PIN   2 //direction
#define STEP_PIN  3 //step
#define MG995_IN 6 // Name Digital D6 pin of Arduinol

Servo mg995Servo;  // Initialize a servo object

const int stepPause = 15; // micro seconds between step motor input pulses
const float stepAngle = 1.8;  //1.8deg/step
float orientation = 180.;  // current orientation
int count = 0; // int to count loop iteration

int analogPin1 = A0;  //solar panel #1
int analogPin2 = A1;  //solar panel #2
                    
float orient[] = {77.8, 79.9, 81.9, 84.0, 86.1, 88.2, 90.5, 92.8, 95.3, 98.0, 
                  100.9, 104.0, 107.5, 111.5, 116.1, 121.5, 127.9, 135.7, 145.1, 156.3,
                   169.2, 183.0, 196.6, 208.8, 219.3, 227.9, 235.0, 241.0, 246.0, 250.3,
                   254.0, 257.4, 260.4, 263.2, 265.8, 268.2, 270.5, 272.7, 274.8, 276.9, 
                   279.0};
float tilt[] = {23.0, 25.9, 28.8, 31.8, 34.8, 37.7, 40.7, 43.7, 46.7, 49.6,
                52.6, 55.5, 58.4, 61.2, 63.9, 66.5, 69.0, 71.2, 73.1, 74.5,
                 75.4, 75.6, 75.1, 74.0, 72.3, 70.2, 67.9, 65.4, 62.7, 59.9,
                 57.1, 54.2, 51.3, 48.3, 45.4, 42.4, 39.4, 36.4, 33.5, 30.5, 
                 27.5};

void setup()
{
  Serial.begin(9600);

  for (int i = 10; i > 0; i--)
  {  
    Serial.print(i); 
    Serial.print(", "); 
    delay(1000);
  }
  Serial.println(" "); 
      
  //set pin modes
  pinMode(DIR_PIN, OUTPUT);
  pinMode(STEP_PIN, OUTPUT);
  
  digitalWrite(DIR_PIN, LOW); //LOW = CW, HIGH = CCW
  digitalWrite(STEP_PIN, LOW);
  
  mg995Servo.attach(MG995_IN);  // Attach signal pin of MG995 to D6 pin

  
}

void loop()
{
  // start of operation
  int iter = count % 41;

  moveTo(orient[iter]);
  mg995Servo.write(tilt[iter]);
  Serial.print(count);
  Serial.print(",");
  Serial.print(orientation);
  Serial.print(",");
  Serial.println(tilt[iter]);

  // read panel data
  analogReference(DEFAULT);
  readPanelData(); // Call readPanleData() function
  delay(60000 * 15); // sets the interval between orientations

  count++;
}

void moveSteps(int steps)
{
  if (steps > 0)
    digitalWrite(DIR_PIN, LOW); //LOW or HIGH
  else
    digitalWrite(DIR_PIN, HIGH);
    
  for (int i = 0; i < abs(steps); i++)
  {
    digitalWrite(STEP_PIN, HIGH);    
    delay(stepPause);
    digitalWrite(STEP_PIN, LOW);      
    delay(stepPause);
  }
}

void moveTo(float angle)
{
  int steps = round((angle - orientation) / stepAngle);
  orientation += steps * stepAngle;
  moveSteps(steps);
}

void readPanelData() {

  Serial.print(count); 
  Serial.print(","); 

  int val1 = analogRead(analogPin1);
  delay(100);
  int val2 = analogRead(analogPin1);
  delay(100);
  int val = int((val1 + val2)/2); // average
  Serial.print(val); 
  Serial.print(",");   
  delay(100);

  val1 = analogRead(analogPin2);
  delay(100);
  val2 = analogRead(analogPin2);
  delay(100);
  val = int((val1 + val2)/2); // average

  Serial.println(val); 
}

Credits

walkingnewbie

walkingnewbie

2 projects • 2 followers
teddyyoonie

teddyyoonie

3 projects • 1 follower

Comments