Automated door for chicken house

Automated door for chicken house © GPL3+

Automatic opening/closing of the front door of a chicken coop based on the day light measured by a LDR

  • 997 views
  • 0 comments
  • 6 respects

Components and supplies

Necessary tools and machines

09507 01
Soldering iron (generic)
4966285
Solder Wire, Lead Free

Apps and online services

About this project

Introduction

If you like fresh eggs for your morning omelettes or your bakery projects, owning chickens is really the thing to do! On top of the good company, they provide top-quality eggs and are of very little effort to take care of.

As you might expect while living in the countryside though, all type of animals from the food chain can be found, and so are foxes. These guys love chicken-based dish and it can literally be a disaster if one manages to get inside your chicken coop.

To prevent foxes from making a mess in your chicken coop, one must be able to close safely the door overnight to protect the chicken from the ferocious predators!

The chickens are free to go out during the day and enjoy fresh air and grass (despite what the above pic shows), but must really go inside to go through a safe night sleep. They are doing it by themselves already, but the door needs to be opened/closed manually every morning/evening.

If you forget only once to close the door overnight, you are very likely to find your chicken eaten by predators the next day.

The project

After being self-initiated with Arduino during Covid-19 lockdown using the "beginner kit", I was looking for a first project to practice on these new skills. This door seemed like a good case to be automated... it was really annoying doing in manually every morning/night and there was of course a risk of forgetting it and therefore endanger the chickens.

The idea was very basic: being able to automatically pilot the chicken coop door:

  • open the door in early morning so the chickens can get out enjoy the fresh air
  • close the door as soon as it gets dark so the chicken can rest safely overnight

How it works

Once plugged to the battery, the door will initiate by opening. By pressing the switch, it will either open/close depending on its state. As soon as the light is too high or too low (threshold defined in the code), and this for a certain amount of time (threshold "hysteresis" defined in the code), the DC motor will start and proceed with the opening or closing.

Most of the hardware used can be found below:

  • Battery 12V
  • DC motor
  • LDR + switch button
  • 2x limit switches
  • Arduino Uno
  • Arduino motor shield rev3

In work

A bit of DIY was also used to implement the mechanism:

  • Old drawer sliding guide for the door
  • Fishing line to pull up the door

Slowly but safely!

Video of the manual losing + opening as it was bright enough outside

In the video, we see a manual closing by pressing the switch, for demo purpose. After 10 sec, as enough light reaches the LDR sensor outside, the door reopens and will remain so until dark.

Conclusion & next steps

This project is technically very simple, but surely has practical benefits:

  • It prevents from waking up early morning to open manually the door to the chicken
  • It ensures that as soon as it gets dark, the chicken can rest safely in the housing
  • When nobody is around for the week-end... the chicken can stay by themselves without a risk for a few days!

A lesson learnt for those who would like to reproduce the project:

Due to slow opening of the door, the chickens tend to force there way out in the morning... in this way they push on the lower part of the door and the upper limit switch can somehow be bypassed. As a result, the motor keeps pulling the cable indefinitely. Few hints to prevent issues:

  • Using a fishing line as cable is a good way to secure the motor in case the top sensor has a defect or is bypassed: the cable will break first and not the motor or the door mechanism
  • Make sure the guiding slide is long and rigid enough so it wont be pushed away from its trajectory toward the sensor by a chicken
  • Increase the opening speed eventually

As for any engineering project... improvement is always needed! Potential for next step:

  • Integrate food & water supply to this Arduino board for more autonomy
  • Alert when egg is available (using weight change?)
  • Any idea... please feel free to propose!

Code

