Coop automation

SGL70

Chirping
Aug 30, 2017
29
30
69
Lulea, Sweden
Next year i am planning to get a couple of hens and for that reason I have been looking for a suitable coop design. Forum member @vehve made a great looking coop & run (Scandin-Avian Coop) that seems to fit my needs.

So with the genereal design decided, I turned my eye toward an automatic door opener...but one thing led to another, so now I am testing more features.

I thought it could be mildly interesting to read my endeavours, but the main reason is to have an amount of external pressure to see this thing thorugh...

Oh, Electrical engineer/programmer isn't my dayjob...beware :)

Planned features:
Auto door open/close
Humidity controlled fan
Temperature controlled heating lamp
Wifi comms
Chicken Cam (Old Android phone acting IP Camera server)
Android App (via Blynk)

Current state of affairs (both layout and code needs work, but in its current state I hope the gist of things will come across):

Layout:
HEN9000_02_bb.png
some comments:
I am aiming at using the Nano with wifi capability (I use a Leonardo with an Ethernet shield atm). I just ordered a NodeMCU, so the Nano might have to go...
It will be powered by a DIY'd 350W PC ATX power supply, but I would like to go nuclear (i.e. solar power).
For the door, I will be using an old cordless drill motor (18VDC) running on 12 VDC. The speed and direction will be managed with PWM and a H-bridge.
SensorUP/Down is Reed switches that will stop the DC motor when reaching an end point.

App:
Screenshot_20170821-193044.png

Code:
Code:
/*

*/
#include <Blynk.h>
#include <DHT.h>;
#include <BlynkSimpleEthernet.h>;

#define BLYNK_PRINT Serial
#define DHTPIN 2  // DHT22
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

//  Blynk app auth Token
char auth[] = "XXXXXXXX";

BlynkTimer timer;

int motorState;
int fanState;
int lampState;
bool mMov = false;
bool sensorUp = false;
bool sensorDown = false;
int doorInfo;
int lampInfo;
int fanInfo;

float hum;
float temp;

int reedPinUp = 4;
int reedPinDown = 3;
int ldrPin = 5;
int mPlusPin = 10;  // pwm
int mMinusPin = 11; // pwm
int fPlusPin = 5;
int lPlusPin = 13;

void myTimerEvent(){
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V4,doorInfo);
  Blynk.virtualWrite(V3,lampInfo);
  Blynk.virtualWrite(V5,hum);
  Blynk.virtualWrite(V6,temp);
  Blynk.virtualWrite(V7,fanInfo);
}

void checkLight(){
  //  Check ambient light (0 - 1023) and adjust Motor and Lampflags.
  int light = analogRead(ldrPin);
 
  if (light >300){
    //  Night. Close door.
    motorState = -1;
  }
  else if (light <=300 || light >100){
    //  Dusk/Evening. Turn the lights on in the coop
    lampState = 1;
  }
  else {
    // Morning/Day. Lights off
    lampState = 0;
    // Open door.
    motorState = 1;
  }
}
void checkTempRH(){
  //  Check temp and humidity. Send info to db/app. Start fan if high humidity.
  hum = dht.readHumidity();
  temp = dht.readTemperature();
 
  if (hum>0.7){
    fanState = 1;
  }
  // Send to db/app
 
}
void activateMotor(){
  //  Activate motor: Up, Down or Stop.
  switch (motorState){
    case 0:
    //    STOP
    //  New layout - L298N H bridge - New code (direction and Speed (PWM)) to be done
    mMov = false;
    break;
    case 1:
    //    UP
    //  New layout - L298N H bridge - New code (direction and Speed (PWM)) to be done
    doorInfo = 255;
    mMov = true;
    // Send to db/app
    case -1:
    //    DOWN
    //  New layout - L298N H bridge - New code (direction and Speed (PWM)) to be done
    mMov = true;
    doorInfo = 0;
    // Send to db/app
  }
}
void activateFan(){
  //  Activate Fan or turn it off. Send status to db/app
  switch (fanState){
    case 0:
    //  OFF
    digitalWrite(fPlusPin, LOW);
    fanInfo = 0;
    break;
    case 1:
    //  ON
    digitalWrite(fPlusPin, HIGH);
    fanInfo = 255;
    break;
  }
  // Send to db/app
}
void activateLamp(){
  //  Lights On or Off. Send status to db/app
  switch (lampState){
    case 0:
    digitalWrite(lPlusPin, LOW);
    lampInfo = 0;
    break;
    case 1:
    digitalWrite(lPlusPin, HIGH);
    lampInfo = 255;
    break;
  }
  // Send to db/app
}
//    Setup
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  //  Init DHT
  dht.begin();
  // Init app
    Blynk.begin(auth);

  timer.setInterval(1000L, myTimerEvent);
  //  Set pinmode
  pinMode(mPlusPin, OUTPUT);
  pinMode(mMinusPin, OUTPUT);
  pinMode(reedPinUp, INPUT);
  pinMode(reedPinDown, INPUT);
  pinMode(fPlusPin, OUTPUT);
  pinMode(lPlusPin, OUTPUT);
  // Set flags
  motorState = 0;
  fanState = 0;
  lampState = 0;
  mMov = false;
}
// the loop routine runs over and over again forever:
void loop() {
  Blynk.run();
  timer.run();
  //    Read sensors
  checkLight();
  checkTempRH();
 
  //     If door har reach endpoint - Stop Motor.
  if (mMov && (digitalRead(reedPinUp) || digitalRead(reedPinDown))){
    motorState = 0; //STOP
  }
 
  //    Run Lamp, Fan and Motor depending on state.
  activateLamp();
  activateMotor();
  activateFan();
}

