Fitting Whole year time in an AVR

Go To Last Post
26 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I had a outdoor light timer created which save a start time and a stop time.It works flawlessly but then I noticed that due to changing sunset and sunrise times (season changes) it is not that effective.I thought of using a LDR. No problem in that too it also worked fine but the problem with that is due to dew water and ofcourse rain water spoils the sensor and it dies off even if I have tried to make it waterproof,loosing sensors every now and then is not wise so I thought of a solution and I thought that If somehow every month has it own start and stop time saved according to the sunrise and sunset time then I don't have to worry about the sensor. But I don't know how it can be done .I thought of using switch statements but failed. Any suggestions guys so that I can start on a right path??

I think atmega16 would suffice even thought I can even use a atmega32 but I dont think so that that is necessary.

Thank you guys in advance.smiley

This topic has a solution.

anshumaan kumar

Last Edited: Wed. Feb 19, 2020 - 04:15 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Go on - there are vast numbers of dawn-to-dusk lights on the market which manage to function for years outdoors without problem.

 

It's really not that hard to make your system resistant/tolerant to moisture.

 

The trouble with trying to program day/night times is that it will vary with location, and won't cope things like weather affecting light levels.

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"Unix time" ;-)

 

IOW <time.h>  https://www.nongnu.org/avr-libc/user-manual/group__avr__time.html 

 

But anyway the monitoring of sunrise/sunset is surely as old as Stonehenge at least so in computerland there are surely well known algorithms for calculating rise/set times.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As. Andy said it's not hard to weatherproof your project.

As for the light sensor, I used a photo transistor to make an ambient light sensor. Worked great.

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I recommend using an external real-time clock based on the DS3231.   These modules from eBay are really cheap:https://www.ebay.com/itm/2X-DS32... and they work well.  They have an alarm that can be set be triggered repeatedly at a certain hour:minute:day-of-the-week, or a one-time trigger event. 

 

On this I2C-based module board there is a 4096-byte EEPROM IC, also  I2C-based, that can  hold the sunrise:sunset times for a whole year.  Use these values to set the real-time clock alarm that will tell the microcontroller when to control the lights.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yeah. It's not that hard to achieve that using a LDR but then I thought that it was too simple, Maybe I am just bent upon doing this.Sorry if this seems awkard to you guyswink

Wait a second just tell me that doing this is not beneficial or is it cumbersome to achieve that??

clawson wrote:
But anyway the monitoring of sunrise/sunset is surely as old as Stonehenge at least so in computerland there are surely well known algorithms for calculating rise/set times.

Maybe I was not able to see that on the internet could be because of a missing keyword to search for.

jgmdesign wrote:
I used a photo transistor to make an ambient light sensor.

Ya it works great I have mentioned it's use. 

Thanks for the valuable comments. I will try Cliff's idea for now. Thanks man.

anshumaan kumar

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Simonetta wrote:
I recommend using an external real-time clock based on the DS3231.

Yes thanks man fully aware of that I have never used that though I have used DS1307

Simonetta wrote:
hold the sunrise:sunset times for a whole year.

Woah. Didn't knew that. I will give it a try thanks for the suggestion.

anshumaan kumar

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have used Yellow LED's as a light sensor, they will produce a small voltage when exposed to sunlight, connect it to one of the ADC channels.

Jim

 

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

>Any suggestions guys so that I can start on a right path??

 

You already have one of 'them', whatever is storing your start/stop time. You need 11 more if you want one for each month.

 

uint32_t start_sec = 18000;

uint32_t stop_sec = 68000;

if( (now_sec >= start_sec) && (now_sec < stop_sec) ) light_on(); else light_off();

 

 

uint32_t start_sec[12] = { 18000, 17000, 16000, ..., 17000 };

uint32_t stop_sec [12]=   { 68000, 67000, 66000, ..., 68000 };

uint8_t m = month(); //0-11, or if 1-12 subtract 1

if( (now_sec >= start_sec[m]) && (now_sec < stop_sec[m]) ) light_on(); else light_off(); <- edit - you probably want the light on in the dark, so reverse

 

 

That would be one idea.

 

Last Edited: Wed. Feb 19, 2020 - 01:10 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

curtvm wrote:
You already have one of 'them', whatever is storing your start/stop time.

LOL. Yes technically you are right and I knew that too but I was hoping that there should be a better way to achieve that.

Thanks man for the idea of using arrays unfortunately they completely slipped out of my mind.

 

anshumaan kumar

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Anshumaan wrote:
Maybe I was not able to see that on the internet could be because of a missing keyword to search for.
I just tried:

 

https://en.wikipedia.org/wiki/Sunrise_equation

 

But as noted in other posts above your position on earth (lat/long) are inputs to any such equation so if you were going to calculate it programmatically you'd either need some way (GPS?) to know where you were or you'd need the user to actually give you Lat/Long.

 

If this device is in some fixed location then obviously you can use a look up table as you can say exactly what the times will be throughout the year at that place on Earth.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Simonetta wrote:
hold the sunrise:sunset times for a whole year

But that's only going to hold for a small area.

 

