Sun-tracking system with MPPT and astronomical equations
Project PPT
![](http://www.weebly.com/weebly/images/file_icons/xls.png)
sun_tracking_system.pptx | |
File Size: | 6621 kb |
File Type: | pptx |
![](http://www.weebly.com/weebly/images/file_icons/xls.png)
sun_tracking_system.pptx | |
File Size: | 6077 kb |
File Type: | pptx |
![](http://www.weebly.com/weebly/images/file_icons/xls.png)
sun_tracking_system.pptx | |
File Size: | 5125 kb |
File Type: | pptx |
Project Report
Chapter 1 work done till 29th Oct.
![](http://www.weebly.com/weebly/images/file_icons/pdf.png)
main.pdf | |
File Size: | 146 kb |
File Type: |
Thesis
1
2
3
4
5
6
7
8
9
10
Papers
1
2
3
4
5
6
7
8
9
10
![](http://www.weebly.com/weebly/images/file_icons/image.png)
circuitdiagream.png | |
File Size: | 33 kb |
File Type: | png |
#include <Servo.h>
#include <Keypad.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(15, 14, 13, 12, 11, 10);
char customKey = 0;
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char hexaKeys[ROWS][COLS] = {
{'0','1','2','3'},
{'4','5','6','7'},
{'8','9','A','B'},
{'C','D','E','F'}
};
byte rowPins[ROWS] = {0, 1, 2, 3}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4, 5, 6, 7};
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
Servo myservo; // create servo object to control a servo
Servo myservo1;
int pos=0;
int pos1=0;
int latflag=1;
int longiflag=0;
int latitude=0;
int longitude =0;
int monthflag=0;
int month = 0;
int minute=0;
int hour=0;
int minuteflag =0;
int hourflag =0;
int year =0;
int day=0;
int dayflag =0;
int yearflag=0;
int sec,secu,localsec=0;
void setup() {
myservo.attach(9);
myservo1.attach(8);
lcd.begin(20, 4);
lcd.clear();
lcd.print("Automatic suntracker");
lcd.setCursor(0, 1);
lcd.print(" Welcome ");
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos1 = 0; pos1 < 180; pos1 += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo1.write(pos1); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos1 = 180; pos1>=1; pos1-=1) // goes from 180 degrees to 0 degrees
{
myservo1.write(pos1); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
//latitude
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter latitude");
lcd.setCursor(0, 1);
while(latflag==1)
{
customKey = customKeypad.getKey();
if (customKey){
if(customKey=='C')
{
if(latitude>180)
{ lcd.clear();
lcd.setCursor(0, 0);
lcd.print("invalid latitude");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter latitude");
lcd.setCursor(0, 1);
latitude=0;
}
else
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Latitude =");
lcd.print(latitude);
delay(2000);
latflag=0;
longiflag=1;
}
}
if(customKey=='F')
{
lcd.print("1");
latitude=1+latitude*10;
}
if(customKey=='B')
{
lcd.print("2");
latitude=2+latitude*10;
}
if(customKey=='7')
{
lcd.print("3");
latitude=3+latitude*10;
}
if(customKey=='E')
{
lcd.print("4");
latitude=4+latitude*10;
}
if(customKey=='A')
{
lcd.print("5");
latitude=5+latitude*10;
}
if(customKey=='6')
{
lcd.print("6");
latitude=6+latitude*10;
}
if(customKey=='D')
{
lcd.print("7");
latitude=7+latitude*10;
}
if(customKey=='9')
{
lcd.print("8");
latitude=8+latitude*10;
}
if(customKey=='5')
{
lcd.print("9");
latitude=9+latitude*10;
}
if(customKey=='8')
{
lcd.print("0");
latitude=0+latitude*10;
}
}
}
// longitude
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter longitude");
lcd.setCursor(0, 1);
while(longiflag==1)
{
customKey = customKeypad.getKey();
if (customKey){
if(customKey=='C')
{
if(longitude>360)
{ lcd.clear();
lcd.setCursor(0, 0);
lcd.print("invalid longitude");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter longitude");
lcd.setCursor(0, 1);
longitude=0;
}
else
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Longitude =");
lcd.print(longitude);
delay(2000);
longiflag=0;
monthflag=1;
}
}
if(customKey=='F')
{
lcd.print("1");
longitude=1+longitude*10;
}
if(customKey=='B')
{
lcd.print("2");
longitude=2+longitude*10;
}
if(customKey=='7')
{
lcd.print("3");
longitude=3+longitude*10;
}
if(customKey=='E')
{
lcd.print("4");
longitude=4+longitude*10;
}
if(customKey=='A')
{
lcd.print("5");
longitude=5+longitude*10;
}
if(customKey=='6')
{
lcd.print("6");
longitude=6+longitude*10;
}
if(customKey=='D')
{
lcd.print("7");
longitude=7+longitude*10;
}
if(customKey=='9')
{
lcd.print("8");
longitude=8+longitude*10;
}
if(customKey=='5')
{
lcd.print("9");
longitude=9+longitude*10;
}
if(customKey=='8')
{
lcd.print("0");
longitude=0+longitude*10;
}
}
}
//month
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter month");
lcd.setCursor(0, 1);
while(monthflag==1)
{
customKey = customKeypad.getKey();
if (customKey){
if(customKey=='C')
{
if(month>12)
{ lcd.clear();
lcd.setCursor(0, 0);
lcd.print("invalid month");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter month");
lcd.setCursor(0, 1);
month=0;
}
else
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Month =");
lcd.print(month);
delay(2000);
monthflag=0;
dayflag=1;
}
}
if(customKey=='F')
{
lcd.print("1");
month=1+month*10;
}
if(customKey=='B')
{
lcd.print("2");
month=2+month*10;
}
if(customKey=='7')
{
lcd.print("3");
month=3+month*10;
}
if(customKey=='E')
{
lcd.print("4");
month=4+month*10;
}
if(customKey=='A')
{
lcd.print("5");
month=5+month*10;
}
if(customKey=='6')
{
lcd.print("6");
month=6+month*10;
}
if(customKey=='D')
{
lcd.print("7");
month=7+month*10;
}
if(customKey=='9')
{
lcd.print("8");
month=8+month*10;
}
if(customKey=='5')
{
lcd.print("9");
month=9+month*10;
}
if(customKey=='8')
{
lcd.print("0");
month=0+month*10;
}
}
}
//day
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter day");
lcd.setCursor(0, 1);
while(dayflag==1)
{
customKey = customKeypad.getKey();
if (customKey){
if(customKey=='C')
{
if(day>31)
{ lcd.clear();
lcd.setCursor(0, 0);
lcd.print("invalid day");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter day");
lcd.setCursor(0, 1);
day=0;
}
else
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Day =");
lcd.print(day);
delay(2000);
dayflag=0;
yearflag=1;
}
}
if(customKey=='F')
{
lcd.print("1");
day=1+day*10;
}
if(customKey=='B')
{
lcd.print("2");
day=2+day*10;
}
if(customKey=='7')
{
lcd.print("3");
day=3+day*10;
}
if(customKey=='E')
{
lcd.print("4");
day=4+day*10;
}
if(customKey=='A')
{
lcd.print("5");
day=5+day*10;
}
if(customKey=='6')
{
lcd.print("6");
day=6+day*10;
}
if(customKey=='D')
{
lcd.print("7");
day=7+day*10;
}
if(customKey=='9')
{
lcd.print("8");
day=8+day*10;
}
if(customKey=='5')
{
lcd.print("9");
day=9+day*10;
}
if(customKey=='8')
{
lcd.print("0");
day=0+day*10;
}
}
}
//year
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter year");
lcd.setCursor(0, 1);
while(yearflag==1)
{
customKey = customKeypad.getKey();
if (customKey){
if(customKey=='C')
{
if(year<2015)
{ lcd.clear();
lcd.setCursor(0, 0);
lcd.print("invalid year");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter year");
lcd.setCursor(0, 1);
year=0;
}
else
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Year =");
lcd.print(year);
delay(2000);
yearflag=0;
hourflag=1;
}
}
if(customKey=='F')
{
lcd.print("1");
year=1+year*10;
}
if(customKey=='B')
{
lcd.print("2");
year=2+year*10;
}
if(customKey=='7')
{
lcd.print("3");
year=3+year*10;
}
if(customKey=='E')
{
lcd.print("4");
year=4+year*10;
}
if(customKey=='A')
{
lcd.print("5");
year=5+year*10;
}
if(customKey=='6')
{
lcd.print("6");
year=6+year*10;
}
if(customKey=='D')
{
lcd.print("7");
year=7+year*10;
}
if(customKey=='9')
{
lcd.print("8");
year=8+year*10;
}
if(customKey=='5')
{
lcd.print("9");
year=9+year*10;
}
if(customKey=='8')
{
lcd.print("0");
year=0+year*10;
}
}
}
//time
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter hour");
lcd.setCursor(0, 1);
while(hourflag==1)
{
customKey = customKeypad.getKey();
if (customKey){
if(customKey=='C')
{
if(hour>24)
{ lcd.clear();
lcd.setCursor(0, 0);
lcd.print("invalid hour");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter hour");
lcd.setCursor(0, 1);
hour=0;
}
else
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Hour =");
lcd.print(hour);
delay(2000);
hourflag=0;
minuteflag=1;
}
}
if(customKey=='F')
{
lcd.print("1");
hour=1+hour*10;
}
if(customKey=='B')
{
lcd.print("2");
hour=2+hour*10;
}
if(customKey=='7')
{
lcd.print("3");
hour=3+hour*10;
}
if(customKey=='E')
{
lcd.print("4");
hour=4+hour*10;
}
if(customKey=='A')
{
lcd.print("5");
hour=5+hour*10;
}
if(customKey=='6')
{
lcd.print("6");
hour=6+hour*10;
}
if(customKey=='D')
{
lcd.print("7");
hour=7+hour*10;
}
if(customKey=='9')
{
lcd.print("8");
hour=8+hour*10;
}
if(customKey=='5')
{
lcd.print("9");
hour=9+hour*10;
}
if(customKey=='8')
{
lcd.print("0");
hour=0+hour*10;
}
}
}
//minut
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter minute");
lcd.setCursor(0, 1);
while(minuteflag==1)
{
customKey = customKeypad.getKey();
if (customKey){
if(customKey=='C')
{
if(minute>60)
{ lcd.clear();
lcd.setCursor(0, 0);
lcd.print("invalid minute");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter minute");
lcd.setCursor(0, 1);
minute=0;
}
else
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Minute =");
lcd.print(minute);
delay(2000);
minuteflag=0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Tracking on: ");
lcd.setCursor(0, 1);
lcd.print("Astronomy equations");
lcd.setCursor(0, 2);
lcd.print(latitude);
lcd.print(" ");
lcd.print(longitude);
}
}
if(customKey=='F')
{
lcd.print("1");
minute=1+minute*10;
}
if(customKey=='B')
{
lcd.print("2");
minute=2+minute*10;
}
if(customKey=='7')
{
lcd.print("3");
minute=3+minute*10;
}
if(customKey=='E')
{
lcd.print("4");
minute=4+minute*10;
}
if(customKey=='A')
{
lcd.print("5");
minute=5+minute*10;
}
if(customKey=='6')
{
lcd.print("6");
minute=6+minute*10;
}
if(customKey=='D')
{
lcd.print("7");
minute=7+minute*10;
}
if(customKey=='9')
{
lcd.print("8");
minute=8+minute*10;
}
if(customKey=='5')
{
lcd.print("9");
minute=9+minute*10;
}
if(customKey=='8')
{
lcd.print("0");
minute=0+minute*10;
}
}
}
}
void loop() {
lcd.setCursor(0, 3);
if(sec<2)
{
lcd.print(" ");
lcd.setCursor(0, 3);
}
lcd.print(day);
lcd.print("/");
lcd.print(month);
lcd.print("/");
lcd.print(year);
lcd.print(" ");
lcd.print(hour);
lcd.print(":");
lcd.print(minute);
lcd.print(":");
lcd.print(sec);
localsec=millis()/1000;
sec=secu+localsec;
if(sec>59)
{secu=secu-60;
minute=minute+1;
}
if(minute>59)
{
hour=hour+1;
minute=0;
}
if(hour>23)
{
day=day+1;
hour=0;
}
if(day>31)
{
month=month+1;
day=1;
}
if(month>12)
{
year=year+1;
month=1;
}
}
#include <Keypad.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(15, 14, 13, 12, 11, 10);
char customKey = 0;
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char hexaKeys[ROWS][COLS] = {
{'0','1','2','3'},
{'4','5','6','7'},
{'8','9','A','B'},
{'C','D','E','F'}
};
byte rowPins[ROWS] = {0, 1, 2, 3}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4, 5, 6, 7};
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
Servo myservo; // create servo object to control a servo
Servo myservo1;
int pos=0;
int pos1=0;
int latflag=1;
int longiflag=0;
int latitude=0;
int longitude =0;
int monthflag=0;
int month = 0;
int minute=0;
int hour=0;
int minuteflag =0;
int hourflag =0;
int year =0;
int day=0;
int dayflag =0;
int yearflag=0;
int sec,secu,localsec=0;
void setup() {
myservo.attach(9);
myservo1.attach(8);
lcd.begin(20, 4);
lcd.clear();
lcd.print("Automatic suntracker");
lcd.setCursor(0, 1);
lcd.print(" Welcome ");
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos1 = 0; pos1 < 180; pos1 += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo1.write(pos1); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos1 = 180; pos1>=1; pos1-=1) // goes from 180 degrees to 0 degrees
{
myservo1.write(pos1); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
//latitude
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter latitude");
lcd.setCursor(0, 1);
while(latflag==1)
{
customKey = customKeypad.getKey();
if (customKey){
if(customKey=='C')
{
if(latitude>180)
{ lcd.clear();
lcd.setCursor(0, 0);
lcd.print("invalid latitude");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter latitude");
lcd.setCursor(0, 1);
latitude=0;
}
else
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Latitude =");
lcd.print(latitude);
delay(2000);
latflag=0;
longiflag=1;
}
}
if(customKey=='F')
{
lcd.print("1");
latitude=1+latitude*10;
}
if(customKey=='B')
{
lcd.print("2");
latitude=2+latitude*10;
}
if(customKey=='7')
{
lcd.print("3");
latitude=3+latitude*10;
}
if(customKey=='E')
{
lcd.print("4");
latitude=4+latitude*10;
}
if(customKey=='A')
{
lcd.print("5");
latitude=5+latitude*10;
}
if(customKey=='6')
{
lcd.print("6");
latitude=6+latitude*10;
}
if(customKey=='D')
{
lcd.print("7");
latitude=7+latitude*10;
}
if(customKey=='9')
{
lcd.print("8");
latitude=8+latitude*10;
}
if(customKey=='5')
{
lcd.print("9");
latitude=9+latitude*10;
}
if(customKey=='8')
{
lcd.print("0");
latitude=0+latitude*10;
}
}
}
// longitude
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter longitude");
lcd.setCursor(0, 1);
while(longiflag==1)
{
customKey = customKeypad.getKey();
if (customKey){
if(customKey=='C')
{
if(longitude>360)
{ lcd.clear();
lcd.setCursor(0, 0);
lcd.print("invalid longitude");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter longitude");
lcd.setCursor(0, 1);
longitude=0;
}
else
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Longitude =");
lcd.print(longitude);
delay(2000);
longiflag=0;
monthflag=1;
}
}
if(customKey=='F')
{
lcd.print("1");
longitude=1+longitude*10;
}
if(customKey=='B')
{
lcd.print("2");
longitude=2+longitude*10;
}
if(customKey=='7')
{
lcd.print("3");
longitude=3+longitude*10;
}
if(customKey=='E')
{
lcd.print("4");
longitude=4+longitude*10;
}
if(customKey=='A')
{
lcd.print("5");
longitude=5+longitude*10;
}
if(customKey=='6')
{
lcd.print("6");
longitude=6+longitude*10;
}
if(customKey=='D')
{
lcd.print("7");
longitude=7+longitude*10;
}
if(customKey=='9')
{
lcd.print("8");
longitude=8+longitude*10;
}
if(customKey=='5')
{
lcd.print("9");
longitude=9+longitude*10;
}
if(customKey=='8')
{
lcd.print("0");
longitude=0+longitude*10;
}
}
}
//month
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter month");
lcd.setCursor(0, 1);
while(monthflag==1)
{
customKey = customKeypad.getKey();
if (customKey){
if(customKey=='C')
{
if(month>12)
{ lcd.clear();
lcd.setCursor(0, 0);
lcd.print("invalid month");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter month");
lcd.setCursor(0, 1);
month=0;
}
else
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Month =");
lcd.print(month);
delay(2000);
monthflag=0;
dayflag=1;
}
}
if(customKey=='F')
{
lcd.print("1");
month=1+month*10;
}
if(customKey=='B')
{
lcd.print("2");
month=2+month*10;
}
if(customKey=='7')
{
lcd.print("3");
month=3+month*10;
}
if(customKey=='E')
{
lcd.print("4");
month=4+month*10;
}
if(customKey=='A')
{
lcd.print("5");
month=5+month*10;
}
if(customKey=='6')
{
lcd.print("6");
month=6+month*10;
}
if(customKey=='D')
{
lcd.print("7");
month=7+month*10;
}
if(customKey=='9')
{
lcd.print("8");
month=8+month*10;
}
if(customKey=='5')
{
lcd.print("9");
month=9+month*10;
}
if(customKey=='8')
{
lcd.print("0");
month=0+month*10;
}
}
}
//day
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter day");
lcd.setCursor(0, 1);
while(dayflag==1)
{
customKey = customKeypad.getKey();
if (customKey){
if(customKey=='C')
{
if(day>31)
{ lcd.clear();
lcd.setCursor(0, 0);
lcd.print("invalid day");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter day");
lcd.setCursor(0, 1);
day=0;
}
else
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Day =");
lcd.print(day);
delay(2000);
dayflag=0;
yearflag=1;
}
}
if(customKey=='F')
{
lcd.print("1");
day=1+day*10;
}
if(customKey=='B')
{
lcd.print("2");
day=2+day*10;
}
if(customKey=='7')
{
lcd.print("3");
day=3+day*10;
}
if(customKey=='E')
{
lcd.print("4");
day=4+day*10;
}
if(customKey=='A')
{
lcd.print("5");
day=5+day*10;
}
if(customKey=='6')
{
lcd.print("6");
day=6+day*10;
}
if(customKey=='D')
{
lcd.print("7");
day=7+day*10;
}
if(customKey=='9')
{
lcd.print("8");
day=8+day*10;
}
if(customKey=='5')
{
lcd.print("9");
day=9+day*10;
}
if(customKey=='8')
{
lcd.print("0");
day=0+day*10;
}
}
}
//year
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter year");
lcd.setCursor(0, 1);
while(yearflag==1)
{
customKey = customKeypad.getKey();
if (customKey){
if(customKey=='C')
{
if(year<2015)
{ lcd.clear();
lcd.setCursor(0, 0);
lcd.print("invalid year");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter year");
lcd.setCursor(0, 1);
year=0;
}
else
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Year =");
lcd.print(year);
delay(2000);
yearflag=0;
hourflag=1;
}
}
if(customKey=='F')
{
lcd.print("1");
year=1+year*10;
}
if(customKey=='B')
{
lcd.print("2");
year=2+year*10;
}
if(customKey=='7')
{
lcd.print("3");
year=3+year*10;
}
if(customKey=='E')
{
lcd.print("4");
year=4+year*10;
}
if(customKey=='A')
{
lcd.print("5");
year=5+year*10;
}
if(customKey=='6')
{
lcd.print("6");
year=6+year*10;
}
if(customKey=='D')
{
lcd.print("7");
year=7+year*10;
}
if(customKey=='9')
{
lcd.print("8");
year=8+year*10;
}
if(customKey=='5')
{
lcd.print("9");
year=9+year*10;
}
if(customKey=='8')
{
lcd.print("0");
year=0+year*10;
}
}
}
//time
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter hour");
lcd.setCursor(0, 1);
while(hourflag==1)
{
customKey = customKeypad.getKey();
if (customKey){
if(customKey=='C')
{
if(hour>24)
{ lcd.clear();
lcd.setCursor(0, 0);
lcd.print("invalid hour");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter hour");
lcd.setCursor(0, 1);
hour=0;
}
else
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Hour =");
lcd.print(hour);
delay(2000);
hourflag=0;
minuteflag=1;
}
}
if(customKey=='F')
{
lcd.print("1");
hour=1+hour*10;
}
if(customKey=='B')
{
lcd.print("2");
hour=2+hour*10;
}
if(customKey=='7')
{
lcd.print("3");
hour=3+hour*10;
}
if(customKey=='E')
{
lcd.print("4");
hour=4+hour*10;
}
if(customKey=='A')
{
lcd.print("5");
hour=5+hour*10;
}
if(customKey=='6')
{
lcd.print("6");
hour=6+hour*10;
}
if(customKey=='D')
{
lcd.print("7");
hour=7+hour*10;
}
if(customKey=='9')
{
lcd.print("8");
hour=8+hour*10;
}
if(customKey=='5')
{
lcd.print("9");
hour=9+hour*10;
}
if(customKey=='8')
{
lcd.print("0");
hour=0+hour*10;
}
}
}
//minut
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter minute");
lcd.setCursor(0, 1);
while(minuteflag==1)
{
customKey = customKeypad.getKey();
if (customKey){
if(customKey=='C')
{
if(minute>60)
{ lcd.clear();
lcd.setCursor(0, 0);
lcd.print("invalid minute");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter minute");
lcd.setCursor(0, 1);
minute=0;
}
else
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Minute =");
lcd.print(minute);
delay(2000);
minuteflag=0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Tracking on: ");
lcd.setCursor(0, 1);
lcd.print("Astronomy equations");
lcd.setCursor(0, 2);
lcd.print(latitude);
lcd.print(" ");
lcd.print(longitude);
}
}
if(customKey=='F')
{
lcd.print("1");
minute=1+minute*10;
}
if(customKey=='B')
{
lcd.print("2");
minute=2+minute*10;
}
if(customKey=='7')
{
lcd.print("3");
minute=3+minute*10;
}
if(customKey=='E')
{
lcd.print("4");
minute=4+minute*10;
}
if(customKey=='A')
{
lcd.print("5");
minute=5+minute*10;
}
if(customKey=='6')
{
lcd.print("6");
minute=6+minute*10;
}
if(customKey=='D')
{
lcd.print("7");
minute=7+minute*10;
}
if(customKey=='9')
{
lcd.print("8");
minute=8+minute*10;
}
if(customKey=='5')
{
lcd.print("9");
minute=9+minute*10;
}
if(customKey=='8')
{
lcd.print("0");
minute=0+minute*10;
}
}
}
}
void loop() {
lcd.setCursor(0, 3);
if(sec<2)
{
lcd.print(" ");
lcd.setCursor(0, 3);
}
lcd.print(day);
lcd.print("/");
lcd.print(month);
lcd.print("/");
lcd.print(year);
lcd.print(" ");
lcd.print(hour);
lcd.print(":");
lcd.print(minute);
lcd.print(":");
lcd.print(sec);
localsec=millis()/1000;
sec=secu+localsec;
if(sec>59)
{secu=secu-60;
minute=minute+1;
}
if(minute>59)
{
hour=hour+1;
minute=0;
}
if(hour>23)
{
day=day+1;
hour=0;
}
if(day>31)
{
month=month+1;
day=1;
}
if(month>12)
{
year=year+1;
month=1;
}
}
/*
The circuit:
* LCD RS pin to digital pin 15
* LCD Enable pin to digital pin 14
* LCD D4 pin to digital pin 13
* LCD D5 pin to digital pin 12
* LCD D6 pin to digital pin 11
* LCD D7 pin to digital pin 10
* LCD R/W pin to ground
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
*/
int localmin=0;
int minu1;
#include <Servo.h>
int flag=0;
int t=0;
#include <Keypad.h>
char customKey = 0;
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'0','1','2','3'},
{'4','5','6','7'},
{'8','9','A','B'},
{'C','D','E','F'}
};
byte rowPins[ROWS] = {0, 1, 2, 3}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4, 5, 6, 7}; //connect to the column pinouts of the keypad
int latitude=19;
int longitude=72;
int minu=0;
int daye=0;
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
Servo myservo; // create servo object to control a servo
Servo myservo1;
int pos=0;
int pos1=0;
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(15, 14, 13, 12, 11, 10);
void setup() {
myservo.attach(9);
myservo1.attach(8);
// set up the LCD's number of columns and rows:
lcd.begin(20, 4);
// Print a message to the LCD.
lcd.print("Automatic suntracker");
lcd.setCursor(0, 1);
lcd.print(" Welcome ");
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos1 = 0; pos1 < 180; pos1 += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo1.write(pos1); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos1 = 180; pos1>=1; pos1-=1) // goes from 180 degrees to 0 degrees
{
myservo1.write(pos1); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
void loop() {
char customKey = customKeypad.getKey();
if (customKey){
if(customKey=='F')
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter latitude");
lcd.setCursor(0, 1);
lcd.print("Current latitude:");
lcd.setCursor(0, 2);
lcd.print(latitude);
flag =1;
}
if(customKey=='B')
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter longitude");
lcd.setCursor(0, 1);
lcd.print("Current longitude:");
lcd.setCursor(0, 2);
lcd.print(longitude);
flag=2;
}
if(customKey=='7')
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter day (1-365):");
lcd.setCursor(0, 1);
lcd.print("Current day:");
lcd.setCursor(0, 2);
lcd.print(daye);
flag =3;
}
if(customKey=='E')
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter mins (0-1440):");
lcd.setCursor(0, 1);
lcd.print("Current minutes:");
lcd.setCursor(0, 2);
lcd.print(minu);
flag=4;
}
if(customKey=='4')
{
if(flag==1)
{latitude=latitude-1;
if(latitude<0)
{latitude=180;
lcd.setCursor(0, 2);
lcd.print(" ");
}
lcd.setCursor(0, 2);
lcd.print(latitude);
}
if(flag==2)
{longitude=longitude-1;
if(longitude<0)
{longitude=360;
lcd.setCursor(0, 2);
lcd.print(" ");}
lcd.setCursor(0, 2);
lcd.print(longitude);
}
if(flag==3)
{daye=daye-1;
if(daye>0)
{daye=365;
lcd.setCursor(0, 2);
lcd.print(" ");}
lcd.setCursor(0, 2);
lcd.print(daye);
}
if(flag==4)
{minu=minu-1;
if(minu<0)
{minu=1440;
lcd.setCursor(0, 2);
lcd.print(" ");
}
lcd.setCursor(0, 2);
lcd.print(minu);
}
}
if(customKey=='C')
{
if(flag==1)
{latitude=latitude+1;
if(latitude>179)
{latitude=0;
lcd.setCursor(0, 2);
lcd.print(" ");
}
lcd.setCursor(0, 2);
lcd.print(latitude);
}
if(flag==2)
{longitude=longitude+1;
if(longitude>359)
{longitude=0;
lcd.setCursor(0, 2);
lcd.print(" ");}
lcd.setCursor(0, 2);
lcd.print(longitude);
}
if(flag==3)
{daye=daye+1;
if(daye>365)
{daye=0;
lcd.setCursor(0, 2);
lcd.print(" ");}
lcd.setCursor(0, 2);
lcd.print(daye);
}
if(flag==4)
{minu=minu+1;
if(minu>1440)
{minu=0;
lcd.setCursor(0, 2);
lcd.print(" ");
}
lcd.setCursor(0, 2);
lcd.print(minu);
}
}
if(customKey=='8')
{ flag=0;
while(flag==0)
{
localmin=millis()/60000;
minu1=minu+localmin;
if(minu1>1440)
{
minu1=0;
}
lcd.setCursor(0, 0);
lcd.print("Tracking on: ");
lcd.setCursor(0, 1);
lcd.print("Astronomy equations");
delay(2000);
if(minu1<771)
{
pos = map(minu1, 0, 770, 0, 179);
}
if(minu1<771)
{
pos=0;
}
int azi=latitude+longitude;
pos1 = map(azi, 0, 540, 0, 179);
myservo1.write(pos1); // tell servo to go to position in variable 'pos'
myservo.write(pos); // tell servo to go to position in variable 'pos'
lcd.setCursor(0, 3);
lcd.print("Run time(sec): ");
lcd.print(millis()/1000);
lcd.setCursor(0, 1);
lcd.print("MPPT tracking mode ");
t=pos;
for(int pos1 = t; pos1 < t+5; pos1 += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos1); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos1 = t; pos1>=t-10; pos1-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos1); // tell servo to go to position in variable 'pos'
delay(15);
// waits 15ms for the servo to reach the position
}
for(pos1 = t; pos1 < t+5; pos1 += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos1); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
int sensorValue = (analogRead(A5));
lcd.setCursor(0, 2);
lcd.print(" ");
lcd.setCursor(0, 2);
lcd.print("ES:");
lcd.print(pos);
lcd.print(",NS:");
lcd.print(pos1);
lcd.print(",V(LV):");
lcd.print(sensorValue);
}
}
//lcd.print(customKey);
}
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
// print the number of seconds since reset:
lcd.setCursor(0, 3);
lcd.print("Run time(sec): ");
lcd.print(millis()/1000);
}
The circuit:
* LCD RS pin to digital pin 15
* LCD Enable pin to digital pin 14
* LCD D4 pin to digital pin 13
* LCD D5 pin to digital pin 12
* LCD D6 pin to digital pin 11
* LCD D7 pin to digital pin 10
* LCD R/W pin to ground
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
*/
int localmin=0;
int minu1;
#include <Servo.h>
int flag=0;
int t=0;
#include <Keypad.h>
char customKey = 0;
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'0','1','2','3'},
{'4','5','6','7'},
{'8','9','A','B'},
{'C','D','E','F'}
};
byte rowPins[ROWS] = {0, 1, 2, 3}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4, 5, 6, 7}; //connect to the column pinouts of the keypad
int latitude=19;
int longitude=72;
int minu=0;
int daye=0;
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
Servo myservo; // create servo object to control a servo
Servo myservo1;
int pos=0;
int pos1=0;
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(15, 14, 13, 12, 11, 10);
void setup() {
myservo.attach(9);
myservo1.attach(8);
// set up the LCD's number of columns and rows:
lcd.begin(20, 4);
// Print a message to the LCD.
lcd.print("Automatic suntracker");
lcd.setCursor(0, 1);
lcd.print(" Welcome ");
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos1 = 0; pos1 < 180; pos1 += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo1.write(pos1); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos1 = 180; pos1>=1; pos1-=1) // goes from 180 degrees to 0 degrees
{
myservo1.write(pos1); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
void loop() {
char customKey = customKeypad.getKey();
if (customKey){
if(customKey=='F')
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter latitude");
lcd.setCursor(0, 1);
lcd.print("Current latitude:");
lcd.setCursor(0, 2);
lcd.print(latitude);
flag =1;
}
if(customKey=='B')
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter longitude");
lcd.setCursor(0, 1);
lcd.print("Current longitude:");
lcd.setCursor(0, 2);
lcd.print(longitude);
flag=2;
}
if(customKey=='7')
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter day (1-365):");
lcd.setCursor(0, 1);
lcd.print("Current day:");
lcd.setCursor(0, 2);
lcd.print(daye);
flag =3;
}
if(customKey=='E')
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter mins (0-1440):");
lcd.setCursor(0, 1);
lcd.print("Current minutes:");
lcd.setCursor(0, 2);
lcd.print(minu);
flag=4;
}
if(customKey=='4')
{
if(flag==1)
{latitude=latitude-1;
if(latitude<0)
{latitude=180;
lcd.setCursor(0, 2);
lcd.print(" ");
}
lcd.setCursor(0, 2);
lcd.print(latitude);
}
if(flag==2)
{longitude=longitude-1;
if(longitude<0)
{longitude=360;
lcd.setCursor(0, 2);
lcd.print(" ");}
lcd.setCursor(0, 2);
lcd.print(longitude);
}
if(flag==3)
{daye=daye-1;
if(daye>0)
{daye=365;
lcd.setCursor(0, 2);
lcd.print(" ");}
lcd.setCursor(0, 2);
lcd.print(daye);
}
if(flag==4)
{minu=minu-1;
if(minu<0)
{minu=1440;
lcd.setCursor(0, 2);
lcd.print(" ");
}
lcd.setCursor(0, 2);
lcd.print(minu);
}
}
if(customKey=='C')
{
if(flag==1)
{latitude=latitude+1;
if(latitude>179)
{latitude=0;
lcd.setCursor(0, 2);
lcd.print(" ");
}
lcd.setCursor(0, 2);
lcd.print(latitude);
}
if(flag==2)
{longitude=longitude+1;
if(longitude>359)
{longitude=0;
lcd.setCursor(0, 2);
lcd.print(" ");}
lcd.setCursor(0, 2);
lcd.print(longitude);
}
if(flag==3)
{daye=daye+1;
if(daye>365)
{daye=0;
lcd.setCursor(0, 2);
lcd.print(" ");}
lcd.setCursor(0, 2);
lcd.print(daye);
}
if(flag==4)
{minu=minu+1;
if(minu>1440)
{minu=0;
lcd.setCursor(0, 2);
lcd.print(" ");
}
lcd.setCursor(0, 2);
lcd.print(minu);
}
}
if(customKey=='8')
{ flag=0;
while(flag==0)
{
localmin=millis()/60000;
minu1=minu+localmin;
if(minu1>1440)
{
minu1=0;
}
lcd.setCursor(0, 0);
lcd.print("Tracking on: ");
lcd.setCursor(0, 1);
lcd.print("Astronomy equations");
delay(2000);
if(minu1<771)
{
pos = map(minu1, 0, 770, 0, 179);
}
if(minu1<771)
{
pos=0;
}
int azi=latitude+longitude;
pos1 = map(azi, 0, 540, 0, 179);
myservo1.write(pos1); // tell servo to go to position in variable 'pos'
myservo.write(pos); // tell servo to go to position in variable 'pos'
lcd.setCursor(0, 3);
lcd.print("Run time(sec): ");
lcd.print(millis()/1000);
lcd.setCursor(0, 1);
lcd.print("MPPT tracking mode ");
t=pos;
for(int pos1 = t; pos1 < t+5; pos1 += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos1); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos1 = t; pos1>=t-10; pos1-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos1); // tell servo to go to position in variable 'pos'
delay(15);
// waits 15ms for the servo to reach the position
}
for(pos1 = t; pos1 < t+5; pos1 += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos1); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
int sensorValue = (analogRead(A5));
lcd.setCursor(0, 2);
lcd.print(" ");
lcd.setCursor(0, 2);
lcd.print("ES:");
lcd.print(pos);
lcd.print(",NS:");
lcd.print(pos1);
lcd.print(",V(LV):");
lcd.print(sensorValue);
}
}
//lcd.print(customKey);
}
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
// print the number of seconds since reset:
lcd.setCursor(0, 3);
lcd.print("Run time(sec): ");
lcd.print(millis()/1000);
}
Latest code:
/*
The circuit:
* LCD RS pin to digital pin 15
* LCD Enable pin to digital pin 14
* LCD D4 pin to digital pin 13
* LCD D5 pin to digital pin 12
* LCD D6 pin to digital pin 11
* LCD D7 pin to digital pin 10
* LCD R/W pin to ground
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
*/
int localmin=0;
int minu1;
#include <Servo.h>
int flag=0;
int t=0;
#include <Keypad.h>
char customKey = 0;
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'0','1','2','3'},
{'4','5','6','7'},
{'8','9','A','B'},
{'C','D','E','F'}
};
byte rowPins[ROWS] = {0, 1, 2, 3}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4, 5, 6, 7}; //connect to the column pinouts of the keypad
int latitude=19;
int longitude=72;
int minu=0;
int daye=0;
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
Servo myservo; // create servo object to control a servo
Servo myservo1;
int pos=0;
int pos1=0;
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(15, 14, 13, 12, 11, 10);
void setup() {
myservo.attach(9);
myservo1.attach(8);
// set up the LCD's number of columns and rows:
lcd.begin(20, 4);
// Print a message to the LCD.
lcd.print("Automatic suntracker");
lcd.setCursor(0, 1);
lcd.print(" Welcome ");
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos1 = 0; pos1 < 180; pos1 += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo1.write(pos1); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos1 = 180; pos1>=1; pos1-=1) // goes from 180 degrees to 0 degrees
{
myservo1.write(pos1); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
void loop() {
char customKey = customKeypad.getKey();
if (customKey){
if(customKey=='F')
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter latitude");
lcd.setCursor(0, 1);
lcd.print("Current latitude:");
lcd.setCursor(0, 2);
lcd.print(latitude);
flag =1;
}
if(customKey=='B')
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter longitude");
lcd.setCursor(0, 1);
lcd.print("Current longitude:");
lcd.setCursor(0, 2);
lcd.print(longitude);
flag=2;
}
if(customKey=='7')
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter day (1-365):");
lcd.setCursor(0, 1);
lcd.print("Current day:");
lcd.setCursor(0, 2);
lcd.print(daye);
flag =3;
}
if(customKey=='E')
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter mins (0-1440):");
lcd.setCursor(0, 1);
lcd.print("Current minutes:");
lcd.setCursor(0, 2);
lcd.print(minu);
flag=4;
}
if(customKey=='4')
{
if(flag==1)
{latitude=latitude-1;
if(latitude<0)
{latitude=180;
lcd.setCursor(0, 2);
lcd.print(" ");
}
lcd.setCursor(0, 2);
lcd.print(latitude);
}
if(flag==2)
{longitude=longitude-1;
if(longitude<0)
{longitude=360;
lcd.setCursor(0, 2);
lcd.print(" ");}
lcd.setCursor(0, 2);
lcd.print(longitude);
}
if(flag==3)
{daye=daye-1;
if(daye>0)
{daye=365;
lcd.setCursor(0, 2);
lcd.print(" ");}
lcd.setCursor(0, 2);
lcd.print(daye);
}
if(flag==4)
{minu=minu-1;
if(minu<0)
{minu=1440;
lcd.setCursor(0, 2);
lcd.print(" ");
}
lcd.setCursor(0, 2);
lcd.print(minu);
}
}
if(customKey=='C')
{
if(flag==1)
{latitude=latitude+1;
if(latitude>179)
{latitude=0;
lcd.setCursor(0, 2);
lcd.print(" ");
}
lcd.setCursor(0, 2);
lcd.print(latitude);
}
if(flag==2)
{longitude=longitude+1;
if(longitude>359)
{longitude=0;
lcd.setCursor(0, 2);
lcd.print(" ");}
lcd.setCursor(0, 2);
lcd.print(longitude);
}
if(flag==3)
{daye=daye+1;
if(daye>365)
{daye=0;
lcd.setCursor(0, 2);
lcd.print(" ");}
lcd.setCursor(0, 2);
lcd.print(daye);
}
if(flag==4)
{minu=minu+1;
if(minu>1440)
{minu=0;
lcd.setCursor(0, 2);
lcd.print(" ");
}
lcd.setCursor(0, 2);
lcd.print(minu);
}
}
if(customKey=='8')
{ flag=0;
while(flag==0)
{
localmin=millis()/60000;
minu1=minu+localmin;
if(minu1>1440)
{
minu1=0;
}
lcd.setCursor(0, 0);
lcd.print("Tracking on: ");
lcd.setCursor(0, 1);
lcd.print("Astronomy equations");
delay(2000);
if(minu1<771)
{
pos = map(minu1, 0, 770, 0, 179);
}
if(minu1<771)
{
pos=0;
}
int azi=astronomical(latitude,longitude,minu,t,daye);
pos1 = map(azi, 0, 540, 0, 179);
myservo1.write(pos1); // tell servo to go to position in variable 'pos'
myservo.write(pos); // tell servo to go to position in variable 'pos'
lcd.setCursor(0, 3);
lcd.print("Run time(sec): ");
lcd.print(millis()/1000);
lcd.setCursor(0, 1);
lcd.print("MPPT tracking mode ");
t=pos;
for(int pos1 = t; pos1 < t+5; pos1 += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos1); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos1 = t; pos1>=t-10; pos1-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos1); // tell servo to go to position in variable 'pos'
delay(15);
// waits 15ms for the servo to reach the position
}
for(pos1 = t; pos1 < t+5; pos1 += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos1); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
int sensorValue = (analogRead(A5));
lcd.setCursor(0, 2);
lcd.print(" ");
lcd.setCursor(0, 2);
lcd.print("ES:");
lcd.print(pos);
lcd.print(",NS:");
lcd.print(pos1);
lcd.print(",V(LV):");
lcd.print(sensorValue);
}
}
//lcd.print(customKey);
}
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
// print the number of seconds since reset:
lcd.setCursor(0, 3);
lcd.print("Run time(sec): ");
lcd.print(millis()/1000);
}
function [azi]=astronomical(latitude,longitude,minu,t,daye)
n=daye
m=minu
Ln=longitude
L=longitude
Ht=0
h(m)=0.25*m
omega(n)=2*pi*(n-1)/365
delta(n)=57.3*(0.007-(0.4*cos(omega(n)))+(0.07*(sin(omega(n))))-(0.007*(cos(2*omega(n))))+(0.0009
(0.003*(cos(3*omega(n))))+(0.0015*(sin(3*omega(n)))))
ET(n)=229.18*(0.00008+(0.0018*cos(omega(n)))-(0.03*sin(omega(n)))-(0.015*cos(2*(omega(n))))-
(0.04*(sin(2*(omega(n))))))
LocalNoon(n)= 12.00-(ET(n)/60)
h(m)=0.25*m
PA(n,m)=90-(0.066*((LocalNoon(n)-h(m))))
HSS(L,n)=0.066*acos(-1*(tan(L)*tan(delta(n))))
HRS(L,n)=-HSS(L,n)
DL(L,n)=0.133*(acos(-1*tan(L)*tan(delta(n))))
TA(L,n)=90-abs(L-delta(n))
Sunrisetime(L,n)=(LocalNoon(n)-(DL(L,n)/2))
Sunsettime(L,n)=(LocalNoon(n)+(DL(L,n)/2))
PA(n,m)=90-(0.066*((LocalNoon(n)-h(m))))
STTA(L,n,m)=PA(n,m)*(Sunrisetime(L,n)+Ht)
SPTA(L,n,m)=PA(n,m)*(Sunsettime(L,n)-Ht)
Ni(count)=STTA(L,n,m)-1025
Ni1(count)=SPTA(L,n,m)-930
[azi] =[dl*cos(theta),PA,TA]
/*
The circuit:
* LCD RS pin to digital pin 15
* LCD Enable pin to digital pin 14
* LCD D4 pin to digital pin 13
* LCD D5 pin to digital pin 12
* LCD D6 pin to digital pin 11
* LCD D7 pin to digital pin 10
* LCD R/W pin to ground
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
*/
int localmin=0;
int minu1;
#include <Servo.h>
int flag=0;
int t=0;
#include <Keypad.h>
char customKey = 0;
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'0','1','2','3'},
{'4','5','6','7'},
{'8','9','A','B'},
{'C','D','E','F'}
};
byte rowPins[ROWS] = {0, 1, 2, 3}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4, 5, 6, 7}; //connect to the column pinouts of the keypad
int latitude=19;
int longitude=72;
int minu=0;
int daye=0;
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
Servo myservo; // create servo object to control a servo
Servo myservo1;
int pos=0;
int pos1=0;
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(15, 14, 13, 12, 11, 10);
void setup() {
myservo.attach(9);
myservo1.attach(8);
// set up the LCD's number of columns and rows:
lcd.begin(20, 4);
// Print a message to the LCD.
lcd.print("Automatic suntracker");
lcd.setCursor(0, 1);
lcd.print(" Welcome ");
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos1 = 0; pos1 < 180; pos1 += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo1.write(pos1); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos1 = 180; pos1>=1; pos1-=1) // goes from 180 degrees to 0 degrees
{
myservo1.write(pos1); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
void loop() {
char customKey = customKeypad.getKey();
if (customKey){
if(customKey=='F')
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter latitude");
lcd.setCursor(0, 1);
lcd.print("Current latitude:");
lcd.setCursor(0, 2);
lcd.print(latitude);
flag =1;
}
if(customKey=='B')
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter longitude");
lcd.setCursor(0, 1);
lcd.print("Current longitude:");
lcd.setCursor(0, 2);
lcd.print(longitude);
flag=2;
}
if(customKey=='7')
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter day (1-365):");
lcd.setCursor(0, 1);
lcd.print("Current day:");
lcd.setCursor(0, 2);
lcd.print(daye);
flag =3;
}
if(customKey=='E')
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter mins (0-1440):");
lcd.setCursor(0, 1);
lcd.print("Current minutes:");
lcd.setCursor(0, 2);
lcd.print(minu);
flag=4;
}
if(customKey=='4')
{
if(flag==1)
{latitude=latitude-1;
if(latitude<0)
{latitude=180;
lcd.setCursor(0, 2);
lcd.print(" ");
}
lcd.setCursor(0, 2);
lcd.print(latitude);
}
if(flag==2)
{longitude=longitude-1;
if(longitude<0)
{longitude=360;
lcd.setCursor(0, 2);
lcd.print(" ");}
lcd.setCursor(0, 2);
lcd.print(longitude);
}
if(flag==3)
{daye=daye-1;
if(daye>0)
{daye=365;
lcd.setCursor(0, 2);
lcd.print(" ");}
lcd.setCursor(0, 2);
lcd.print(daye);
}
if(flag==4)
{minu=minu-1;
if(minu<0)
{minu=1440;
lcd.setCursor(0, 2);
lcd.print(" ");
}
lcd.setCursor(0, 2);
lcd.print(minu);
}
}
if(customKey=='C')
{
if(flag==1)
{latitude=latitude+1;
if(latitude>179)
{latitude=0;
lcd.setCursor(0, 2);
lcd.print(" ");
}
lcd.setCursor(0, 2);
lcd.print(latitude);
}
if(flag==2)
{longitude=longitude+1;
if(longitude>359)
{longitude=0;
lcd.setCursor(0, 2);
lcd.print(" ");}
lcd.setCursor(0, 2);
lcd.print(longitude);
}
if(flag==3)
{daye=daye+1;
if(daye>365)
{daye=0;
lcd.setCursor(0, 2);
lcd.print(" ");}
lcd.setCursor(0, 2);
lcd.print(daye);
}
if(flag==4)
{minu=minu+1;
if(minu>1440)
{minu=0;
lcd.setCursor(0, 2);
lcd.print(" ");
}
lcd.setCursor(0, 2);
lcd.print(minu);
}
}
if(customKey=='8')
{ flag=0;
while(flag==0)
{
localmin=millis()/60000;
minu1=minu+localmin;
if(minu1>1440)
{
minu1=0;
}
lcd.setCursor(0, 0);
lcd.print("Tracking on: ");
lcd.setCursor(0, 1);
lcd.print("Astronomy equations");
delay(2000);
if(minu1<771)
{
pos = map(minu1, 0, 770, 0, 179);
}
if(minu1<771)
{
pos=0;
}
int azi=astronomical(latitude,longitude,minu,t,daye);
pos1 = map(azi, 0, 540, 0, 179);
myservo1.write(pos1); // tell servo to go to position in variable 'pos'
myservo.write(pos); // tell servo to go to position in variable 'pos'
lcd.setCursor(0, 3);
lcd.print("Run time(sec): ");
lcd.print(millis()/1000);
lcd.setCursor(0, 1);
lcd.print("MPPT tracking mode ");
t=pos;
for(int pos1 = t; pos1 < t+5; pos1 += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos1); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos1 = t; pos1>=t-10; pos1-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos1); // tell servo to go to position in variable 'pos'
delay(15);
// waits 15ms for the servo to reach the position
}
for(pos1 = t; pos1 < t+5; pos1 += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos1); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
int sensorValue = (analogRead(A5));
lcd.setCursor(0, 2);
lcd.print(" ");
lcd.setCursor(0, 2);
lcd.print("ES:");
lcd.print(pos);
lcd.print(",NS:");
lcd.print(pos1);
lcd.print(",V(LV):");
lcd.print(sensorValue);
}
}
//lcd.print(customKey);
}
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
// print the number of seconds since reset:
lcd.setCursor(0, 3);
lcd.print("Run time(sec): ");
lcd.print(millis()/1000);
}
function [azi]=astronomical(latitude,longitude,minu,t,daye)
n=daye
m=minu
Ln=longitude
L=longitude
Ht=0
h(m)=0.25*m
omega(n)=2*pi*(n-1)/365
delta(n)=57.3*(0.007-(0.4*cos(omega(n)))+(0.07*(sin(omega(n))))-(0.007*(cos(2*omega(n))))+(0.0009
(0.003*(cos(3*omega(n))))+(0.0015*(sin(3*omega(n)))))
ET(n)=229.18*(0.00008+(0.0018*cos(omega(n)))-(0.03*sin(omega(n)))-(0.015*cos(2*(omega(n))))-
(0.04*(sin(2*(omega(n))))))
LocalNoon(n)= 12.00-(ET(n)/60)
h(m)=0.25*m
PA(n,m)=90-(0.066*((LocalNoon(n)-h(m))))
HSS(L,n)=0.066*acos(-1*(tan(L)*tan(delta(n))))
HRS(L,n)=-HSS(L,n)
DL(L,n)=0.133*(acos(-1*tan(L)*tan(delta(n))))
TA(L,n)=90-abs(L-delta(n))
Sunrisetime(L,n)=(LocalNoon(n)-(DL(L,n)/2))
Sunsettime(L,n)=(LocalNoon(n)+(DL(L,n)/2))
PA(n,m)=90-(0.066*((LocalNoon(n)-h(m))))
STTA(L,n,m)=PA(n,m)*(Sunrisetime(L,n)+Ht)
SPTA(L,n,m)=PA(n,m)*(Sunsettime(L,n)-Ht)
Ni(count)=STTA(L,n,m)-1025
Ni1(count)=SPTA(L,n,m)-930
[azi] =[dl*cos(theta),PA,TA]