Project tutorial
Automatic Solar Powered Chicken Door

Automatic Solar Powered Chicken Door © GPL3+

How to create and program a door that open and close at sunrise and sunset, powered by solar panel.

  • 3 respects

Components and supplies

Necessary tools and machines

09507 01
Soldering iron (generic)
PCB with holes
Digital multimeter

Apps and online services

About this project

I wanted to build something with an arduino since I have received and completed an "arduino starter kit". Therefore, this project is my first attempt at building something with an arduino (and electronics) and I have done a lot of mistakes along the way. This is far from being perfect and I can't guaranty it will work out if you try this yourself. I have written down all the mistakes I have done so you could avoid them.

English is not my native language, sorry for potential grammatical or syntactic errors.

Feedback will be greatly appreciated.


I needed to build a door for chickens that closes and opens automatically at sunrise and sunset. The door could not be connected to the grid (too far from the house) so batteries and solar panels were a requirement. If you have the chance to be able to connect your system to the grid, do so. Battery charging/management is a nightmare.

If, like me, you are new at this, build your circuit on a breadboard first to be sure everything works fine, then solder.


An H-Bridge is a component that will allow you to control your DC Motor. I went with a L298N double H-Bridge at the beginning because I thought that its 5V output would allow me to power the logical circuit. It could have, but unfortunately it draws to much power and would have emptied the batteries at night. I tried also to NOT power the logical circuit with it but even then, it draws to much power.

To give you some numbers : at 4.2V, the arduino and all the others circuit components use 20mA. While the L298N is connected (without powering the motor) the circuit uses ~100mA. With the L293D the circuit consumes ~55mA. I also tried to use transistors to "switch off/on" the H-Bridge but unless you know a lot about transistors, I would not recommend that (leak current when off, not enough current when on,...).


After some tests, I realized that a battery of 1100mAH is barely enough to get through the night. If you have a H-Bridge which does not leak current when off, it is enough. In my case, I had to connect two batteries in parallel to not have to worry about power shortage.

I would recommend buying a battery with a bigger capacity because batteries in parallel are not a good idea, if one is faulty, the other will go down with it.


I have originally used a P4056 Micro USB 5V 1A but it does not protect the battery against over-discharge. With Li batteries, over-discharge is a real issue, it will kill your battery over time. I used a TP4056 18650 charger allowing me to charge the battery while the battery powers the circuit.

Step-Up Power Booster

5V is not enough to power the motor. You need a power booster to convert from 5V to 12V. I used the MT3609 Module


I used a geared motor because, once not-powered, it will not move because of mechanical tension to door could apply (the door stay open when the motor is off).

Solar panel

Simple solar panel. 2.5W 5V / 500mAh is way more than enough to charge the batteries during the day.

Light detector

I have reckoned I could save a photosensor because I had a solar panel and should be able to know if it is day or night by measuring the tension emitted from the solar panel. It kind of worked. I am able to measure the tension with two resistors (see schematics). However, that was a mistake. To measure the luminosity, the best way should be to measure the current, not the voltage. The voltage, go from 0 to 5V with a bit of light. And the current is harder to measure. A photo-resistor being cheap, I would suggest using one instead of my circuit.


The door must be light if your motor is not very powerful (like mine). That's why I chose a plastic door which is empty inside. You should not worry about predators raising the door if you have a gutter at the bottom.


The reed switches allow the arduino to know when the door is opened and closed. I have placed a small magnet inside the door (at the top). The magnet closes the circuit when in front of the reed switch.

You may notice in the schematics that the reed switches are connected to a digital pin and the ground. It's normal, I use the pin mode INPUT_PULLUP to detect if the switch is closed.

Others kind of switches may be more adapted.


I used a junction box : 11.6 x 11.4 x 5.6 cm

I wanted this as small as possible. I think now, this was a mistake, I should have used a bigger box: less minimalist/pretty but more functional.


