SGL70
Chirping
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:
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:
Code:
Feel free to comment or suggest!!
Greger
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:

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:

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: