-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolar_tracker_v1.00.ino
153 lines (134 loc) · 3.56 KB
/
solar_tracker_v1.00.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/**
* @author Ioannis Katsikavelas <[email protected]>
Dimitrios Tsoukantanas <[email protected]>
* @copyright 2015 - Ioannis Katsikavelas - Dimitrios Tsoukantanas
* @license {@link http://choosealicense.com/licenses/mit/ | MIT License}
*/
#include <Servo.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
Servo Servo1 ;// x axis
Servo Servo2 ;//y axis
/*the cable colours also helped us on hardware installation
that's why we followed the pattern here too*/
const int GSensorPin = A0 ;//green left
const int BSensorPin = A1 ;//blue right
const int bSensorPin = A2 ;//brown bottom
const int OSensorPin = A3 ;//orange up
int blueSensor=0;
int greenSensor=0;
int brownSensor=0;
int orangeSensor=0;
//correction factor after reading ldrs due to their construction inaccuracy
int correctionBlue=1;
int correctionGreen=1;
int correctionOrange=1;
int correctionBrown=1;
const int dif=50;//difference for LDRs
int angle1 = 0 ;// x angle to write on servo
int angle2 = 0 ;//y angle to write on servo
int x = 0 ;
void setup()
{
lcd.begin(16,2);
Servo1.attach(9) ;
Servo2.attach(10) ;
Serial.begin(9600);
lcd.print("MADE BY : ") ;
delay(3000);
lcd.setCursor(0, 1);
lcd.print("MWRAITIS .S");
delay(3000);
lcd.clear();
lcd.print("MWRAITIS .N");
delay(3000);
lcd.clear();
lcd.print("TSOUKANTANAS .D");
delay(3000);
lcd.clear();
lcd.print("KATSIKAVELAS .I");
delay(3000);
lcd.clear();
lcd.setCursor(0,0);
}
void loop()
{
blueSensor=analogRead(BSensorPin)*correctionBlue;
greenSensor=analogRead(GSensorPin)*correctionGreen;
brownSensor=analogRead(bSensorPin)*correctionBrown;
orangeSensor=analogRead(OSensorPin)*correctionOrange;
if ( (abs(greenSensor - blueSensor) > dif) && ((greenSensor - blueSensor)>0) )
{
angle1=angle1+5;
if (angle1 >165)
{
angle1=165;
}
Servo1.write(angle1);
delay(45);
}
else if ( (abs(greenSensor - blueSensor) > dif) && ((greenSensor - blueSensor)<0) )
{
angle1=angle1-5;
if (angle1 < 0)
{
angle1=0;
}
Servo1.write(angle1);
delay (45);
}
else
{
//do nothing
}
if ( (abs(brownSensor - orangeSensor)> dif) && ((brownSensor - orangeSensor)>0) )
{
angle2=angle2+5;
if (angle2 >179)
{
angle2=179;
}
Servo2.write(angle2);
delay(45);
}
else if ( abs(brownSensor - orangeSensor) > dif && brownSensor - orangeSensor<0 )
{
angle2=angle2-5;
if (angle2 < 0)
{
angle2=0;
}
Servo2.write(angle2);
delay (45);
}
else
{
//do nothing
}
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Angle 1 : ");
lcd.print(angle1);
delay(100);
lcd.setCursor(1,1);
lcd.print("Angle 2 : ");
lcd.print(angle2);
delay(100);
Serial.print(" ANGLE 1\t");
Serial.print(angle1);
Serial.print(" \t green ");
Serial.print(greenSensor);
Serial.print(" \t blue ");
Serial.print(blueSensor);
Serial.print(" difference ");
Serial.print(greenSensor - blueSensor);
Serial.print(" ANGLE 2\t");
Serial.print(angle2);
Serial.print(" \t brown ");
Serial.print(brownSensor);
Serial.print(" \t orange ");
Serial.print(orangeSensor);
Serial.print(" difference ");
Serial.println(brownSensor - orangeSensor);
delay(1000);
}