Introduction: Automatic Chicken Coop Door (arduino)

About: I'm an hobbyist, i like to have fun with arduino and i love instructables!

I will show you how to build an automatic door for the chicken coop with Arduino nano. The door is powered by solar energy and opens and closes automatically based on the sunlight, so the hens will no longer have to wait closed in the chicken coop for the breeder to open the door for them ;)


  • Arduino nano (cheaper and low energy consumption)
  • Stepper motor (i used 28byj-48) and the motor driver shield
  • Photoresistor
  • Powerbank (better solar powerbank)
  • Small photovoltaic panel (If you use a normal powerbank)
  • 10k ohm resistor
  • Wires

Step 1: Arduino Circuit

Put the arduino nano on the breadboard

connect the photoresistor to the 5v. Put the 10k ohm resistor between the photoresistor and the GND. Connect a wire to the A0 pin of Arduino and between the photoresistor and the 10k ohm resistor.

Connect the stepper driver to the 5v and GND.

The signal pins of the driver are connected like these scheme:

driver N4 -> D8 arduino

driver N3 -> D9 arduino

driver N2 -> D10 arduino

driver N1 -> D11 arduino

Circuit done!

ADVISE: you cane connect a fuse between the 5v battery and Arduino to protect Arduino from voltage drops.

Step 2: The Code

#include <LowPower.h>

#include <CheapStepper.h>

const int lightLimitUp = 300;
const int lightLimitDown = 300;
int door = 0  ; //0 closed, 1 opened
int light;

CheapStepper stepper (8,9,10,11);

void setup() {
  stepper.setRpm(13); //stepper makes 13 spins per minute
  digitalWrite(LED_BUILTIN, LOW); //Turn off the builtin led 

  // (Optional)
  // if you want to save even more electricity you can uncomment 
  // these two lines that slow down the clock speed of the Arduino.
  // Obviously the stepper speed is also slowed down and it will go 
  // slower. Be careful if you use the delay statement in your code
  // that slowing down the clock in half, 1000 ms will correspond 
  // to 2000 ms
  //CLKPR = 0x80;
  //CLKPR = 0x01; //clock speed half //0x02 is for 1/4 speed

void loop() {
  // Read the light
  light = analogRead(A0);
  if (light > lightLimitUp && door == 0 ){
  } else if (light < lightLimitDown && door == 1){
  //power down for 10 minutes
  for (int i = 0 ;  i < 75 ; i++){
    LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);

void openClose(){
  if (door == 0){
    spin(true); // counterclockwise
  } else {
    spin(false); // clockwise
  door = 1 - door;

void spin(boolean way){
  // I split the stepper spins because it doesn't 
  // work all together (17 spins in total)
  stepper.moveDegrees (way,  2700);  // 7.5 spins
  stepper.moveDegrees (way,  2700);  // 7.5 spins
  stepper.moveDegrees (way,  720);   // 2 spins

  //Turn off the stepper leds
  digitalWrite (8,LOW);
  digitalWrite (9,LOW);
  digitalWrite (10,LOW);
  digitalWrite (11,LOW);

Click here to download the libraries. Or copy and paste this url in your browser:

You can find the code in my github repository for this project

Or download the code here ⬇

Step 3: (Optional) Hack Arduino to Consume Less Energy

(I take no responsibility if you damage your Arduino in any way. This operation will be carried out at your own risk)

I hacked a chinese clone of the Arduino nano to not spoil the original.

This hack can reduce the power consumption of the Arduino nano.

  1. Remove the resistor near the POW led, like in first picture, so this led will not stay always on.
  2. Remove the voltage regulator behind the Arduino nano, like in second picture. Note that if you remove the voltage regulator, the VIN pin will no longer work. So you have to power the Arduino nano via the 5V pin or via USB.

Step 4: Powerbank Hack

You must also hack your powerbank because otherwise the powerbank after a few seconds will remove the power from the USB ports, as Arduino nano consumes very little current.

I used a 5000mA powerbank. Arduino nano in sleep mode, with the hacks consumes about 0.3mAh. This means that Arduino can run with this battery for 1 year and 11 months. If you use a solar panel to charge the powerbak, the duration of the battery is illimitate.

(I take no responsibility if you damage your powerbank in any way. This operation will be carried out at your own risk)

This operation is very easy.

  1. Cut a mini usb cable, and then take only the red and the black wires.
  2. Weld the red and black cables directly to the battery cables of the powerbank.

Step 5: Installation of the Door

I've build a simple wooden door.

I've build also a box where i put Arduino and the circuit. I used a plastic bag to protect the box from water.

On the stepper motor I applied a wooden wheel that I had at home, so as not to let the wire slide down. You can also use a piece of Lego.

As a wire for the door I used a 0.18mm fishing wire, with 3.5kg seal

Step 6: Photovoltaic Panel Installation

  1. Cut a micro usb wire and weld it to the photovoltaic panel in order to have a wire long enough for your needs.
  2. Place the photovoltaic panel in a sunny place so that it cannot move.
  3. Connect the photovoltaic panel cable to the power bank.

In this way the battery life will be unlimited.