Problems calculating the position of the sun

I have a error with the librery SunPosition, this is my code

#include <SunPosition.h>
#include <UnixTime.h>

float latitude = 37.7749;    
float longitude = -122.4194; 
int timeZone = -8;  

unsigned long lastUpdateTime = 0;

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

void loop() {
  unsigned long currentTime = millis();

  if (currentTime - lastUpdateTime >= 10000) {
    lastUpdateTime = currentTime;

    SunPosition sunPosition;

    sunPosition.compute(latitude, longitude, 0, timeZone);

    float solarAngle = static_cast<float>(sunPosition.angle180());

    Serial.print("Ángulo solar: ");
    Serial.print(solarAngle);
    Serial.println(" grados");
  }
}

What is the error?

Where did you find that library?

How does that library know the time of day?

This library works extremely well, and I recommend it: GitHub - KenWillmott/SolarPosition: Arduino Library to calculate the position of the sun relative to geographic coordinates

You do need to give it the correct time of day.

I would think that the position of any celestial body is expressed as two coordinates

This might be written for "terrestrial" observers, with lat/lon is right-ascension and angle is declination to avoid introducing new terms too soon.

HI, @alfredo133
Welcome to the forum.

What model Arduino are you using?
Does it compile?

Thanks.. Tom.. :grinning: :+1: :coffee: :australia:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.