I love fresh yard eggs, but I'm lazy.
to solve the first problem I'm converting an old 6X6 shed into a coop for 4-5 chickens.
to solve the second problem I'm going to automate all the tedious things, like calling them in at night and feeding.
my goal is to go out about once a week to collect eggs, add feed and clean poo.
I know very little about code, but a bit about electronics.
I'm looking for someone to proof my code and tell me if I'm heading in the correct direction.
keep in mind this is not finished.
I originally plan on using a DS18B20 to sense temp and turn on a fan or heater accordingly. but due to the complex nature of this device I decided to go with a very simple thermal resistor connected to the analog in.
on a final note, all # are just to start, I will re-calibrate as as soon as I get everything hardwired and settled
/*
The circuit:
* 20k Ohm resistor from +5V to pin 1, and a photo resistor from analog pin 1 to Gnd
* 140k Ohm resistor from +12V to pin 2, and temperature resistor from analog pin 2 to Gnd
* a 5VDC buzzer connected from "high" to pin 5, and 5VDC on pin + and gnd on pin -
* a 5VDC actuator connected through a relay from pin 6 to gnd
* a 120 VAC 12" fan connected thorugh a 5VDC relay from pin 7 to gnd
* a 120 VAC 100W heat lamp connected thorugh a relay from pin 8 to gnd
* a 120 VAC light bulb connected through a relay from pin 9 to gnd
* a normally open push button connected from +5VDC to pin 10
* a normally open push button connected from +5VDC to pin 11
* a 5VDC actuator connected through a relay (cw in ON state and ccw in off state with limit swithces in place to ensure secure open/close) from pin 6 to gnd
* note to self 1-5 are analog, move accordingly
* also PWM pins are 3, 5, 6, 9, 10, and 11
created Feb 2010
by Jake Dixon
jakedixon@hotmail.com
*/
// set pin numbers:
int PhotoPin = 1; // photo pin
int TempPin = 2; //temp sensor
int BuzzPin = 5; //OMG food!
int FeedPin = 6; //dispenses feed
int FanPin = 7; // exhaust fan
int HeatPin = 8; // heat lamp
int LightPin = 9; //night light
int Closepin = 10; // Door close button
int Openpin = 11; // Door open button
int DoorPin = 12; // Door actuator relay
// variables will change:
int OpenState = 0; // variable for reading the pushbutton status
int CloseState = 0; // variable for reading the pushbutton status
int Bright = 0; // variable for photo pin
int temp = 0; // variable for temp cold
int flip = HIGH; // variable for me to get confused with flop
int flop= LOW; // variable for me to get confused with flip
void setup() {
pinMode(BuzzPin, OUTPUT);
pinMode(FeedPin, OUTPUT);
pinMode(FanPin, OUTPUT);
pinMode(HeatPin, OUTPUT);
pinMode(LightPin, OUTPUT);
pinMode(DoorPin, OUTPUT);
}
void loop()
{
// ******** Define int ********
OpenState = digitalRead(Openpin);
CloseState = digitalRead(Closepin);
Bright = analogRead(PhotoPin) / 4;
temp = analogRead(TempPin);
// ****** manual operation ******
if (OpenState == HIGH) // if open button is pushed
{
digitalWrite(DoorPin, HIGH); // open the door
}
if (CloseState == HIGH) // if close button is pushed
{
digitalWrite(DoorPin, LOW); // close the door
}
// ********Morinig Routine********
if ((flip == HIGH) and (Bright > 100)) //if it's light out and morning is enabled
{
digitalWrite(DoorPin, HIGH); // open the door
digitalWrite(flip, LOW); // enable night mode
}
// ********Evening Routine********
if ((flip == LOW) and (Bright < 80)) // if it's dark out and night is enabled
{
digitalWrite(LightPin, HIGH); // turn on the light
delay (5000); // wait 5 seconds
digitalWrite(BuzzPin, HIGH); // turn on the dinner bell
delay (5000); // wait 5 seconds
digitalWrite(FeedPin, HIGH); // food dispenser on
delay (800); // let it run for .8 seconds, no fat chickens here
digitalWrite(FeedPin, LOW); // food dispenser off
delay (14200); // delay 14.2 seconds more
digitalWrite(BuzzPin, LOW); // total dinner bell time 20 seconds
delay (300000); // wait 5 min for all the chickens to get home
digitalWrite (DoorPin, LOW); //close the door
delay (300000); // lets everyone get settled
digitalWrite(LightPin, LOW); // sleep tight
digitalWrite(flip, HIGH);
}
//temp reg
if ((temp < 80) and (flop== LOW);
{ digitalWrite(FanPin, HIGH);
digitalWrite (flop, HIGH)
}
if (temp < 90);
{ digitalWrite (FanPin, HIGH) ;
digitalWrite (flop, LOW)
}
}