-
Notifications
You must be signed in to change notification settings - Fork 0
/
Star_Finder.ino
179 lines (162 loc) · 5.28 KB
/
Star_Finder.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// This project is design to monitor the movement of the Sun (during day time) and Moon (during night time) on the celestial sphere, recording the bearing and altitude
// for the calculation of the position of the observer.
// The project is using a photo resistor which senses the highest light intensity and records the position of the two servo motors.
// The servo motors sweep the photo resistor across the sky and when the maximum light intensity is sensed the position of the servo motors is recorded on the LCD.
// The project is design to be fun, easy, cheap and "help navigators find their way" :P.
#include <Servo.h>
#include <LiquidCrystal.h>
int servoPin1=10; //Declare pin 10 as servoPin1
int servoPin2=11; //Declare pin 11 as servoPin2
int pos1=90; //Default/calibration position for horizontal servo
int pos2=90; //Default/calibration position for vertical servo
int servoDelay=25;
int pinButton=12; //Declare pin 12 as pinButton
int rezPin=A0; //Declare int variable rezPin as pin A0
int analogValue; //Declare valoareArduino as an int - values read from the A0 pin
int minimValue=1023; //The minimum analogValue read
int currentValue; //The current analogValue read
int buttonStatus; //Variable for the state of the button
Servo horizontal;
Servo vertical;
LiquidCrystal lcd(2,3,4,5,6,7);
void setup() {
Serial.begin(9600); //Start serial communication
horizontal.attach(servoPin1);
vertical.attach(servoPin2);
lcd.begin(16,2); //Declare LCD
lcd.setCursor(0,0);
lcd.print("Star finder"); //Print on the LCD
lcd.setCursor(0,1);
lcd.print("Hello Sky"); //Print on the LCD
delay(3000);
lcd.setCursor(0,0);
lcd.print(" ");
pinMode(rezPin,INPUT); //Declare rezPin as an INPUT pin
}
void loop() {
buttonStatus=digitalRead(pinButton); //Read the state of the button
if(buttonStatus==HIGH){ // If button is pressed (HIGH)
for(int i=20; i<=170; i=i+2){
pos1=i;
horizontal.write(pos1); //horizontal servo takes positions from 30 to 150 degrees
delay(servoDelay);
for (int j=90; j<=170; j=j+2){ //vertical servo takes positions from 90 to 170 degrees
pos2=j;
vertical.write(pos2);
delay(servoDelay);
analogValue=analogRead(rezPin); //Assigne analogValue the value read from the A0
currentValue=analogValue; //analogValue becomes currentValue
lcd.setCursor(0,0);
lcd.print("Pos:BRG=");
lcd.print(i);
lcd.print("/H=");
lcd.print(j-90);
if( currentValue<=minimValue){ // if currentValue smaller than minimValue (first time is 1023) make currentValue=minimumValue
minimValue=currentValue;
lcd.setCursor(0,1);
lcd.print("BRG=");
lcd.print(i);
lcd.print(" /// H=");
lcd.print(j-90);
Serial.print(minimValue);
Serial.print("// BRG=");
Serial.println(i);
Serial.print(" Altitude=");
Serial.println(j);
}
}
for (int j=170; j>=90; j=j-2){ //vertical servo takes positions from 170 to 90 degrees
pos2=j;
vertical.write(pos2);
delay(servoDelay);
analogValue=analogRead(rezPin); // read again the analogValue from the A0 pin
currentValue=analogValue; // set currentValue=analogValue
lcd.setCursor(0,0);
lcd.print("Pos:BRG=");
lcd.print(i);
lcd.print("/H=");
lcd.print(j-90);
if( currentValue<=minimValue){
minimValue=currentValue;
lcd.setCursor(0,1);
lcd.print("BRG=");
lcd.print(i);
lcd.print(" /// H=");
lcd.print(j-90);
Serial.print(minimValue);
Serial.print("// BRG=");
Serial.println(i);
Serial.print(" Altitude=");
Serial.println(j);
}
}
}
minimValue=1023;
for(int i=170; i>=20; i=i-2){ //Horizontal sevo takes position from 150 to 30 degrees
pos1=i;
horizontal.write(pos1);
delay(servoDelay);
for (int j=90; j<=170; j=j+2){
pos2=j;
vertical.write(pos2);
delay(servoDelay);
analogValue=analogRead(rezPin);
currentValue=analogValue;
lcd.setCursor(0,0);
lcd.print("Pos:BRG=");
lcd.print(i);
lcd.print("/H=");
lcd.print(j-90);
if( currentValue<=minimValue){
minimValue=currentValue;
lcd.setCursor(0,1);
lcd.print("BRG=");
lcd.print(i);
lcd.print(" /// H=");
lcd.print(j-90);
Serial.print(minimValue);
Serial.print("// BRG=");
Serial.println(i);
Serial.print(" Altitude=");
Serial.println(j);
}
}
for (int j=170; j>=90; j=j-2){
pos2=j;
vertical.write(pos2);
delay(servoDelay);
analogValue=analogRead(rezPin);
currentValue=analogValue;
lcd.setCursor(0,0);
lcd.print("Pos:BRG=");
lcd.print(i);
lcd.print("/H=");
lcd.print(j-90);
if( currentValue<=minimValue){
minimValue=currentValue;
lcd.setCursor(0,1);
lcd.print("BRG=");
lcd.print(i);
lcd.print(" /// H=");
lcd.print(j-90);
Serial.print(minimValue);
Serial.print("// BRG=");
Serial.println(i);
Serial.print(" Altitude=");
Serial.println(j);
}
}
}
minimValue=1023;
}
else{ //If button is not pressed both servos take 90 degrees position
pos1=90;
horizontal.write(pos1);
pos2=90;
vertical.write(pos2);
lcd.setCursor(0,0); //Print on the LCD message
lcd.print("Calibrate");
lcd.setCursor(0,1);
lcd.print("Press to measure");
}
}