Automated Chicken Coop Door

Owners of chickens often wail about having to get up to let their loved ones out to forage - and about having to abandon dinner to round their loved ones up and into the safety of their coop at the end of the day.

After finding a couple of drawer runners abandoned by the verge and partnering them up with a small electric motor in my junk-box, I decided to noodle out an electronic circuit that would open and shut a coop door at dawn and dusk.

Testing the limit-switches that stop the coop door motor when the door is fully open or fully closed

In the above video, the door lifts as light falls on the light-dependent resistor, Simulatiing dawn. The door lifts until a magnet mounted on it closes a reed switch near the top of the vertical rails. When my hand covers the LDR again - simulating nightfall - the circuit waits five seconds before lowering the door until the magnet closes a reed switch mounted near the bottom of the vertical rails. The 'closing' delay is to sound an alert to warn the hens that the door is about to close, though, outside of this test, it would usually be set for ten minutes or so.

The exercise turned out to be a revelation in electronic design principles.

Here's how.

The dawn-dusk piece is pretty easy - just use an adjustable light-level detector. That part of the circuitry could be a standard combination of light-dependent resistor and op-amp comparator. More challenging was the problem of having the motor change direction depending on whether it is dawn or dusk; whether the door needs opening or closing and sensing where the door is in its travel.

Click here to read more

Click here to see less

Click here to see less

I started thinking through how the circuit would assess where the door is and therefore in which direction to turn the motor. I figured I could use an H-bridge circuit to drive the door and discovered that discrete and integrated H-bridges use two (usually) complementary input states to determine in which direction to drive the motor. That is: a 1 + 0 drives the motor in one direction and a 0 + 1 drives the motor in the other direction.

The logic would need to prevent the motor running after the door reached the end of its travel - otherwise the motor would likely burn out. It seemed to me I'd need logic that would determine where the door is and to deliver the correct logic output pair until the door reached the correct location: fully open or fully closed.

The problems with that scenario are that there are any number of places the door can be between open and closed that are hard to sense cheaply and rather harder to design position-assessment logic around cheaply. Also, if we care about knowing which end-travel sensors are in which position all the time, then we are having to use three-input logic/truth tables, which are slightly newer to me than two-input logic/truth tables.

I batted that around for three days or so. One of the problems I considered was that building in logical fault sensing was much more complicated if we cared about the door's position. I spent some time considering if the H-bridge's 'enable/disable' pin could be hacked to help out with this.

The breakthrough came when I realised that it doesn't matter whether the system knows where the door is; what matters is where the door is *not* when the light level changes up (dawn) or down (dusk).

Click here to read more

Click here to see less

Click here to see less

In other words, if the light level has just changed up at dawn, what matters is that the door heads towards being open until fully open. Similarly, if the light level has just changed down at dusk, what matters is that the door heads towards being closed until fully closed.

That revelation reveals that I only needed to create logic around two conditions:

  1. If the light level is high and the door is not open, drive the door until it is sensed as being open.
  2. If the light level is low and the door is not closed, drive the door until it is sensed as being closed.

Two reed switches - one at the top of the door's travel and one at the bottom - would provide the position sensing if the door was fitted with magnets that would trip the reed switches. The reed switches' *logic* output could be pre-set by biasing each switch with resistors.

Click here to read more

Click here to see less

Click here to see less

Fault detection - if provided at all - could be reduced to detecting any condition where the door was out of either of fully open or fully closed position for more than the time known for the door to complete its travel from one extreme to the other, plus a couple of other 'switch failure' conditions.

With the revelation behind me, I started to look at the logic I'd need, focusing on the chips that are cheap or that I already had in my junk box. The comparator piece was easy: use a 741 or an LM393 along with three 1k resistors from the junkbox. I took an LDR from a discarded night-light.

After some scratching around I realised that the reed switch logic could be simplified if the logic conditions we look for were reduced to:

Light sensor = high + lower reed switch = high (1 + 1)

and

Light sensor = low + upper reed switch = low (0 + 0)

