Moon rise/set implementation

Share you PDE file with our community
User avatar
Posts: 5351
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Wed Mar 20, 2013 8:44 pm
Hey guys,

So, I found this other aquarium controller code at http://code.google.com/p/stilo/ that had ported a javascript implementation of a Moonrise/set calculator into Arduino. I have adapted it to the RA libraries and it looks like it's working great.

Anyway if you want to have your moonlights follow an actual rise/set calculated based on GPS location, then here's what you have to do..

Code: Select all
#include Moon.h


And then in your loop() function, add this

Code: Select all
moon_init(21,-73); // pass it lat / lon - it uses ints for the caclulation...


You will then have access to the Moon struct which has the following definition:

Code: Select all
struct moon_t
{
  boolean isRise;
  boolean isSet;
  byte riseH;
  byte riseM;
  byte setH;
  byte setM;
  float riseAZ;
  float setAZ;
}


So you'll be able to do something like this:

Code: Select all
  if (Moon.isRise) {
    ReefAngel.PWM.SetDaylight(MoonPhase());
    ReefAngel.PWM.SetActinic(MoonPhase());
  } else {
    ReefAngel.PWM.SetDaylight(0);
    ReefAngel.PWM.SetActinic(0);
  }


or add this to your display

Code: Select all
    sprintf(buf, "%02d:%02d", Moon.riseH, Moon.riseM);
    ReefAngel.LCD.DrawText(COLOR_BLACK,DefaultBGColor,x,y,"MR:"); x+=21;
    ReefAngel.LCD.DrawText(COLOR_RED,DefaultBGColor,x,y,buf);
    sprintf(buf, "%02d:%02d", Moon.setH, Moon.setM); x+=36;
    ReefAngel.LCD.DrawText(COLOR_BLACK,DefaultBGColor,x,y,"MS:"); x+=21;
    ReefAngel.LCD.DrawText(COLOR_RED,DefaultBGColor,x,y,buf); x+=36;
    if(Moon.isRise) ReefAngel.LCD.DrawText(COLOR_RED,DefaultBGColor,x,y,"@");
    else ReefAngel.LCD.DrawText(COLOR_RED,DefaultBGColor,x,y,"_");
Attachments
Moon.h
(8.39 KiB) Downloaded 319 times

Posts: 12276
Joined: Fri Mar 18, 2011 6:47 pm
PostPosted: Wed Mar 20, 2013 9:10 pm
Cool :)
Just as curiosity, without having to open the h file, did you change it to use our Time.h library??
What is the time that we had moonrise today? :)
Roberto.
User avatar
Posts: 5351
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Thu Mar 21, 2013 2:48 am
Yeah i changed it to use out time library.

Rise and set on my screen:
15:32 4:24

There may be some logic in this i still dont understand because my lights are still on lol.. But the times look ok.

They dont match the page that the source came from, but the times change each day properly...

So maybe not exact but Im not an astronomer :) it does take latitude and longitude..

I'll need to look further why the boolean is keeping my light on right now :)
User avatar
Posts: 5351
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Thu Mar 21, 2013 3:49 am
Alright, I have a fix in, so lights are off at the moment...we'll see if they go on tonight.

There may also be some logic issues when calculating that I may have to review..I may be getting the next days set time while still in the previous days cycle...maybe...
User avatar
Posts: 5351
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Thu Mar 21, 2013 1:56 pm
Ok, the moon did rise :) Next I want to see if it calculated set time for tomorrow or if I'll need to wait till after midnight. I'll know when I get home :)

Will also test the new PWMSlope function.
User avatar
Posts: 5351
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Fri Mar 22, 2013 5:18 am
And the moon did set...did not get to see what today's calculation was...I'll have to just wait and see...

The PWMSlope function worked for overnight still :) needs to be checked for standard use now too.

Posts: 267
Joined: Fri Jul 20, 2012 7:13 am
Location: Oakley, CA
PostPosted: Fri Mar 22, 2013 7:40 am
This is very cool, Lee! Are you using the same lat/lon you use for your lighting? I haven't looked too deep into the sunrise/sunset code so not terribly familiar with how that works at the moment.

~Charlie
User avatar
Posts: 5351
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Fri Mar 22, 2013 11:06 am
Yeah, I'm using the same lat / long right now that I'm using for my SunLocation, but they are not tied to each other. So I'm just setting the same variables. I wanted to keep these seperate so they can stand alone...
User avatar
Posts: 5351
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Fri Mar 22, 2013 2:20 pm
Well at 4:29pm i have a status of moonlights coming on for today. So thats ~hour diff then yesterday.

I think the offset from real moonrise / set may be from the fact that we do not use any timezone in our clock. I need to test with some other locations and see what the result is.

But it looks like its working. I'll try and test pwmslope with the normal condition and if it works we should be good to go...
User avatar
Posts: 5351
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Fri Mar 22, 2013 3:17 pm
New times were 16:24 to 04:58
Next

Return to My PDE/INO file

Who is online

Users browsing this forum: No registered users and 1 guest

cron