Chicken Coop Door Code

Posted by on January 12, 2010

I’ve been writing the code for my arduino controlled chicken coop door. This is what I have so far:

// Troy Watson Arduino Powered Chicken Coop Door
// Waits for the sun to come up, turns a servo to open a drawbridge then waits and closes the bridge.

#include <Servo.h>

Servo servo0;  // create servo object

int sensVal = 0;  // analog pin used for light sensor
int rotateDeg = 1080;    // number of degrees to lower drawbrigde
int darkVal = 55;

void servoUp()
{
servo0.write(rotateDeg); //tells the servo to turn out the winch
}

void servoDown()
{
servo0.write(-1*rotateDeg);  //writes the servo to turn back up?
}

void setup()
{
servo0.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop()
{
if (sensVal > darkVal){                      // duh
delay(360000);                         // waits 6 minutes
if (sensVal > darkVal){                // checks the sensor again to make sure its really the sun not just some retard in the neighbors driveway
servoDown();                     // lets door fall open gracefully
delay(43200000);                 // waits 12 hours.
servoUp();                       // pulls door back up
}
}

}Download it here.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>