because the first (1 + 1) can be handled by an AND gate and the second (0 + 0) can be handled by an NOR gate. That is: if the reed switches and their voltage bias were judiciously arranged, the 1 + 1 AND condition could handle the 'door opening' condition and the 0 + 0 NOR condition could handle the 'door closing' condition.

Click here to read more

Click here to see less

Click here to see less

To conceptualise this another way, the door controller strives to get away from the pair of AND conditions that exist when the light sensor is high and one of the reed switches is set 'high', or when the light sensor is low and one of the reed switches is set 'low'. The reed switch high/low conditions are set not by whether or not the reed switches are open but by their role in a resistor-divider that sets up one each of the AND and NOR gate inputs.

This logic is shown in the truth tables below:

Door opens

Light Sensor Upper Switch Action Notes
11Door opensLight level went high; AND Gate triggers

Door closes

Light Sensor Lower Switch Action Notes
00Door closesLight level went low; NOR Gate triggers

Click here to see complete truth table

Click here to hid complete truth table

Click here to hid complete truth table

Complete Truth Table
Light Sensor Upper Switch Lower Switch Action Notes
000Door close startsDusk, close starts after 555-determined delay
001Door closingDoor has begun to close. Fault condition if prolonged
011Door closedThis condition should last through night
010Fault condition
111Door open startsDawn, open starts immediately
101Door openingDoor has begun to open. Fault condition if prolonged
100Door openThis condition should last through day
110Fault condition

Click here to read more

Click here to see less

Click here to see less

I began by setting up and Arduino and the Arduino MotorShield to drive the motor. But testing with the Arduino motor drive code example from LadyAda's MotorShield library revealed that the controller combination consumed 100-115mA even in quiescent mode. Too high for this application. I abandoned that approach and turned to CMOS logic.

A little more scratching around revealed that I could use three NOR gates to create an AND gate, which meant that I could use the four NOR gates in the CMOS 4001 in my junkbox to handle all the logic. Two-input logic gates being more common than three-input logic gates, particularly in my junk-box.

So far, the cost of this project was nil.

Click here to read more

Click here to see less

Click here to see less

After reading up on the L293D and L298 H-bridge chips, I breadboarded the light detector and logic circuitry to check it would provide the 0 + 1 and 1 + 0. It worked fine.

The next step was to figure out how to give the chickens some warning that the door was going to close each night. After all, you don't want your agricultural assets clustered around a closed coop door as the foxes close in.

What I needed was to delay the operation of the H-bridge - and possibly the operation of the CMOS logic gates - when the light level was detected as changing from high to low. During the delay, a piezo-buzzer should sound to warn the hens of the coop door's imminent closure.

Click here to read more

Click here to see less

Click here to see less

I needed a monostable multivibrator that could preserve the 'door OK to be open' logic condition based on light-level that holds during the day while also sounding a buzzer. Having messed around with Maplin's monostable kits before and knowing that their output level sits low until triggered, I realised I could switch into the door-closing logic one of these monostables so that feeding the monostable's output to the input to the NOR logic gate could keep the logic gate input at 0 + 1 rather than 0 + 0 until the monostable timed out to a low output level.

The difficulty with this trick is that we want to detect only low-going light level changes, not the high-going changes. That is, we only care to insert this delay at dusk, when the light level is falling, and not at dawn, when the light level is rising.

Fixing this proved easy: it's possible to configure a 555-based monostable like the Maplin kit to trigger only on low-going edges by sandwiching a capacitor between two pull-up resistors at the trigger pin (pin 2) of the 555. A couple of diodes inserted after the output stage of the light-level detector and the monostable isolated their respective outputs from each other so that only the 'high' output of either sub-circuit made its way to the inputs of the 4001's NOR gate.

Automatic Chicken Coop Door Controller circuit (First Draft - H bridge untested)

Breadboard tests proved the viability of the design.

Stripboard Testing

Click here to read more

Click here to see less

Click here to see less

Unit did not work when completed and tested.

