EmbeddedRelated.com
Forums

Sunrise/Sunset calculation

Started by Tim Dale November 9, 2005
Hello all,

I have a question. I'm tyring to make a game feeder that goes off at
certain times of the day, like 1 hour after sunrise and 1 hour before
sunset. Obviously this time changes every day. Is it possible to make
a program to run on an AVR that can do that? If I input a location
default, the time, and the day will it work like a clock and calculate
the correct time to go off every day, sending a signal to a small
motor for say 20 seconds?

As you can probably tell I'm rather new to microcontrollers, but I
think it shouldn't be to hard for a first time project




That should be easy to do. Look for real-time clock circuits and
programs. There's probably something on AVRFreaks.

Zack On Wed, 9 Nov 2005, Tim Dale wrote:

> Hello all,
>
> I have a question. I'm tyring to make a game feeder that goes off at
> certain times of the day, like 1 hour after sunrise and 1 hour before
> sunset. Obviously this time changes every day. Is it possible to make
> a program to run on an AVR that can do that? If I input a location
> default, the time, and the day will it work like a clock and calculate
> the correct time to go off every day, sending a signal to a small
> motor for say 20 seconds?
>
> As you can probably tell I'm rather new to microcontrollers, but I
> think it shouldn't be to hard for a first time project
>




On avrfreaks.net, take a look at OPEX in the user contributed academy
projects. It can run user code segments at scheduled specific dates/times
recurring intervals, etc. You'd have to code in your process you add to OPEX
a table of sunset/sunrise times by month or week for your latitude. You can
calculate this mathematically, assuming no nearby mountains to change the
elevation of your horizon. It's easier to just do a table lookup. Maybe
interpolate between two entries in the table if you want that accuracy.

In OPEX, if you wanted smaller code, just lift the date/time routines. They
use a periodic timer interrupt on the AVR. There's a newer version of OPEX
that reads the date/time from a hardware clock/calendar chip every few
minutes, and on power-up. The unique thing about OPEX is that it runs
whatever C processes you wish at given month/day/year,
hour/minute/second/millisecond. Most schedulers just have delays of X
milliseconds and the rest is up to you.

-----Original Message-----
From: avrclub@avrc... [mailto:avrclub@avrc...] On Behalf Of
Tim Dale
Sent: Tuesday, November 08, 2005 8:36 PM
To: avrclub@avrc...
Subject: [AVR club] Sunrise/Sunset calculation

Hello all,

I have a question. I'm tyring to make a game feeder that goes off at
certain times of the day, like 1 hour after sunrise and 1 hour before
sunset. Obviously this time changes every day. Is it possible to make
a program to run on an AVR that can do that? If I input a location
default, the time, and the day will it work like a clock and calculate
the correct time to go off every day, sending a signal to a small
motor for say 20 seconds?

As you can probably tell I'm rather new to microcontrollers, but I
think it shouldn't be to hard for a first time project

Yahoo! Groups Links


Hi

I saw a project like this a while back.

The micro had a light sensor that was connected to an A/D port. A
reading was taken periodically - say every minute. You don't need to
know the time, just which tick count each reading occurred on.

Record when it got dark enough to call it sunset and when it got light
enough to call sunrise. Ignoring for now the fun of daylight savings
time, midnight and midday are halfway between these two events. Since
midnight and midday don't change much (ignoring serious storms and
eclipses), an event just needs to happen so many ticks after whichever
you choose. The system was self-calibrating for day length changes as
midnight and midday are re-calculated every day.

Say we set the counter to zero at sunrise and record the value (in
minutes) at which sunset occurs. This might be at minute 420 for a
seven-hour day length. A reasonable prediction for sunrise will be 1020
minutes later so you can activate your feeder after 960 ticks - one hour
before sunrise.

Hope that makes sense.

Pete Harrison Tim Dale wrote:
> Hello all,
>
> I have a question. I'm tyring to make a game feeder that goes off at
> certain times of the day, like 1 hour after sunrise and 1 hour before
> sunset. Obviously this time changes every day. Is it possible to make
> a program to run on an AVR that can do that? If I input a location
> default, the time, and the day will it work like a clock and calculate
> the correct time to go off every day, sending a signal to a small
> motor for say 20 seconds?
>
> As you can probably tell I'm rather new to microcontrollers, but I
> think it shouldn't be to hard for a first time project >
>
> Yahoo! Groups Links >
>