Automatic chicken door

Hello guys,

I would like to ask you for help. I do have a automatic door opening using actuator. It is based on the time (for every single day).
Unfortunately, I am lost with the code. even if I have declared variables as “long” it does not return me values bigger than 65535.
I would appreciate any help with this.

Thank you in advance

P.S: code is too long, so pasting as attachment

code.txt (13 KB)

“ does not return me values bigger than 65535.”

Because you are using an ‘int’ integer.

Use ‘unsigned long’.


  • word (16 bit) (unsigned int) - unsigned number from 0-65535

  • unsigned long (32 bit) - unsigned number from 0-4,294,967,295. The most common usage of this is to store the result of the millis() function, which returns the number of milliseconds the current code has been running

Hmm, I thought that I use long... as you can see in the code

static const long sunsetAr[] PROGMEM = {62760,62820,62820,62880,62940,63000,....

Why store the sun position when you can easily calculate it? https://github.com/KenWillmott/SolarPosition

I'm a newbie and building an automatic chicken door also. I find your code very interesting. If you want the door to open and close at sunrise and sunset, wouldn't it be easier just to use an light detecting resistor? That is what I am using currently, and this way you won't have to store the sunrise/sunset times.

Solved - converted to minutes. so no "long" is needed. Thanks to guys in CZ :)

freedomlantern: wouldn't it be easier just to use an light detecting resistor?

It's quite difficult to get right using an LDR. Affected by weather conditions, easily fooled by partly cloudy skies etc.. Chooks not fooled by such things!

mike_cz: Hmm, I thought that I use long... as you can see in the code

static const long sunsetAr[] PROGMEM = {62760,62820,62820,62880,62940,63000,....

You need to put "UL" after each number literal, e.g. "62760UL,62820UL"...