Careful simulation of lighting and switching showed that the logic and electronics through to the ping 3 and 4 outputs of U3 CMOS 4001 worked correctly.

Testing around U4 L293D showed that its logic power supply on pin 16 Vcc1 and Enable pin 1 was at 2.10 volts instead of the 5.1V theoretically delivered by the combination of 5.1V zener D3 and 1k resistor R14.

Given that this logic power supply had been tested delivering 5.1V before U4 L293D was inserted, it seemed likely that the issue was that the 1k resistor R14 was dropping too many volts at the current required by the L293D's logic power supply Vcc2.

So, let's work out what we need:

Logic Supply Voltage VCC1: 2.14V not 5.1V as it should be

Output Supply Voltage VCC2 in use: 12.5V

Voltage drop is:

6.39V

over 1kR

Logic supply current ICC1 is = 0.0064 6.4mA

According to TI's L293D datasheet, ICC1 is min: 13mA and max (in this application): 35mA

Calculate new R14 resistance:

12.5 - 5.1 = 7.4

At max I<subL</sub> current 7.4 / 0.035 = 211R

At min I<subL</sub> current 7.4 / 0.013 = 569R

Use 200R or close

Calculate resistor wattage rating: 7.4 * 0.035 = 0.26W

'Use' Cases

Click to read more

Click to see less

Click to see less

These use cases show how the door's actual position correlates with the logic conditions in the truth tables above.

Case 1:

Night-time, door closed, 0 + 1 presented to the AND gate; 0 + 1 presented to the NOR gate

Light Sensor = 0
Upper Switch = 1

  |
  |
  |
  ||
  ||

Lower Switch = 1

Case 2:

Dawn breaks, light sensor output goes high, 1 + 1 presented to the AND gate; 1 + 1 presented to the NOR gate

Light Sensor = 1
Upper Switch = 1

  |
  |
  |
  ||
  ||

Lower Switch = 1

Case 3:

Day-time, light sensor output has gone high, AND gate high output has begun to pull door open, lower switch opens and goes low, 1 + 1 presented to the AND gate; 1 + 0 presented to the NOR gate

Light Sensor = 1
Upper Switch = 1

  |
  |
  ||
  ||
  |

Lower Switch = 0

Case 4: Day-time, light sensor output high, door fully open, upper switch closes and goes low, 1 + 0 presented to the AND gate; 1 + 0 presented to the NOR gate

Light Sensor = 1
Upper Switch = 0

  ||
  ||
  |
  |
  |

Lower Switch = 0

Case 5:

During daytime, light sensor output high, door fully open, 1 + 0 presented to the AND gate; 1 + 0 presented to the NOR gate

Light Sensor = 1
Upper Switch = 0

  ||
  ||
  |
  |
  |

Lower Switch = 0

Case 6:

Dusk, light sensor output goes low, door fully open, 0 + 0 presented to the AND gate; 0 + 0 presented to the NOR gate; NOR gate output goes high

Light Sensor = 0
Upper Switch = 0

  ||
  ||
  |
  |
  |

Lower Switch = 0

Case 7:

Dusk, light sensor output low, NOR gate beginning to close door, upper switch opens and goes high, 0 + 1 presented to the AND gate; 0 + 0 presented to the NOR gate; NOR gate output goes high and begins to close door

Light Sensor = 0
Upper Switch = 1

  |
  ||
  ||
  |
  |

Lower Switch = 0

Case 8:

Night-time, light sensor output low, NOR gate completes door-closing, lower switch closes at completion of door-closing and goes high, 0 + 1 presented to the AND gate; 0 + 1 presented to the NOR gate; NOR gate output goes low again as door closes. Same as case 1.

Light Sensor = 0
Upper Switch = 1

  |
  |
  |
  ||
  ||

Lower Switch = 1

Useful Links

Discussion

Enter your comment
WYYQM
 
automatic_chicken_coop_door.txt · Last modified: 2010/08/24 10:07 by lee
Translate: AR CN DE ES FR HI PT PT-br RU UR