Damn! This is hard.


The project worked for about a week. I did this door for somebody else and something went wrong while I was not there. I can't diagnostic the problem from afar. We had to turn the door off and wait the next time I will be able to have a look. I am pretty sure it is not the battery. The motor would not stop and I do not know why. The loop line 80 in my code should exit and turn off the motor after 15s but it didn't.

I have learnt a lot with this project. I will try to learn a bit more theory on electronics before my next project. Any advice on a book ?

I am pretty sure this all project could be done without the arduino. Logical gates should do the trick and should be cheaper but I lack the knowledge at the moment.



Untitled fileC/C++
// pins
const int solarTensionPin = A2;
const int motorPin1 = 2;
const int motorPin2 = 3;
const int switchMotorPin = 4;
const int magneticSensorDoorClosedPin = 5;
const int magneticSensorDoorOpenPin = 6;

// constants
const int numSamples = 10;
const int triggeringEventCountLimit = 2;
const float solarVoltageThreshold = 2.0;
const int maxTimeMotorRotation = 15000; // 15s

// variables
bool doorOpen = false;
int triggeringEventCount = 0;
bool ligthUp = false;

void setup() {
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(switchMotorPin, OUTPUT);
  pinMode(magneticSensorDoorClosedPin, INPUT_PULLUP);
  pinMode(magneticSensorDoorOpenPin, INPUT_PULLUP);

void loop() {
    ligthUp = false;
    if (getSolarVoltage() > solarVoltageThreshold) {
      ligthUp = true;
    // a triggering event is night when the door is open or day when the door is open
    // This condition is XOR : ^
    if (doorOpen ^ ligthUp) {
    } else {
      triggeringEventCount = 0;

    // After three triggering event, you switch the door.
    if (triggeringEventCount > triggeringEventCountLimit) {
      triggeringEventCount = 0;
    delay(120000); //cycle every 2min

float getSolarVoltage()
    int sum = 0;
    float voltage = 0.0;
    for (int sampleCount = 0; sampleCount < numSamples; sampleCount++) {
      sum += analogRead(solarTensionPin);
    // We divide the sum by the number of samples to get the average value.
    // The average value measured is between 0 and 1024. 1024 represent 5V.
    // So we multiply the measured by 5 and divide the result by 1024.
    voltage = ((float)sum / (float)numSamples * 5.0) / 1024.0;
    // time 2 because voltage mesured = real voltage * R1/(R1+R2) = real voltage * 10/20 = real voltage / 2
    return voltage * 2;

void switchDoor()
  unsigned long start = millis();
  int sensor = doorOpen ? magneticSensorDoorClosedPin : magneticSensorDoorOpenPin;
  int pin1 = doorOpen ? motorPin1 : motorPin2;
  int pin2 = doorOpen ? motorPin2 : motorPin1;

  // activate motor
  digitalWrite(switchMotorPin, HIGH);
  digitalWrite(pin1, HIGH);
  digitalWrite(pin2, LOW);
  while(digitalRead(sensor) == HIGH && (unsigned long)(millis() - start) < maxTimeMotorRotation) {    
  //turn off motor
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(switchMotorPin, LOW);
  doorOpen = !doorOpen;


Untitled sketch schem bwa7dhpzgo


Similar projects you might like

Mobile Weather Station Being Powered by Solar Energy

Project tutorial by Kutluhan Aktar

  • 17 respects

Automated door for chicken house

by Quelud

  • 9 respects

Automatic Sliding Door for the Garage

Project tutorial by DVDMDN

  • 132 respects

Raspberry Pi - Powered Candy Dispenser

Project tutorial by Arduino “having11” Guy

  • 1 comment
  • 16 respects

Solar Powered LED Parking Sensor

Project tutorial by aams86

  • 14 respects

Automatic Hand Sanitizer

Project tutorial by Nikolaos Babetas

  • 37 respects
Add projectSign up / Login