Feel free to comment or suggest!!


Greger
 
Last edited:
Looks like a fun project. Though, unless you're really cold where you are, the heat lamp shouldn't be needed. I would rather do large automated vents up high that open when the humidity gets too high and then shut again, with smaller permanent vents up high that never close. Also, south facing windows that sense indoor temp and outdoor temp and will open the shutters when it is warmer outside than inside, then close again when the temps even out. Can also do a heat sink inside that would collect heat when those south facing windows open up and slowly trickle the heat back out once the windows close.

I have a few certificates in alternative energy which in addition to doing things with alternative energy, also teaches neat ways to conserve the little bit of energy you are producing.
 
Winters are becoming a bit weird, but -25C (-13F) is pretty normal in my neck of the wood (Northern Sweden), so the heat lamp might be handy. But we'll see about that.

The automated vents will, in my setting, consist of humidity controlled fan or fans with a gadget preventing cold air getting in (I haven't the faintest what the english word for it is - in general it operates the same way that old tractors had a lid on the exhaust pipe).

A heat sink? As in a brick wall, for instance?

Greger
 
This is one hell of a project haha Good luck! Not a fan of automation but sure sounds epic! Although with the automatic door I'm sure you will time it to close when it's complete dark because some times chickens take longer or have harder times getting back when it's too dark out
 
I don't know if my plans will work, as I know too little about chickens (fixin' to change that, though)

The door will be controlled by a light sensor - during winter it will hardly ever open and in the summer it will never shut. I was thinking to turn the lights on in the coop, some time before shutting the door...assuming that the chickens prefer the light indoors over the dark outside. However, I don't know if the birds see it the same way :)

Greger
 
I'd still have the light turn off when they're going to sleep, but not if they ain't all in the coop to roost. Sound like it Would be a good way for them to find way back as the sun goes down although!
 
Winters are becoming a bit weird, but -25C (-13F) is pretty normal in my neck of the wood (Northern Sweden), so the heat lamp might be handy. But we'll see about that.

The automated vents will, in my setting, consist of humidity controlled fan or fans with a gadget preventing cold air getting in (I haven't the faintest what the english word for it is - in general it operates the same way that old tractors had a lid on the exhaust pipe).

A heat sink? As in a brick wall, for instance?

Greger

Exactly, a brick wall, or a black barrel of water, something that will hold the heat and then release it later.

During winter it is pitch black here for 22 out of 24 hours....I will need to give light a bit more consideration. Hmm...

How important is good laying to you? They will not lay in those light conditions. Are you planning on free ranging or doing an enclosed run? If in a run, I would put flood lights in the run, and also lights in the building, have them set for a 12+ hour lighted period with the lights coming on outside and then the ones inside to simulate the sun rising, then have the outside ones go out but inside ones stay on to draw the birds inside - they will head for the light. In your situation, having the door on a timer might be better than light sensitive.
 
Yeah definitely a fun project. I once put a PLC on an aquaponics project. Turned out to be totally unnecessary after I refined the process, but it satisfied a geeky urge in me. I love automation.
 
Yeah definitely a fun project. I once put a PLC on an aquaponics project. Turned out to be totally unnecessary after I refined the process, but it satisfied a geeky urge in me. I love automation.

Hahaha...it tickles my inner geek, too!...and it might turn out to be crap. But it will keep me entertained this winter!


How important is good laying to you? They will not lay in those light conditions. Are you planning on free ranging or doing an enclosed run? If in a run, I would put flood lights in the run, and also lights in the building, have them set for a 12+ hour lighted period with the lights coming on outside and then the ones inside to simulate the sun rising, then have the outside ones go out but inside ones stay on to draw the birds inside - they will head for the light. In your situation, having the door on a timer might be better than light sensitive.

I'll have a run. I distrust the plethora of dogs and cats that my nieghbours have...
I think I am fine with laying being a sesonal event at this point. But come summer, they will have a fit...the summer never sets for a period. :)

Greger
 

New posts New threads Active threads

Back
Top Bottom