I have uploaded this example complete to the nano board. It does not give the correct azimuth and elevation for the sun at my latitude and longitude. I know this because I use an application called the suns position at my location today. This is available on the internet.
For instance if you lived in London the app would give you the suns elevation and azimuth at a particular time in London.
I simply uploaded to the board from my laptop from the usb port with no other external connections to the nano. It compiled ok. Are there supposed to be hardware connections to the nano board such as a RTC? Should the nano be powered from an external source rather than just the usb connection?
Any help with this project would be appreciated as then I should be able to get a solar panel aimed directly at the sun once I have the elevation and azimuth. Instead of printing out to the serial monitor the information could be used directly to get servo motors to move the solar panel to the best position.
Please give us some clues as to what you are doing. Start by posting the sketch and details of where you got it from
Like UKHeliBob said, please provide more information.
That being said;
If your calculation is based on time of day, then you would need to supply said time of day to the Arduino either by connecting a RTC or using a time library and setting the time. Either way the Arduino (even your laptop) has no idea what the time is without some time source.
Location and time are needed to calculate solar position. You can fill in the location variables yourself, or get them from a GPS for mobile use. Same for the time. Get them from the PC, a GPS, or a RTC. What you choose depends on your project.
Just wrote a sketch for an ESP32-C3 for a fixed/stationary location and NTP (internet time).
Prints the time and azimuth/elevation.
Leo..
#include <SolarCalculator.h> // jpb10
const float latitude = -45.89854; // negative for southern hemisphere, in DecimalDegrees
const float longitude = 170.38657; // positive for east of Greenwich
const char* wDay[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
const char* mon[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
double az, el; // azimuth, elevation
#include "esp_sntp.h"
unsigned long prevTime;
bool reSync;
time_t now; // epoch
tm tm; // time struct
void cbSyncTime(struct timeval *tv) { // sync callback
reSync = true;
Serial.println("Time Sync");
}
void setup() {
Serial.begin(115200);
delay(10);
WiFi.mode(WIFI_STA);
WiFi.begin("SSID", "PASSWORD"); // YOUR credentials
sntp_set_time_sync_notification_cb(cbSyncTime); // enable callback
configTzTime("NZST-12NZDT,M9.5.0,M4.1.0/3", "nz.pool.ntp.org"); // https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv
Serial.println("Getting local time");
while (!reSync) yield(); // wait here for a valid time string
}
void loop() {
time(&now);
localtime_r(&now, &tm);
if (now != prevTime) {
prevTime = now;
printf("\n%s %u %s %u %02u:%02u:%02u", wDay[tm.tm_wday], tm.tm_mday, mon[tm.tm_mon], tm.tm_year + 1900, tm.tm_hour, tm.tm_min, tm.tm_sec);
calcHorizontalCoordinates(now, latitude, longitude, az, el); // calculate sun angle
Serial.print("Azimuth: ");
Serial.print(az, 4);
Serial.print("\tElevation: ");
Serial.println(el, 4);
Serial.println("");
}
}
Really? God only knows what example that might be, but there has to be a swag of Sun AltAz programmes out there, and all you need is your location and the correct time.
Jan Meeus and Peter Duffet-Smith started this off for small computers, and may still be the keywords, as anything more modern is likely to be derived from them.
It seems that most Arduino solar trackers rely more on finding the best radiation in the sky, which is not necessarily in the direction of the sun. I guess that would save a hell of a lot of maths.
You can upload any sketch using the IDE without peripherals connected. The code will still look at the pins and operate as if devices were giving real data.
You can also compile a sketch on the IDE without a board connected, but only the board selected.
Rather than starting with a solar panel, try using light dependent resistors (LDR) separated by cardboard dividers, with the code reading the LDRs in order to point the simple "panel" at the strongest light source.
There are silly people who track the sun with light sensors that don't know what time or day it is. Silly, silly, silly.
But, would wear out the mechanical components faster by constantly searching for the "bright spot".
Historically (like, 99% of human existence), not knowing time of day or day of week has been normal. Abnormal and pointless was the invention of the watch. What does a plant care what day it is or time of day? I hear they follow the Sun, too, without watches.
Here is the code Bob. I got the example from the examples list on the Arduino IDE. It does not give the correct elevation and azimuth even when you put in your latitude and longitude. Looking at the code it may be getting the time from when you first uploaded the code. Try it yourself guys and see if you get the correct E and A. If you do then you may be able to tell me how you did it.
// SolarCalculator Library for Arduino example sketch: SolarTrackingTimeLib.ino
//
// Monitor the Sun's position in the sky for any location on Earth.
//
// Tested with Arduino IDE 1.8.19 and Arduino Uno
//======================================================================================================================
#include <SolarCalculator.h>
#include <TimeLib.h>
// Location
double latitude = 45.55;
double longitude = -73.633;
int utc_offset = -5;
// Refresh interval, in seconds
int interval = 10;
void setup()
{
Serial.begin(9600);
// Set system time to compile time
setTime(toUtc(compileTime()));
// Set time manually (hr, min, sec, day, mo, yr)
//setTime(0, 0, 0, 1, 1, 2022);
}
void loop()
{
static unsigned long next_millis = 0;
// At every interval
if (millis() > next_millis)
{
time_t utc = now();
double az, el;
// Calculate the solar position, in degrees
calcHorizontalCoordinates(utc, latitude, longitude, az, el);
// Print results
Serial.print(F("Az: "));
Serial.print(az);
Serial.print(F("° El: "));
Serial.print(el);
Serial.println(F("°"));
next_millis = millis() + interval * 1000L;
}
}
time_t toUtc(time_t local)
{
return local - utc_offset * 3600L;
}
// Code from JChristensen/Timezone Clock example
time_t compileTime()
{
const uint8_t COMPILE_TIME_DELAY = 8;
const char *compDate = __DATE__, *compTime = __TIME__, *months = "JanFebMarAprMayJunJulAugSepOctNovDec";
char chMon[4], *m;
tmElements_t tm;
strncpy(chMon, compDate, 3);
chMon[3] = '\0';
m = strstr(months, chMon);
tm.Month = ((m - months) / 3 + 1);
tm.Day = atoi(compDate + 4);
tm.Year = atoi(compDate + 7) - 1970;
tm.Hour = atoi(compTime);
tm.Minute = atoi(compTime + 3);
tm.Second = atoi(compTime + 6);
time_t t = makeTime(tm);
return t + COMPILE_TIME_DELAY;
}
Trackers that find the best radiation also do not need to know the time, long or lat.
Especially two axis devices.
An ATtiny85 could probably do all the calculation work.
Tom..
Aha! I wondered about that....
I assume that, if OP wants to track at all, he may want to track seriously, and therefore is prepared to put up with the mechanical wear and tear. Silly is a relative term.
It's not like that at all JCA34F, except for some people's v1 trackers.
The good ones use some manner of hysteresis to only adjust periodically. They work with shadow and light on both sides of each axis and the difference, with a range of designs.
I've been following what some people use with solar cookers for years. One mobile unit doesn't just point at the sun, it moves itself out of shade from buildings and trees. That's a Stan Wells design, he makes one-offs and resists using MCUs.
The apparent sun moves 1 degree every 4 minutes is also how sun shadows move. Clouds and partial shade complicate that, and where the sun is does not cover those.
Sun tracking has many issues, that makes it more interesting!
Add reflectors and tilt/move options, it could be as fun as model trains while making a real difference! How about that for a topic?
IMO, sensing what is beats aiming where the sun should be in design terms.
Interesting,TNX.
Knowing what time it is, the greatest driver of clock tech has been navigation.
There's a survival trick callled the shadowless shadow stick.
You're lost without a compass in the day. You take a straight stick and stick it in the ground pointing at the sun so it casts no shadow, In a while it casts a shadow that points east. Not always exactly east but when you're lost and trying to not move in circles, it's a good trick.
It seems you're near Montreal.
int utc_offset = -5;
Doesn't that work out to -3 with DST.
The sketch I posted works fine.
Maybe you should try with a $5 ESP32-C3
Leo..
There are multiple social media groups where sun tracking has been discussed for years, browsing those discussions reveals all kinds of things that can save time and effort finding out!
I almost never find MCU solutions on those!
Youtube is often the showroom.
Crude example from days ago: https://www.youtube.com/watch?v=wL9PcGu_xrA&t=22s&pp=ygUSc3VuIHRyYWNrZXIgc29sYXIg
Stan Wells does not use MCU's
I venture that there's a niche topic the forum could explore!
TNX for that.
It does
What happens if you use the current date/time ?
The same can be said about the invention of whatever electronic device you used to type those words.