Design and build a system to be installed in a chicken coop which will automate many of the tedious processes needing to be monitored by the owner of the chickens. This project was conceptualized after the event of a chicken dying from heat exposure on a hot summer day while the owner was away for a few days. There needed to be a way to control some of the elements within the chicken coop to prevent things like that happening again. I was approached with the project and asked to help develop the system to do this. There were various requirements for the system to have including:
Control of a solenoid valve to provide water for the chickens in the form of a water misting system.
Control of a temperature sensor to monitor the temperature inside the coop and determine the conditions for which the other devices would activate.
Control of a light sensor to determine if more light or heat lamps are needed within the coop.
Control of a heating element for the chickens water supply in the winter time to prevent the water from icing over or from getting too hot and harming the chickens or burning though the water container.
Include an option to be able to set the system for either summer conditions or winter conditions.
Design the system to be plug and play for the user.
/*****************************************************************
* Project Name: Chicken Life Support
* Author: Benton Murray
* Date: 11/23/2020
* Description: This project is designed to be a life support
* module for a chicken coop. Another way to think of
* it is as a climate control unit. It will measure
* temperature and light and turn on and off different
* connected devices depending on what is needed based
* on the data it receives.
******************************************************************/
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
// declare digital pin variables
int solRelay = 7;
int lampRelay = 6;
int heatRelay = 5;
int seasonBTN = 12;
int photoSensor = A5;
int buttonStateLED = 13;
// variables for program
float temp;
int lightVal;
int buttonState;
int timerA;
int timerB;
void setup()
{
pinMode(solRelay, OUTPUT);
pinMode(lampRelay, OUTPUT);
pinMode(heatRelay, OUTPUT);
pinMode(seasonBTN, OUTPUT);
pinMode(buttonStateLED, OUTPUT);
// Initialize the timer variables
timerA = 0;
timerB = 0;
Serial.begin(9600);
sensors.begin();
}
void loop()
{
/*****************************************************************
* Begin reading the temperature sensor and map to temp variable
* Begin reading the light sensor and map to lightVal variable
*****************************************************************/
sensors.requestTemperatures();
temp = sensors.getTempFByIndex(0);
lightVal = analogRead(photoSensor);
/*************************************
* Enter into light level relay logic
*************************************/
if (lightVal < 400)
{
digitalWrite(lampRelay, HIGH);
}
else
{
digitalWrite(lampRelay, LOW);
}
/****************************************************************************
* Check button for seasonal setting. Enter into logic conditions for either
* the solenoid relay or the water heater relay.
****************************************************************************/
digitalWrite(seasonBTN, HIGH); // Setup driving voltage for seasonal button from I/O
buttonState = digitalRead(seasonBTN); // Determine state of button for seasonal setting
/***********************************
* Enter into solenoid relay logic
***********************************/
if (buttonState == HIGH) // Apply button statement in logic for relay activation
{
timerB = 0; // Reset timer to 0 if seasonBTN is changed
digitalWrite(heatRelay, LOW); // Make sure heat relay is turned off
digitalWrite(buttonStateLED, LOW); // Button indicator on board LED for testing
if (temp > 80 & (timerA > 0 & timerA < 1270)) // Activate solenoid if temperature gets too high
{
digitalWrite(solRelay, HIGH);
timerA += 1; // Run for 15 minutes
}
else if (timerA > 1270)
{
digitalWrite(solRelay, LOW);
timerA = -2540; // Set timer for a 30 minute count
}
else
{
digitalWrite(solRelay, LOW);
timerA += 1; // Increase timer to zero so loop can re-engage
}
}
/***************************************
* Enter into water heater relay logic
***************************************/
else if (buttonState == LOW)
{
timerA = 0; // Reset timer to 0 if seasonBTN is changed
digitalWrite(solRelay, LOW); // Make sure solenoid relay is turned off
digitalWrite(buttonStateLED, HIGH); // Button indicator on board LED for testing
if (temp < 38 & (timerB > 0 & timerB < 1270)) // Activate heater if water temp gets too low
{
digitalWrite(heatRelay, HIGH);
timerB += 1; // Run for 15 minutes
}
else if (timerB > 1270)
{
digitalWrite(heatRelay, LOW);
timerB = -2540; // Set timer for 30 minute count
}
else
{
digitalWrite(heatRelay, LOW);
timerB += 1; // Increase timer to zero so loop can re-engage
}
}
}
Inside the unit showing the arduino uno which was used for control and the relays for the various controlled elements.
Completed System.
Output connectors for the controlled elements. Power switch and seasonal selection switch.
Light detection for the heat lamps and general lights.
Main power input and power indication.
Labeled output connectors for the controlled elements.