Go Down

Topic: Chicken Coop Door open/close (Read 5892 times) previous topic - next topic

Ed123

I keep forgetting to close the coop door so I automated the door with an Arduino, a linear actuator from Firgelli Automations, four solid state relays from Fotek (in hindsight this is super over designed), and a real time clock from Sparkfun (uses i2c).

Below is the code. It takes into account the day of the year and adjusts sunrise and sunset. The door opens one hour after sunrise and closes one hour after sunset.

/*
* ChickenCoopDoor.pde
*
* Close door at sunset plus
* Open door at sunrise plus
*
* Once a day just after midnight calculate sunrise and sunset times for the day
*
* Edwin A. Pell III 06/29/2010
*
*/

#include <Wire.h>
#include <Math.h>
#define RTC_ADDR 0x68

int current_day;
int door_opened;
int door_closed;
int sunrise; // in minutes from midnight
int sunset;  // in minutes from midnight

int close_a = 2;
int close_b = 3;
int open_a  = 4;
int open_b  = 5;

int second;
int minutex;
int hour;
int dayOfWeek;
int dayOfMonth;
int month;
int year;


void setup()
{
//  Serial.begin(9600);    

 pinMode(close_a, OUTPUT);
 pinMode(close_b, OUTPUT);
 pinMode(open_a, OUTPUT);
 pinMode(open_b, OUTPUT);
 
 digitalWrite(open_a, LOW);
 digitalWrite(open_b, LOW);
 digitalWrite(close_a, LOW);
 digitalWrite(close_b, LOW);
 
 door_opened = 1;
 door_closed = 0;
 
 Wire.begin();
 ReadTime();
 int current_day = dayOfMonth;
 getRiseSet();
 
}

// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
 return ( (val/10*16) + (val%10) );
}

// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
 return ( (val/16*10) + (val%16) );
}

void OpenDoor()
{
 digitalWrite(open_a, HIGH);
 digitalWrite(open_b, HIGH);
 delay(25000);
 digitalWrite(open_a, LOW);
 digitalWrite(open_b, LOW);
 door_opened = 1;
}

void CloseDoor()
{
 digitalWrite(close_a, HIGH);
 digitalWrite(close_b, HIGH);
 delay(25000);
 digitalWrite(close_a, LOW);
 digitalWrite(close_b, LOW);
 door_closed = 1;
}

void getRiseSet()
{
 sunrise = int(350 + (90*cos(((((month-1)*30.5)+dayOfMonth)+8)/58.1)));
 sunset = int(1075 + (90*sin(((((month-1)*30.5)+dayOfMonth)-83)/58.1)));
}

void NewDay()
{
 current_day = dayOfMonth;
 getRiseSet();
 door_opened = 0;
 door_closed = 0;
}

void ReadTime()
{
 Wire.beginTransmission(RTC_ADDR);   // Open I2C line in write mode
 Wire.send(0x00);                              // Set the register pointer to (0x00)
 Wire.endTransmission();                       // End Write Transmission

 Wire.requestFrom(RTC_ADDR, 7);      // Open the I2C line in send mode

 second     = bcdToDec(Wire.receive() & 0x7f); // Read seven bytes of data
 minutex    = bcdToDec(Wire.receive());
 hour       = bcdToDec(Wire.receive() & 0x3f);  
 dayOfWeek  = bcdToDec(Wire.receive());
 dayOfMonth = bcdToDec(Wire.receive());
 month      = bcdToDec(Wire.receive());
 year       = bcdToDec(Wire.receive());
}


void  loop()
{  
 delay(300000);
 ReadTime();
 if (current_day!=dayOfMonth)
 {
   NewDay();
 }
 
 int current_time = (hour*60)+minutex;
 
 if (current_time > (sunrise+60))
 {
   if (door_opened == 0)
   {
     OpenDoor();
   }
 }
 
 if (current_time > (sunset+60))
 {
   if (door_closed == 0)
   {
     CloseDoor();
   }
 }
}

Ed  

sciguy

That's the first arduino powered chicken door I've ever seen!!!!!!
Congratulations on being the first to do this!
:D



Oh, and by the way, please use code brackets around code.  In the forum editor highlight your code, and click the button that looks like a #.
Soundcloud page: http://soundcloud.com/beefinator-2
Youtube channel: http://www.youtube.com/user/beefinator14
Old soundcloud page (ran out o

TchnclFl

Nifty use of that Arduino!  I feel like I've seen a video of it in action before (I recall something about a locking system that keeps animals from getting in).

Very nice :).

Meinaart

There was a whole article on automated Chicken Coop Doors in the latest MAKE magazine (page 64, issue 22), worth a read! Might be a nice inspiration for expanding your project Ed123 ;).

bld

Maybe it was this http://hackaday.com/2010/05/03/automated-chicken-coop-door/ locking system?
captain-slow.dk | non contagious!

Ran Talbott

Not to diminish the coolness of this project,  but it actually has been done before.

A forum search for "chicken coop" will turn up a reference to other threads on the subject.  It would be a good idea to read them,  because there were some discussions of how to avoid accidental avian decapitation through lowering the door at inappropriate times.

As a matter of curiosity,  is this sudden interest in automated chicken care because of an effort I saw on the news recently,  where European cities give (sub)urban families chickens so they'll eat household food waste,  and reduce the volume of garbage?

zoomkat

I've seen post in the past in this forum concerning critter doors. One has to be careful to make the door "critter safe" while still meeting various design needs. The make magazine door looks cool but way overdone. The racoon lock probably could be eliminated by simply not giving the racoon a good way to grip the door to lift it up. Linear actuators have the power to be critter crushers.
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

bld

#7
Jul 04, 2010, 10:07 am Last Edit: Jul 04, 2010, 10:22 am by bld Reason: 1
Quote
Linear actuators have the power to be critter crushers.

Don't have to use one, here is my solution to that problem. :)


(I know it is dirty, but won't clean it, have to smell as much of my cat as possible or others will come in, and the lock is not done yet, still struggeling with the rfid range being about 5mm :()
That is strong enough to hold the cats out, and at the same time not strong or big enough to hurt anyone.

My program is keeping an eye on the magnet holding the door closed at the same time, so 5 seconds after unlocking, it will wait for the door to close, and if it have been closed for 500 ms (not just a fast sving-by) it will turn the servo to lock position again.

This is only keeping other cats out, which is good enough for me, but two way can be made too, just cut away a bit of the plastic at the bottom, and the servo is then thin enough to go underneath the swinging door and reach the arm up on the outside of it, just make sure to somehow waterproof it then.
captain-slow.dk | non contagious!

pluggy

Feeding the cat's mate's from the neighbours is part of the joys of owning a cat (or rather having a cat own you.......)   :)
http://pluggy.is-a-geek.com/index.html

bld

Quote
Feeding the cat's mate's from the neighbours is part of the joys of owning a cat

Biggest problem is the nightly fights inside my scullery. ;)
captain-slow.dk | non contagious!

Ran Talbott

Quote
Feeding the cat's mate's from the neighbours is part of the joys of owning a cat


Not always:  not only have the two strays that have been sponging off me for years failed to learn proper gratitude,  they've added insult to injury by teaching one of my own to be leery of me,  too.

If I weren't such an incurable softy,  I'd move the kibble and water bowls indoors and let the ingrates starve.

wyager

I like the project-the neighbor's dog came over and killed all of our chickens a while back (at least the foxes ATE them lol), I might be doing something like this if we still had them.

spidie

Awesome! Just what I needed... and I thought I was the only person crazy enough to think of this.

The next thing I want is something that tweets when one of the chickens lays an egg!

Go Up