Source Code

I've put my coop automation source code on GitHub along with my Arduino Aquarium source code to help others with their projects.  The source on git is shown below.  Also, here's a zip of the libraries used in this project, as I've been told some are not easy to find these days! CoopControllerLibraries.zip
Here's a breakdown of current features for the Coop:

  • Calculate daily sunrise/sunset based on latitude and longitude via the TimeLord library to adjust relative timers
  • Close the coop door after sunset *
  • Open the coop door at sunrise 
  • Fill water bowl after sunrise *
  • Turn the lights on in the coop before sunset *
  • Turn the lights off in the coop awhile after sunset (simulating a 16 hour day, 8 hours darkness encourages laying per Raising Chickens For Dummies) *
  • Feed morning, mid-day, afternoon, and evening *
  • Turn on the fan if it gets too hot in the coop, and turn off when temperature drops
  • Manage the door motor (if open stop the motor, if closed stop the motor, etc.)
  • Fill up the water bowl if the level drops (for thirsty birds)
  • Handle input from controller box (buttons/switches)
  • Handle input from Infrared receiver
* See source constant sections for actual values (e.g. 30 minutes after sunset).

Arduino-Coop GitHub Project

19 comments:

  1. Hello,
    I just wanted to thank you for posting your code. The comments and notes you left are what allowed me to finally get the TimeLord.h library to work.

    Thanks

    ReplyDelete
  2. hi ,
    i m sorry for my english (From France).

    First, thanks for your project and sharring it !
    I m doing a coop almost like you , only door automated with rtc.
    When i m compilling the code , it give me an error
    "PAAG.ino: In function 'void scheduleTodayAlarms()':
    PAAG:99: error: 'nowhour' was not declared in this scope
    PAAG:99: error: 'nowMinute' was not declared in this scope
    PAAG:99: error: 'hourMinuteToHour' was not declared in this scope"

    i tried your other program"aquarium", and it worked well.

    thanks for your help

    ReplyDelete
    Replies
    1. float hourMinuteToHour(int hour, int minute){
      return hour + minute/60.0f;
      }

      Delete
    2. Late reply, but hope you've got it working now. Could be a library or version issue as I'm sure is successfully compiled on my end before I posted the code.

      Delete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Thank you... thank you! We are novice Arduino users and
    your chicken coop sketch is very much like the code we're trying to develop for our school garden's aquaponics greenhouse. We needed sunrise and sunset plus the monitoring and control of various devices, much like your chicken coop. About the only thing we'll still need to develop is linking the sun's altitude during the day to PWM high intensity LED lamps... I'm pretty sure the timelord library has the capability to do this for us... any hints?

    ReplyDelete
  5. I'm not familiar with that feature of the library. You could always simplify and set a timer that started a gradual increase in PWM signal until full brightness over time on the main loop. And then another timer to start a gradual decrease in full brightness. I guess it depends how precise you're trying to get. Good luck!

    ReplyDelete
  6. I'll try for a better understanding of TimeLord. Thanks for the workaround idea.
    Downloaded the code and correct libraries. Upon compiling I get the following errors. Is this a problem with/between the IRremote and IRremoteInt libraries. Any ideas?:


    IRremote\IRremote.cpp.o: In function `MATCH(int, int)':
    /IRremoteInt.h:180: multiple definition of `MATCH(int, int)'
    chickencoopcontroller_ino.cpp.o:C:\Users\emorse\Documents\Arduino\libraries\IRremote/IRremoteInt.h:180: first defined here
    c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/bin/ld.exe: Disabling relaxation: it will not work with multiple definitions
    IRremote\IRremote.cpp.o: In function `MATCH_MARK(int, int)':
    /IRremoteInt.h:181: multiple definition of `MATCH_MARK(int, int)'
    chickencoopcontroller_ino.cpp.o:C:\Users\emorse\Documents\Arduino\libraries\IRremote/IRremoteInt.h:181: first defined here
    IRremote\IRremote.cpp.o: In function `MATCH_SPACE(int, int)':
    /IRremoteInt.h:182: multiple definition of `MATCH_SPACE(int, int)'
    chickencoopcontroller_ino.cpp.o:C:\Users\emorse\Documents\Arduino\libraries\IRremote/IRremoteInt.h:182: first defined here

    ReplyDelete
  7. Forgot to mention that we are using an Arduino Mega. The Arduino Forum notes problems using the IRremote library with the Mega.

    see http://forum.arduino.cc/index.php?PHPSESSID=cee6qp7uhk3b4cobegmggpoer2&action=printpage;topic=28434.0

    The Mega uses pin 9 rather than pin 3 to connect to the ATmega chip OCR2B. Rather than change the coop code, the forum suggests "a minor change in the library." "you should modify the enableIROut() library function to initialize Pin 9, not Pin 3."

    Since many folks would prefer the Mega for extra flexibility, would you: 1.recommend modifying the coop code or the library code. 2. Are changes also required in the IRremoteInt.h library?

    ReplyDelete
  8. Mr Reed do you still visit this blog if you do can you post up your libraries for your aquarium build and the coop some of them are not available or well hidden

    Thank you

    ReplyDelete
  9. Sorry for the delay folks! I have uploaded the libraries for both the Coop and Aquarium projects as a zip file on github. Also linked to from these blogs. Enjoy!

    ReplyDelete
  10. I found a "bug". on line 315 and 362 you call "int nowHr = hourMinuteToHour(hour(), minute());" But hourMinuteToHour() returns a float not an int.

    This can cause calc issues at certain times.

    ReplyDelete
  11. What is calling the scheduleTodayAlarms() function in the loop? how do the alarm once alarms in the function actually make the function work? I am using some of this code and it initializes just fine, but none of the alarms that are being scheduled are actually causing functions to operate.

    ReplyDelete
  12. This comment has been removed by the author.

    ReplyDelete
  13. great work u have done here
    I am having a hard time converting to Celsius any suggestions?

    ReplyDelete
  14. Hi i have an issues with the airtemp. When i Start the manuel watering i have a airtemp error and i can't toggle the light on and off. do you have any ideas?

    ReplyDelete
  15. need to add timelib.h to get it working on my setup. if your getting alot errors like now() etc, try that.

    ReplyDelete
  16. I want to use the RTC PCF8563. What do I need to change in the code to get it to work. I added the library but get error when compiling - 'RTC' was not declared in this scope - With this line - setSyncProvider(RTC.get);

    ReplyDelete
    Replies
    1. I deleted that line which allows it to compile but the time resets to 1970 every time the serial monitor opens and doesn't hold the time that was set from the IDE examples.

      Delete