Components and supplies
Resistor 10k ohm
Breadboard (generic)
Arduino UNO
Stepper motor driver board A4988
Nema 17 Stepper Motor
Resistor 22.1 ohm
12V 2A Power Supply AC Adapter
MG995 servo motor
5.5V 80mA Solar Panel
Project description
Code
Stepper Motor test
arduino
1/* 2 *12V motor: A4988 - orientation 3*/ 4 5#include <Arduino.h> 6 7#define DIR_PIN 2 //direction 8#define STEP_PIN 3 //step 9 10const int stepPause = 15; // micro seconds between step motor input pulses 11const float stepAngle = 1.8; //1.8deg/step 12float orientation = 180.; // current orientation 13 14void setup() 15{ 16 //set pin modes 17 pinMode(DIR_PIN, OUTPUT); 18 pinMode(STEP_PIN, OUTPUT); 19 20 digitalWrite(DIR_PIN, LOW); //LOW = CW, HIGH = CCW 21 digitalWrite(STEP_PIN, LOW); 22 23 Serial.begin(9600); 24 Serial.println("Booting"); 25} 26 27void loop() 28{ 29 Serial.print("Orientation: "); 30 Serial.println(orientation); 31 32 moveTo(90); 33 delay(1000); 34 Serial.print("Orientation: "); 35 Serial.println(orientation); 36 37 moveTo(135); 38 delay(1000); 39 Serial.print("Orientation: "); 40 Serial.println(orientation); 41 42 moveTo(180); 43 delay(1000); 44 Serial.print("Orientation: "); 45 Serial.println(orientation); 46 47 moveTo(225); 48 delay(1000); 49 Serial.print("Orientation: "); 50 Serial.println(orientation); 51 52 moveTo(270); 53 delay(1000); 54 Serial.print("Orientation: "); 55 Serial.println(orientation); 56 57 moveTo(180); 58 delay(1000); 59 Serial.print("Orientation: "); 60 Serial.println(orientation); 61} 62 63void moveSteps(int steps) 64{ 65 if (steps > 0) 66 digitalWrite(DIR_PIN, LOW); //LOW or HIGH 67 else 68 digitalWrite(DIR_PIN, HIGH); 69 70 for (int i = 0; i < abs(steps); i++) 71 { 72 digitalWrite(STEP_PIN, HIGH); 73 delay(stepPause); 74 digitalWrite(STEP_PIN, LOW); 75 delay(stepPause); 76 } 77} 78 79void moveTo(float angle) 80{ 81 int steps = round((angle - orientation) / stepAngle); 82 orientation += steps * stepAngle; 83 moveSteps(steps); 84} 85
Main Test Program
arduino
1/* 2 *12V motor: A4988 - orientation 3 * MG995 Servo motor - tilt angle 4 * 5 * Solar panel terminals to Arduino: 6 analog in A0 -- panel 1 -- fixed 7 analog in A1 -- panel 2 -- tracking 8 9*/ 10 11#include <Arduino.h> 12#include <Servo.h> // include servo library 13 14#define DIR_PIN 2 //direction 15#define STEP_PIN 3 //step 16#define MG995_IN 6 // Name Digital D6 pin of Arduinol 17 18Servo mg995Servo; // Initialize a servo object 19 20const int stepPause = 15; // micro seconds between step motor input pulses 21const float stepAngle = 1.8; //1.8deg/step 22float orientation = 180.; // current orientation 23int count = 0; // int to count loop iteration 24 25int analogPin1 = A0; //solar panel #1 26int analogPin2 = A1; //solar panel #2 27 28float orient[] = {77.8, 79.9, 81.9, 84.0, 86.1, 88.2, 90.5, 92.8, 95.3, 98.0, 29 100.9, 104.0, 107.5, 111.5, 116.1, 121.5, 127.9, 135.7, 145.1, 156.3, 30 169.2, 183.0, 196.6, 208.8, 219.3, 227.9, 235.0, 241.0, 246.0, 250.3, 31 254.0, 257.4, 260.4, 263.2, 265.8, 268.2, 270.5, 272.7, 274.8, 276.9, 32 279.0}; 33float tilt[] = {23.0, 25.9, 28.8, 31.8, 34.8, 37.7, 40.7, 43.7, 46.7, 49.6, 34 52.6, 55.5, 58.4, 61.2, 63.9, 66.5, 69.0, 71.2, 73.1, 74.5, 35 75.4, 75.6, 75.1, 74.0, 72.3, 70.2, 67.9, 65.4, 62.7, 59.9, 36 57.1, 54.2, 51.3, 48.3, 45.4, 42.4, 39.4, 36.4, 33.5, 30.5, 37 27.5}; 38 39void setup() 40{ 41 Serial.begin(9600); 42 43 for (int i = 10; i > 0; i--) 44 { 45 Serial.print(i); 46 Serial.print(", "); 47 delay(1000); 48 } 49 Serial.println(" "); 50 51 //set pin modes 52 pinMode(DIR_PIN, OUTPUT); 53 pinMode(STEP_PIN, OUTPUT); 54 55 digitalWrite(DIR_PIN, LOW); //LOW = CW, HIGH = CCW 56 digitalWrite(STEP_PIN, LOW); 57 58 mg995Servo.attach(MG995_IN); // Attach signal pin of MG995 to D6 pin 59 60 61} 62 63void loop() 64{ 65 // start of operation 66 int iter = count % 41; 67 68 moveTo(orient[iter]); 69 mg995Servo.write(tilt[iter]); 70 Serial.print(count); 71 Serial.print(","); 72 Serial.print(orientation); 73 Serial.print(","); 74 Serial.println(tilt[iter]); 75 76 // read panel data 77 analogReference(DEFAULT); 78 readPanelData(); // Call readPanleData() function 79 delay(60000 * 15); // sets the interval between orientations 80 81 count++; 82} 83 84void moveSteps(int steps) 85{ 86 if (steps > 0) 87 digitalWrite(DIR_PIN, LOW); //LOW or HIGH 88 else 89 digitalWrite(DIR_PIN, HIGH); 90 91 for (int i = 0; i < abs(steps); i++) 92 { 93 digitalWrite(STEP_PIN, HIGH); 94 delay(stepPause); 95 digitalWrite(STEP_PIN, LOW); 96 delay(stepPause); 97 } 98} 99 100void moveTo(float angle) 101{ 102 int steps = round((angle - orientation) / stepAngle); 103 orientation += steps * stepAngle; 104 moveSteps(steps); 105} 106 107void readPanelData() { 108 109 Serial.print(count); 110 Serial.print(","); 111 112 int val1 = analogRead(analogPin1); 113 delay(100); 114 int val2 = analogRead(analogPin1); 115 delay(100); 116 int val = int((val1 + val2)/2); // average 117 Serial.print(val); 118 Serial.print(","); 119 delay(100); 120 121 val1 = analogRead(analogPin2); 122 delay(100); 123 val2 = analogRead(analogPin2); 124 delay(100); 125 val = int((val1 + val2)/2); // average 126 127 Serial.println(val); 128} 129
Stepper Motor & Servo Motor Test
arduino
1/* 2 *12V motor: A4988 - orientation 3 * MG995 Servo motor - tilt angle 4*/ 5 6#include <Arduino.h> 7#include <Servo.h> // include servo library 8 9#define DIR_PIN 2 //direction 10#define STEP_PIN 3 //step 11#define MG995_IN 6 // Name Digital D6 pin of Arduinol 12 13Servo mg995Servo; // Initialize a servo object 14 15const int stepPause = 15; // micro seconds between step motor input pulses 16const float stepAngle = 1.8; //1.8deg/step 17float orientation = 180.; // current orientation 18int count = 0; // int to count loop iteration 19 20float orient[] = {77.8, 79.9, 81.9, 84.0, 86.1, 88.2, 90.5, 92.8, 95.3, 98.0, 21 100.9, 104.0, 107.5, 111.5, 116.1, 121.5, 127.9, 135.7, 145.1, 156.3, 22 169.2, 183.0, 196.6, 208.8, 219.3, 227.9, 235.0, 241.0, 246.0, 250.3, 23 254.0, 257.4, 260.4, 263.2, 265.8, 268.2, 270.5, 272.7, 274.8, 276.9, 24 279.0}; 25float tilt[] = {23.0, 25.9, 28.8, 31.8, 34.8, 37.7, 40.7, 43.7, 46.7, 49.6, 26 52.6, 55.5, 58.4, 61.2, 63.9, 66.5, 69.0, 71.2, 73.1, 74.5, 27 75.4, 75.6, 75.1, 74.0, 72.3, 70.2, 67.9, 65.4, 62.7, 59.9, 28 57.1, 54.2, 51.3, 48.3, 45.4, 42.4, 39.4, 36.4, 33.5, 30.5, 29 27.5}; 30 31void setup() 32{ 33 //set pin modes 34 pinMode(DIR_PIN, OUTPUT); 35 pinMode(STEP_PIN, OUTPUT); 36 37 digitalWrite(DIR_PIN, LOW); //LOW = CW, HIGH = CCW 38 digitalWrite(STEP_PIN, LOW); 39 40 Serial.begin(9600); 41 mg995Servo.attach(MG995_IN); // Attach signal pin of MG995 to D6 pin 42 43} 44 45void loop() 46{ 47 int iter = count % 41; 48 49 moveTo(orient[iter]); 50 mg995Servo.write(tilt[iter]); 51 Serial.print(count); 52 Serial.print(","); 53 Serial.print(orientation); 54 Serial.print(","); 55 Serial.println(tilt[iter]); 56 57 delay(500); // sets the interval between orientations 58 59 count++; 60 61} 62 63void moveSteps(int steps) 64{ 65 if (steps > 0) 66 digitalWrite(DIR_PIN, LOW); //LOW or HIGH 67 else 68 digitalWrite(DIR_PIN, HIGH); 69 70 for (int i = 0; i < abs(steps); i++) 71 { 72 digitalWrite(STEP_PIN, HIGH); 73 delay(stepPause); 74 digitalWrite(STEP_PIN, LOW); 75 delay(stepPause); 76 } 77} 78 79void moveTo(float angle) 80{ 81 int steps = round((angle - orientation) / stepAngle); 82 orientation += steps * stepAngle; 83 moveSteps(steps); 84} 85
Stepper Motor test
arduino
1/* 2 *12V motor: A4988 - orientation 3*/ 4 5#include <Arduino.h> 6 7#define DIR_PIN 2 //direction 8#define STEP_PIN 3 //step 9 10const int stepPause = 15; // micro seconds between step motor input pulses 11const float stepAngle = 1.8; //1.8deg/step 12float orientation = 180.; // current orientation 13 14void setup() 15{ 16 //set pin modes 17 pinMode(DIR_PIN, OUTPUT); 18 pinMode(STEP_PIN, OUTPUT); 19 20 digitalWrite(DIR_PIN, LOW); //LOW = CW, HIGH = CCW 21 digitalWrite(STEP_PIN, LOW); 22 23 Serial.begin(9600); 24 Serial.println("Booting"); 25} 26 27void loop() 28{ 29 Serial.print("Orientation: "); 30 Serial.println(orientation); 31 32 moveTo(90); 33 delay(1000); 34 Serial.print("Orientation: "); 35 Serial.println(orientation); 36 37 moveTo(135); 38 delay(1000); 39 Serial.print("Orientation: "); 40 Serial.println(orientation); 41 42 moveTo(180); 43 delay(1000); 44 Serial.print("Orientation: "); 45 Serial.println(orientation); 46 47 moveTo(225); 48 delay(1000); 49 Serial.print("Orientation: "); 50 Serial.println(orientation); 51 52 moveTo(270); 53 delay(1000); 54 Serial.print("Orientation: "); 55 Serial.println(orientation); 56 57 moveTo(180); 58 delay(1000); 59 Serial.print("Orientation: "); 60 Serial.println(orientation); 61} 62 63void moveSteps(int steps) 64{ 65 if (steps > 0) 66 digitalWrite(DIR_PIN, LOW); //LOW or HIGH 67 else 68 digitalWrite(DIR_PIN, HIGH); 69 70 for (int i = 0; i < abs(steps); i++) 71 { 72 digitalWrite(STEP_PIN, HIGH); 73 delay(stepPause); 74 digitalWrite(STEP_PIN, LOW); 75 delay(stepPause); 76 } 77} 78 79void moveTo(float angle) 80{ 81 int steps = round((angle - orientation) / stepAngle); 82 orientation += steps * stepAngle; 83 moveSteps(steps); 84} 85
Stepper Motor & Servo Motor Test
arduino
1/* 2 *12V motor: A4988 - orientation 3 * MG995 Servo motor - tilt angle 4*/ 5 6#include <Arduino.h> 7#include <Servo.h> // include servo library 8 9#define DIR_PIN 2 //direction 10#define STEP_PIN 3 //step 11#define MG995_IN 6 // Name Digital D6 pin of Arduinol 12 13Servo mg995Servo; // Initialize a servo object 14 15const int stepPause = 15; // micro seconds between step motor input pulses 16const float stepAngle = 1.8; //1.8deg/step 17float orientation = 180.; // current orientation 18int count = 0; // int to count loop iteration 19 20float orient[] = {77.8, 79.9, 81.9, 84.0, 86.1, 88.2, 90.5, 92.8, 95.3, 98.0, 21 100.9, 104.0, 107.5, 111.5, 116.1, 121.5, 127.9, 135.7, 145.1, 156.3, 22 169.2, 183.0, 196.6, 208.8, 219.3, 227.9, 235.0, 241.0, 246.0, 250.3, 23 254.0, 257.4, 260.4, 263.2, 265.8, 268.2, 270.5, 272.7, 274.8, 276.9, 24 279.0}; 25float tilt[] = {23.0, 25.9, 28.8, 31.8, 34.8, 37.7, 40.7, 43.7, 46.7, 49.6, 26 52.6, 55.5, 58.4, 61.2, 63.9, 66.5, 69.0, 71.2, 73.1, 74.5, 27 75.4, 75.6, 75.1, 74.0, 72.3, 70.2, 67.9, 65.4, 62.7, 59.9, 28 57.1, 54.2, 51.3, 48.3, 45.4, 42.4, 39.4, 36.4, 33.5, 30.5, 29 27.5}; 30 31void setup() 32{ 33 //set pin modes 34 pinMode(DIR_PIN, OUTPUT); 35 pinMode(STEP_PIN, OUTPUT); 36 37 digitalWrite(DIR_PIN, LOW); //LOW = CW, HIGH = CCW 38 digitalWrite(STEP_PIN, LOW); 39 40 Serial.begin(9600); 41 mg995Servo.attach(MG995_IN); // Attach signal pin of MG995 to D6 pin 42 43} 44 45void loop() 46{ 47 int iter = count % 41; 48 49 moveTo(orient[iter]); 50 mg995Servo.write(tilt[iter]); 51 Serial.print(count); 52 Serial.print(","); 53 Serial.print(orientation); 54 Serial.print(","); 55 Serial.println(tilt[iter]); 56 57 delay(500); // sets the interval between orientations 58 59 count++; 60 61} 62 63void moveSteps(int steps) 64{ 65 if (steps > 0) 66 digitalWrite(DIR_PIN, LOW); //LOW or HIGH 67 else 68 digitalWrite(DIR_PIN, HIGH); 69 70 for (int i = 0; i < abs(steps); i++) 71 { 72 digitalWrite(STEP_PIN, HIGH); 73 delay(stepPause); 74 digitalWrite(STEP_PIN, LOW); 75 delay(stepPause); 76 } 77} 78 79void moveTo(float angle) 80{ 81 int steps = round((angle - orientation) / stepAngle); 82 orientation += steps * stepAngle; 83 moveSteps(steps); 84} 85
Main Test Program
arduino
1/* 2 *12V motor: A4988 - orientation 3 * MG995 Servo motor - tilt 4 angle 5 * 6 * Solar panel terminals to Arduino: 7 analog in A0 -- panel 8 1 -- fixed 9 analog in A1 -- panel 2 -- tracking 10 11*/ 12 13#include <Arduino.h> 14#include 15 <Servo.h> // include servo library 16 17#define DIR_PIN 2 //direction 18#define 19 STEP_PIN 3 //step 20#define MG995_IN 6 // Name Digital D6 pin of Arduinol 21 22Servo 23 mg995Servo; // Initialize a servo object 24 25const int stepPause = 15; // micro 26 seconds between step motor input pulses 27const float stepAngle = 1.8; //1.8deg/step 28float 29 orientation = 180.; // current orientation 30int count = 0; // int to count loop 31 iteration 32 33int analogPin1 = A0; //solar panel #1 34int analogPin2 = A1; 35 //solar panel #2 36 37float orient[] = {77.8, 79.9, 81.9, 38 84.0, 86.1, 88.2, 90.5, 92.8, 95.3, 98.0, 39 100.9, 104.0, 107.5, 40 111.5, 116.1, 121.5, 127.9, 135.7, 145.1, 156.3, 41 169.2, 183.0, 42 196.6, 208.8, 219.3, 227.9, 235.0, 241.0, 246.0, 250.3, 43 254.0, 44 257.4, 260.4, 263.2, 265.8, 268.2, 270.5, 272.7, 274.8, 276.9, 45 279.0}; 46float 47 tilt[] = {23.0, 25.9, 28.8, 31.8, 34.8, 37.7, 40.7, 43.7, 46.7, 49.6, 48 52.6, 49 55.5, 58.4, 61.2, 63.9, 66.5, 69.0, 71.2, 73.1, 74.5, 50 75.4, 51 75.6, 75.1, 74.0, 72.3, 70.2, 67.9, 65.4, 62.7, 59.9, 52 57.1, 53 54.2, 51.3, 48.3, 45.4, 42.4, 39.4, 36.4, 33.5, 30.5, 54 27.5}; 55 56void 57 setup() 58{ 59 Serial.begin(9600); 60 61 for (int i = 10; i > 0; i--) 62 63 { 64 Serial.print(i); 65 Serial.print(", "); 66 delay(1000); 67 68 } 69 Serial.println(" "); 70 71 //set pin modes 72 pinMode(DIR_PIN, 73 OUTPUT); 74 pinMode(STEP_PIN, OUTPUT); 75 76 digitalWrite(DIR_PIN, LOW); 77 //LOW = CW, HIGH = CCW 78 digitalWrite(STEP_PIN, LOW); 79 80 mg995Servo.attach(MG995_IN); 81 // Attach signal pin of MG995 to D6 pin 82 83 84} 85 86void loop() 87{ 88 89 // start of operation 90 int iter = count % 41; 91 92 moveTo(orient[iter]); 93 94 mg995Servo.write(tilt[iter]); 95 Serial.print(count); 96 Serial.print(","); 97 98 Serial.print(orientation); 99 Serial.print(","); 100 Serial.println(tilt[iter]); 101 102 103 // read panel data 104 analogReference(DEFAULT); 105 readPanelData(); // Call 106 readPanleData() function 107 delay(60000 * 15); // sets the interval between orientations 108 109 110 count++; 111} 112 113void moveSteps(int steps) 114{ 115 if (steps > 0) 116 digitalWrite(DIR_PIN, 117 LOW); //LOW or HIGH 118 else 119 digitalWrite(DIR_PIN, HIGH); 120 121 for 122 (int i = 0; i < abs(steps); i++) 123 { 124 digitalWrite(STEP_PIN, HIGH); 125 126 delay(stepPause); 127 digitalWrite(STEP_PIN, LOW); 128 delay(stepPause); 129 130 } 131} 132 133void moveTo(float angle) 134{ 135 int steps = round((angle - orientation) 136 / stepAngle); 137 orientation += steps * stepAngle; 138 moveSteps(steps); 139} 140 141void 142 readPanelData() { 143 144 Serial.print(count); 145 Serial.print(","); 146 147 148 int val1 = analogRead(analogPin1); 149 delay(100); 150 int val2 = analogRead(analogPin1); 151 152 delay(100); 153 int val = int((val1 + val2)/2); // average 154 Serial.print(val); 155 156 Serial.print(","); 157 delay(100); 158 159 val1 = analogRead(analogPin2); 160 161 delay(100); 162 val2 = analogRead(analogPin2); 163 delay(100); 164 val = int((val1 165 + val2)/2); // average 166 167 Serial.println(val); 168} 169
Downloadable files
Full Measurement system
Full Measurement system
Full Measurement system
Full Measurement system
Documentation
Assembly of tracking panel
Assembly of tracking panel
Comments
Only logged in users can leave comments
teddyyoonie
0 Followers
•0 Projects
Table of contents
Intro
0
0