It is currently Thu Jul 31, 2014 2:35 pm


Post a new topicPost a reply Page 1 of 1   [ 3 posts ]
Author Message
 Post subject: Arduino project: Automatic Chicken-Door
PostPosted: Thu Nov 18, 2010 11:23 am 

Joined: Sun Oct 31, 2010 7:52 am
Posts: 11
Following Chris's very useful Arduino class, I decided to do a small practice exercise, using the stepper motor I got from him. When I'm learning a new language, it always works better for me to try doing some real problem, not just some dumb textbook example.

So I decided to see if I could make an automatic chicken-door opener. We have backyard chickens, and they have to be locked in every evening and let out every morning, to prevent predators from doing midnight chicken-snacking. Commercial units run like $180-$400.

I had purchased a Danger Shield, which piggy-backs on the Arduino board and gives me a photocell and some linear potentiometers, so along with the servo motor I thought I had all the parts needed. And sure enough it didn't take long to get something working.

The stepper motor turns a disk of light cardboard (for now) with a wedge cut out of it. The sketch monitors the photocell and rotates the disk 180 degrees when the light level crosses a threshold. A second draft added the ability to read one pot to set the threshold level (don't want to close the door before the chickens have gone to roost) and to read another pot to control the speed of rotation (don't want to create a chicken guillotine).

Of course now I have the more interesting and (for a software guy) challenging part: scaling it up to real-world size and materials. The door has to be strong enough to keep raccoons out and robust enough to not jam when chicken feed and chicken poop and rain-splashed dirt build up on it. And a 3-foot diameter disk would be unwieldy in an average-sized coop. But as an exercise in coding and debugging the Arduino it was very useful, and a lot of fun...

Larry Walker

Code:
// Chicken-House Door automator
// by Larry Walker 11/12/10


//    uses a servo motor to open/close a chicken door
//     responds to photocell to open close at dawn/dusk
//     reads potentiometer 1 to control speed of door open/close
//       (to avoid creating a chicken guillotine!)
//     reads potentiometer 2 to control trigger light-level
//       (to avoid closing door too early (or during thunderstorms?))

#include <Servo.h>

#define LIGHT    3
#define SLIDER1  0
#define SLIDER2  1

const int SHUT = 0;
const int OPEN = 1;

Servo myservo;              // create servo object to control a servo

int pos = 180;              // variable to store the servo position
int light_val;              // variable to store light level
int step_delay;             // variable to store stepper delay value
int trigger_level;          // variable to store trigger light-level

int desired_pos = SHUT;     // desired door position
int curr_pos = SHUT;        // current door position



void setup()
{
  myservo.attach(9);        // attaches the servo on pin 9 to the servo object
  Serial.begin(9600);
}


void loop()
{
  // get the current light level
  light_val = analogRead(LIGHT);
  Serial.print("Light: ");
  Serial.println(light_val);

  // get the delay value
  step_delay = map(analogRead(SLIDER1), 0, 1023, 1, 30);
  Serial.print("Delay: ");
  Serial.println(step_delay);

  // get the trigger-level value
  trigger_level = analogRead(SLIDER2);
  Serial.print("Trigger: ");
  Serial.println(trigger_level);
  Serial.println();


  // check the light level: light=open-door; dark=close-door
  if (light_val < trigger_level) {
    desired_pos = SHUT;
  }
  else
  {
    desired_pos = OPEN;
  }

  if (curr_pos != desired_pos) {
    if (desired_pos == SHUT) {
      // open the door by spinning it to 180
      for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees
      {                                  // in steps of 1 degree
        myservo.write(pos);              // tell servo to go to position in variable 'pos'
        delay(step_delay);               // waits for the servo to reach the position
        // allow for dynamic speed changes
        step_delay = map(analogRead(SLIDER1), 0, 1023, 1, 30);
      }
    }
    else
    {
      // close door by spinning it to 0
      for(pos = 180; pos >= 1; pos -= 1) // goes from 180 degrees to 0 degrees
      {                               
        myservo.write(pos);              // tell servo to go to position in variable 'pos'
        delay(step_delay);               // waits for the servo to reach the position
        // allow for dynamic speed changes
        step_delay = map(analogRead(SLIDER1), 0, 1023, 1, 30);
      }
    }
    curr_pos = desired_pos;
  }

}


Boring still photo attached...

Less-boring movie: http://walkerphotographix.com/vidclips/chicken_door.mov


Attachments:
scaled.chicken_door.jpg
scaled.chicken_door.jpg [ 64.07 KiB | Viewed 3910 times ]
Top
 Profile  
 
 Post subject: Re: Arduino project: Automatic Chicken-Door
PostPosted: Wed Jan 19, 2011 8:48 pm 

Joined: Wed Jan 19, 2011 8:42 pm
Posts: 1
Nice project! I've had success in the past by using a motor shield from Sparkfun (http://www.sparkfun.com/products/9106) and a rechargeable drill motor from an old 12 volt drill. That would probably do the job on a full sized one of these too.
Just my $0.02


Top
 Profile  
 
 Post subject: Re: Arduino project: Automatic Chicken-Door
PostPosted: Sat Jan 07, 2012 2:15 pm 

Joined: Sat Jan 07, 2012 1:44 pm
Posts: 5
If space is an issue, you could use a cam setup to cut your footprint down. Software compensation should be reasonably straightforward.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 3 posts ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron


Powered by phpBB