Chicken Gate
This instructable shows a not so common way of making a opening/closening mechanism for a chicken house. It was a request from my dad who didnt like the available alternatives requiring limit switches and using wire for pulling up the "gate" of the chicken house. The limit switches gets damaged and the wire breaks or gets messed up (a rare event though).
So, the focus here is a robust solution without the need for limit switches. Since I had a uStepper controller at hand I decided to use a stepper motor driven approach with a linear actuator (See Instructable here !) and a cheap week timer my dad had lying around anyway...
The result is as seen here - and works perfect !
Supplies
- uStepper S
- uStepper Prototype Shield
- uStepper Linear Actuator See Instructable here !
- Week timer or RTC module instead
- Some water-tight boxing
- 12V 2A power supply
- "Fittings" for fastening it to the house and "gate"
Assembly
Most of the assembly relates to the Linear Actuator which I linked to previously. So, the remaining part is just fitting the actuator to the box and wiring stuff up !
Pictures says more than a thousand words - so I'll let them tell the story here ;)
Coding
Disclaimer: The coding is not pretty and can easily be improved now that I look at it again... But it works ! ;)
There's not so much to it, I've used the debounce example from Arduino to debounce on the signal from the week-timer and then made a state-machine where I drive the gate until the uStepper detects a resistance of some given magnitude - indicating the limit of the travel:
#include <uStepperS.h> #define SPEED 300 uStepperS stepper; const int inputPin = 2; uint8_t state = 0; int inputState; // the current reading from the input pin int lastInputState = LOW; // the previous reading from the input pin unsigned long lastDebounceTime = 0; // the last time the output pin was toggled unsigned long debounceDelay = 1000; // the debounce time; increase if the output flickers void setup() { // Configure uStepper stepper.setup(); pinMode(inputPin, INPUT); stepper.setBrakeMode(COOLBRAKE); } void loop() { // read the state of the switch into a local variable: int reading = digitalRead(inputPin); if (reading != lastInputState) { // reset the debouncing timer lastDebounceTime = millis(); } if ((millis() - lastDebounceTime) > debounceDelay) { // whatever the reading is at, it's been there for longer than the debounce // delay, so take it as the actual current state: // if the button state has changed: if (reading != inputState) { inputState = reading; } } lastInputState = reading; if(state == 0) // { if(inputState == HIGH) { state = 1; } } else if(state == 1) // { //Go back to home stepper.setRPM(-SPEED); delay(100); stepper.enableStallguard(3, true, SPEED); // Wait for stall to be detected. while( !stepper.isStalled() ){} // Clear stallguard stepper.clearStall(); stepper.disableStallguard(); stepper.stop(); state = 2; } else if(state == 2) // { if(inputState == LOW) { state = 3; } } else if(state == 3) // { stepper.setRPM(SPEED); delay(100); stepper.enableStallguard(1, true, SPEED); // Wait for stall to be detected. while( !stepper.isStalled() ){} // Clear stallguard stepper.clearStall(); stepper.disableStallguard(); stepper.stop(); state = 0; } }