Author Topic: Azimuth Incorrect?  (Read 1486 times)

ptroy

  • New Member
  • *
  • Posts: 4
    • View Profile
Azimuth Incorrect?
« on: December 14, 2014, 12:14:41 AM »
Ok, so what I am using is a stripped down version of the code to only calculate sun position - no control. Hopefully I haven't mucked anything up.

Now, using this website http://www.sunearthtools.com/dp/tools/pos_sun.php

And comparing the output from the arduino - elevation seems fine but azimuth is incorrect.


Code: [Select]
  #include <Flash.h>
  #include <EEPROM.h>
  #include <BigNumber.h>
  #include <BigNumberMath.h>
 

//PUT YOUR LATITUDE, LONGITUDE, AND TIME ZONE HERE
  float latitude = -37.788;
  float longitude = 175.324;
  float timezone = 12;
 
//If you live in the northern hemisphere, put 0 here. If you live in the southern hemisphere put 1.
  int useNorthAsZero = 1;
   
//BigNumber Library Settings
  int calculationScale=10;
  int calculationSpeed=0;// 0 for slow, 1 for fast (but less accurate)
//
  float pi = 3.14159265, SunsAltitude, SunsAzimuth, h, delta;

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

void loop()

 
  int month, year, day, dayOfWeek;
  float hour, minute, second;
  month = 12;
  year = 2014;
  day = 14;
  dayOfWeek = 1;
  hour = 14;
  minute = 30;
  second = 45;
 
 

  findSunsAltAndAzOne(year, month, day, timezone, hour, minute, second, latitude, longitude);
      SunsAltitude = SunsAltitude + (1.02/tan((SunsAltitude + 10.3/(SunsAltitude + 5.11)) * pi/180.0))/60.0;//Refraction Compensation: Meeus Pg. 105
     
     
    if(useNorthAsZero==1){
      if (SunsAzimuth<0){
      SunsAzimuth=(SunsAzimuth+180)*-1;
      }
      if (SunsAzimuth>0){
      SunsAzimuth=(SunsAzimuth-180)*-1;
      }
     
         
      //Serial.print("Sun's Azimuth Modified for Southern Hemisphere: ");
      //Serial.println(SunsAzimuth);
      }
       Serial.print("Sun's Alt: ");
           Serial.println(SunsAltitude,3);
           delay(50);
           Serial.print("Sun's Az: ");
           Serial.println(SunsAzimuth , 3);

  }



Gabriel

  • Administrator
  • Hero Member
  • *****
  • Posts: 651
    • View Profile
Re: Azimuth Incorrect?
« Reply #1 on: December 15, 2014, 02:47:38 PM »
Hi ptroy,

The azimuth can be measured using either north as the zero angle or south as the zero angle. It looks like the web link uses north as zero. The program for the Arduino, however, uses south as zero. You'll probably be able to get both angles to match by adding 180 degrees to the Arduino programs output.

If not, let me know.
Thanks!
Gabriel


ptroy

  • New Member
  • *
  • Posts: 4
    • View Profile
Re: Azimuth Incorrect?
« Reply #2 on: December 16, 2014, 02:27:53 PM »
Hi Gabriel,
I've tryed changing useNorthAsZero from 0 and 1, it does change the azimuth but never anywhere near what the website is showing for the same input data. I've tryed setting the lat/long to somewhere in the northern hemisphere and trying that but they still do not match, so it makes me think I am missing something simple here.

Gabriel

  • Administrator
  • Hero Member
  • *****
  • Posts: 651
    • View Profile
Re: Azimuth Incorrect?
« Reply #3 on: December 17, 2014, 06:59:37 AM »
Do you mind posting the example output from the program? My Mega is currently assigned to other things right now.

ptroy

  • New Member
  • *
  • Posts: 4
    • View Profile
Re: Azimuth Incorrect?
« Reply #4 on: December 17, 2014, 02:21:16 PM »
Output from arduino:


Sun's Az: 73.538
Sun's Alt: 57.223



Output from sun earth tools:

Suns Az: 286.64
suns Alt: 57.36


ptroy

  • New Member
  • *
  • Posts: 4
    • View Profile
Re: Azimuth Incorrect?
« Reply #5 on: December 17, 2014, 07:10:04 PM »
Playing with a calculator I can make it work, So i think its the southern / northern hemisphere calculation part not working. I will look in to it more when I get some more time..

Gabriel

  • Administrator
  • Hero Member
  • *****
  • Posts: 651
    • View Profile
Re: Azimuth Incorrect?
« Reply #6 on: December 18, 2014, 07:36:10 AM »
Ok I'm dumb. I forgot that I modified the Az output in the southern hemisphere to mirror the motion in the northern hemisphere. I have the full explanation here. http://www.cerebralmeltdown.com/northern-and-southern-hemisphere-differences-in-the-sun-tracking-heliostat-program/

Anyway, to make the output match you would set useNorthAsZero to 0 and then add 180.

Sorry about that. It's been so long since I've put much thought into southern hemisphere examples that I had forgotten that I had it set up like that. I added a warning to the documentation above to hopefully make it clearer to people.