Even across England - which is quite a small place - there's over 20 minutes difference in sunrise and sunset times.

 

And, again, that makes no account for other effects - such as weather.

 

It really does seem to be a huge amount of extra complication just to end up with a worse result!

 

And you'll still need to weather-proof it anyhow!

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
But that's only going to hold for a small area.

Yes I was hoping to install that on my home first.

awneil wrote:
It really does seem to be a huge amount of extra complication just to end up with a worse result!

Well this may sound harsh but it's true .One thing that I have learned is that whatever you make it must be the end result of all the factors taken into account.

awneil wrote:
And you'll still need to weather-proof it anyhow!

Well I think yes.

Thanks.

anshumaan kumar

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

Let's see, 1440 minutes per day, so that will fit easily into a 16 bit number. Any AVR has enough flash to store 732 16 bit ints. Well, not a tiny 10. Then how to know the time, what values to fill in and so on...  Go with a light sensor. Shoot I made one in the '70s with a photo transistor epoxied to the outside of a wooden box sealed with silicone that worked for years. All that was inside was a transformer, diode, capacitor, 741 op amp, transistor, relay and a few resistors.

If you don't know my whole story, keep your mouth shut.

If you know my whole story, you're an accomplice. Keep your mouth shut. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

An important consideration: you  DO NOT need a table with 365 entries. The sunrise and sunset times vary much more slowly than that. Even at once a week, you only end up with 52 entries.

 

Second, you do not need a table with complex hour, minute, second. Just use unix seconds (or equivalent) so that there is just one number for sunrise and one for sunset. 

 

Here, we have sunrise and sunset and "civil sunrise" and "civil sunset". These values are for pilots in determining when it is safe to fly if you are not rated for night-time flight. Civil sunset is typically after the geometric sunset (which, in the case of aircraft, appears to vary  with the observer's altitude). But, there is probably more variation due to weather. That is why light level sensing is the practical way to go.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There have been several projects here for prayer clocks - where prayer times are related to sunrise & sunset. So you might want to look at them ...

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can store the dawn/dusk minutes-past-midight of the 2 solstices for your location and then use linear interpolation.
Not super-accurate, but ...

Last Edited: Tue. Feb 18, 2020 - 10:16 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There’s cheapy wifi lights that are hackable. Assuming you have wifi connectivity, these get the time from the network. Using alternate firmware like Tasmota, you get sunrise/sundown as part of the package. It’s open source so you can see how they calculate it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
There have been several projects here for prayer clocks - where prayer times are related to sunrise & sunset. So you might want to look at them ...

Thanks I think i was missing this keyword . I will search this.

Kartman wrote:
Assuming you have wifi connectivity,

I don't know why my brain panics you are right wifi will do it no need to fill in the time when you have internet. Much more accurate much more reliable and ofcource not limited to small area.Thanks man for helping me rediscover the internet.

Thank you all I think for a offline version unix seconds will do and why do anything else when I have internet. Thank you people once again.See you soon.

anshumaan kumar

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mikech wrote:
You can store the dawn/dusk minutes-past-midight of the 2 solstices for your location and then use linear interpolation.
Not super-accurate, but ...

Going back to the original question, one could use three or four bits for each day as the difference from previous. So for a particular location 180 bytes. Yes, I could find that much eeprom space on a '324 class AVR.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Anshumaan wrote:
Much more accurate much more reliable

Well, it can give you time accurately & reliably - until your internet connection drops - but that still won't account for other "local factors" which will affect the optimum time for the light to be on!

 

The one true indication of when the light needs to be on is, "is it dark?".

 

You can't beat a light sensor for that!

 

Plus it's way easier, simpler, and cheaper. 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Use an LDR, for heavens sake. Otherwise how will you cope with extremely overcast days? Or plagues of locusts? Or eclipses? Are you going to program all future eclipses into this thing? I think not.

 

 

Four legs good, two legs bad, three legs stable.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Wouldn't most people forgive an outdoor light timer on the very rare occasion that it was fooled by a total eclipse that darkened the sky to the point where it mis-activated? ;-)

 

(actually one might actually praise a device that put the lights on when the sky went unusually dark!)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
was fooled by a total eclipse that darkened the sky to the point where it mis-activated?

Surely, that would be an entirely valid activation ?

 

cheeky

 

(actually one might actually praise a device that put the lights on when the sky went unusually dark!)

Indeed

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

Wouldn't most people forgive an outdoor light timer on the very rare occasion that it was fooled by a total eclipse that darkened the sky to the point where it mis-activated? ;-)

 

(actually one might actually praise a device that put the lights on when the sky went unusually dark!)

That was my point. An LDR or photodiode copes with the real-life situation, not a forecasted lighting condition. As as somebody said, you have to weatherproof the thing anyway.

 

 

Four legs good, two legs bad, three legs stable.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

But what does one do when a bird deposits a load of #### on the light sensor ?,
or when a spider decides to live there ? ;)



Time-of-day lighting-control is more suited to be a backup to a light-sensor.
Think of the big outdoor LED displays.,
if the light-sensor fails you do not want midday (or even dusk) brightness-intensity during the night,
and during daylight hours you need more than the night-time brightness.