Code Arduino
How to adapt:
- DC Motor rotational direction: lines 204 et 210 (to be updated depending on how it is mounted).
- hysteresis threshold duration: line 31 (time needed at a certain brightness threshold before the engine starts).
- Brightness threshold: lines 25 and 26 (normalized brightness in % from when it will open/close the door, to be adjusted for your case depending on your sensor voltage output as well as the position (more or less exposed to shadow)
// DC Motor shield uses chanels D8 - D11 - D13 - A1 => do not use for other I/O!

/////////////////////////////////////////////////////////
//----------------------VARIABLES----------------------//
/////////////////////////////////////////////////////////

// Pins
const int brightnessPin = A4; //BasDroit Rouge Noir LDR
const int limitSwitchDownPin = 2; // HautDroit Jaune Blanc
const int limitSwitchUpPin = 9;// HautDroit Rouge Noir
const int switchPin = 10; //BasDroit Jaune Blanc

// Intitialize switches
int switchState = 0;
int limitSwitchUpState = 0;
int limitSwitchDownState = 0;

//Calibrate brightness  - Max voltage corresponds to min brightness of LDR
float brightnessMinVoltage = 5;
float brightnessMaxVoltage = 0;
float brightnessMin = 0.0;
float brightnessMax = 100.0;

//Threshold brightness to open/close door
float brightnessLowThreshold = 1.5; //in %
float brightnessHighThreshold = 10; //in %

//Hysteresis variables to avoid abrut incessant opening/closing of the door
int hysteresis_opening; //Compteur pour éviter ouverture brusque 
int hysteresis_closing; //Compteur pour éviter fermeture brusque 
float hysteresisThreshold = 100; // *0,1 in s

int previousSwitchState;
int currentSwitchState = 0;


/////////////////////////////////////////////////////////
//------------------------SETUP------------------------//
/////////////////////////////////////////////////////////

void setup() {
  
  Serial.begin(9600); // open a serial connection to your computer

  //Switches 
  pinMode(switchPin, INPUT);
  pinMode(limitSwitchUpPin, INPUT);
  pinMode(limitSwitchDownPin, INPUT);

  //Motor (Setup on Channel B of the shield)
  pinMode(13, OUTPUT); //Initiates Motor Channel B pin
  pinMode(8, OUTPUT); //Initiates Brake Channel B pin

}


/////////////////////////////////////////////////////////
//-------------------------LOOP------------------------//
/////////////////////////////////////////////////////////

void loop() {

  //Read state of the switches
  switchState = digitalRead(switchPin);
  limitSwitchUpState = digitalRead(limitSwitchUpPin);
  limitSwitchDownState = digitalRead(limitSwitchDownPin);  

  //When switch is pressed, store the info into difference btw below variables
  if (switchState == HIGH) { 
    previousSwitchState=currentSwitchState;
    currentSwitchState++;  
  }


  ///////////////////////////
  //      INITIALIZE       //
  ///////////////////////////

  //When turning on the arduino, always open the door first
  if (millis() < 1000) { 
      while (limitSwitchUpState != HIGH) {
          // Open door
          openDoor();
          limitSwitchUpState = digitalRead(limitSwitchUpPin);
          limitSwitchDownState = digitalRead(limitSwitchDownPin);  
      }
  }

  ///////////////////////////
  //   MESURE BRIGHTNESS   //
  ///////////////////////////
  
  //Get voltage in analogic
  int brightnessAnalog = analogRead(brightnessPin);
  //Convert to V
  float brightnessVoltage = (brightnessAnalog / 1024.0) * 5.0;
  //Convert to %brighntess
  float brightness = (brightnessMax - brightnessMin) / (brightnessMinVoltage - brightnessMaxVoltage) * brightnessVoltage
               + (brightnessMax * brightnessMaxVoltage - brightnessMin * brightnessMinVoltage) / (brightnessMaxVoltage - brightnessMinVoltage);


  ///////////////////////////
  //         DEBUG         //
  ///////////////////////////

  Serial.print("BP bas: ");
  Serial.print(limitSwitchDownState);
  Serial.print("\t BP haut: ");
  Serial.print(limitSwitchUpState);
  Serial.print("\t brightness %: ");
  Serial.print(brightness);
//  Serial.print(" \t brightness analog: ");
//  Serial.print(brightnessAnalog);
//  Serial.print(" \t brightness voltage: ");
//  Serial.print(brightnessVoltage);
  Serial.print(" \t hyst_open: ");
  Serial.print(hysteresis_opening);
  Serial.print(" \t hyst_clos: ");
  Serial.print(hysteresis_closing);
//  Serial.print(" \t switch: ");
//  Serial.print(switchState);
  Serial.print(" \t curr_switch: ");
  Serial.print(currentSwitchState);
  Serial.print(" \t prev_switch: ");
  Serial.println(previousSwitchState);


  ///////////////////////////
  //          DOOR         //
  ///////////////////////////

  // CLOSING - if low brightness
  if (brightness < brightnessLowThreshold && limitSwitchDownState == LOW) {
      hysteresis_closing++;

      delay(100);

      // Do only if brighntess remains below the threshold for a certain time
      if(hysteresis_closing > hysteresisThreshold){ 
          // Close door
          closeDoor();
      }
  }

  // OPENING - if high brightness
  else if (brightness > brightnessHighThreshold && limitSwitchUpState == LOW) {
      hysteresis_opening++;
      delay(100);
    
      // Do only if brighntess remains below the threshold for a certain time
      if(hysteresis_opening > hysteresisThreshold){ 
          // Open door
          openDoor();
      }
  }
 
  else {
      analogWrite(11, 0);   //Stop motor
  
      //initialize hysteresis for LDR activation
      hysteresis_opening=0;
      hysteresis_closing=0;
  }

  // CLOSING - if switch button pressed
  if (currentSwitchState != previousSwitchState && limitSwitchUpState == HIGH) {
      while (limitSwitchDownState != HIGH) {
        
          // Close door
          closeDoor();
          limitSwitchUpState = digitalRead(limitSwitchUpPin);
          limitSwitchDownState = digitalRead(limitSwitchDownPin);  

      }
      previousSwitchState = currentSwitchState;
      analogWrite(11, 0);   //Stop motor
   }

  // OPENING - if switch button pressed
  if (currentSwitchState != previousSwitchState && limitSwitchDownState == HIGH) {
      while (limitSwitchUpState != HIGH) {
        
          // Open door
          openDoor();
          limitSwitchUpState = digitalRead(limitSwitchUpPin);
          limitSwitchDownState = digitalRead(limitSwitchDownPin);  
          
      }
      previousSwitchState = currentSwitchState;
      analogWrite(11, 0);   //Stop motor
   }
}


/////////////////////////////////////////////////////////
//----------------------FUNCTIONS----------------------//
/////////////////////////////////////////////////////////

// Function to open or close the door
// To reverse engine rotation, juste change the line in the functions:
// digitalWrite(13, HIGH); // to digitalWrite(13, LOW); or reverse

void closeDoor () {
        digitalWrite(13, HIGH); //Establishes backward direction of Channel B
        digitalWrite(8, LOW);   //Disengage the Brake for Channel B
        analogWrite(11, 255);   //Spins the motor on Channel B at full speed
}

void openDoor () {
        digitalWrite(13, LOW); //Establishes forward direction of Channel B
        digitalWrite(8, LOW);   //Disengage the Brake for Channel B
        analogWrite(11, 255);   //Spins the motor on Channel B at full speed
}

Schematics

Schematics
Porte automatique poulailler bb rux9wabqqt
Schematics_Fritzinig
https://fritzing.org/
porte_automatique_poulailler_ujmQ4bXKgv.fzz

Comments

Similar projects you might like

Automated Driveway Gate(s)

Project tutorial by K Gray

  • 2,724 views
  • 3 comments
  • 7 respects

Automated Garden

Project tutorial by Thomas sxt

  • 33,903 views
  • 15 comments
  • 96 respects

Enter the house like a Sith Lord

Project tutorial by Prasantha Jayakody

  • 24,818 views
  • 10 comments
  • 84 respects

Arduino Automated Parking Garage

Project tutorial by ashraf_minhaj

  • 15,827 views
  • 11 comments
  • 35 respects

VSB Chicken Coop Door Opener Repair / Upgrade

Project tutorial by Erik de Ruiter

  • 8,421 views
  • 11 comments
  • 32 respects

Automated Dehumidifier Sump Pump

Project tutorial by Zachary J. Fields

  • 7,920 views
  • 10 comments
  • 23 respects
Add projectSign up / Login