{"id":6560,"date":"2014-01-07T20:00:44","date_gmt":"2014-01-08T04:00:44","guid":{"rendered":"http:\/\/davenaves.com\/blog\/?p=6560"},"modified":"2025-07-18T11:19:12","modified_gmt":"2025-07-18T18:19:12","slug":"arduino-chicken-coop-controller","status":"publish","type":"post","link":"https:\/\/davenaves.com\/blog\/interests-projects\/chickens\/arduino-chicken-coop-controller\/","title":{"rendered":"Arduino Chicken Coop Controller"},"content":{"rendered":"<div class=\"fusion-fullwidth fullwidth-box fusion-builder-row-1 fusion-flex-container nonhundred-percent-fullwidth non-hundred-percent-height-scrolling\" style=\"--awb-border-radius-top-left:0px;--awb-border-radius-top-right:0px;--awb-border-radius-bottom-right:0px;--awb-border-radius-bottom-left:0px;--awb-flex-wrap:wrap;\" ><div class=\"fusion-builder-row fusion-row fusion-flex-align-items-flex-start fusion-flex-content-wrap\" style=\"max-width:1144px;margin-left: calc(-4% \/ 2 );margin-right: calc(-4% \/ 2 );\"><div class=\"fusion-layout-column fusion_builder_column fusion-builder-column-0 fusion_builder_column_1_1 1_1 fusion-flex-column\" style=\"--awb-bg-size:cover;--awb-width-large:100%;--awb-margin-top-large:0px;--awb-spacing-right-large:1.92%;--awb-margin-bottom-large:0px;--awb-spacing-left-large:1.92%;--awb-width-medium:100%;--awb-spacing-right-medium:1.92%;--awb-spacing-left-medium:1.92%;--awb-width-small:100%;--awb-spacing-right-small:1.92%;--awb-spacing-left-small:1.92%;\"><div class=\"fusion-column-wrapper fusion-flex-justify-content-flex-start fusion-content-layout-column\"><div class=\"fusion-text fusion-text-1\"><h3>Chicken Coop Arduino Controller<\/h3>\n<p>When I started my chicken coop, I knew I wanted it to be technically advanced, but I didn&#8217;t really want it to *look* too high tech, and not too &#8220;country&#8221; either. So I just went for it and I&#8217;m pretty happy with the results. Being the chicken nerd I am, I loved every phase of combining technology with building a chicken coop and raising chickens. (I actually don&#8217;t think I&#8217;ll ever want to stop adding to it b\/c it&#8217;s just too fun) I mean, why shouldn&#8217;t technology keep them safer, more comfortable, and healthier? Ok, and why shouldn&#8217;t *I* have more fun with it? =)<\/p>\n<p>What was the most important part for me (like most of us chicken owners) is keeping the chickens safe, especially at night. So for the automation part, it was all about the <strong><a title=\"Arduino Automatic Chicken Coop Door\" href=\"https:\/\/davenaves.com\/blog\/interests-projects\/chickens\/chicken-coop\/arduino-automatic-chicken-coop-door\/\">door<\/a><\/strong>. Predators are strong, sneaky and relentless critters, so you have to really get this door part right. After a while, you realize that one of the biggest pains is opening and closing the door every morning and evening. We chicken owners can&#8217;t go out to dinner without worrying whether or not a raccoon or a fox has been eyeballing them all day, waiting for the sun to go down to get into the coop to have *their* dinner. I also installed a <strong><a title=\"Live Chicken Cam\" href=\"https:\/\/davenaves.com\/blog\/live-chicken-cam\/\">chicken cam<\/a><\/strong> for a little added comfort.<\/p>\n<p><div id=\"attachment_6566\" style=\"width: 660px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" aria-describedby=\"caption-attachment-6566\" class=\"lazyload size-full wp-image-6566\" src=\"https:\/\/davenaves.com\/blog\/wp-content\/uploads\/arduino-chicken-coop-contoller-labelled.jpg\" data-orig-src=\"https:\/\/davenaves.com\/blog\/wp-content\/uploads\/arduino-chicken-coop-contoller-labelled.jpg\" alt=\"Arduino Chicken Coop Controller (labelled)\" width=\"650\" srcset=\"data:image\/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" data-srcset=\"https:\/\/davenaves.com\/blog\/wp-content\/uploads\/arduino-chicken-coop-contoller-labelled-290x300.jpg 290w, https:\/\/davenaves.com\/blog\/wp-content\/uploads\/arduino-chicken-coop-contoller-labelled-500x516.jpg 500w, https:\/\/davenaves.com\/blog\/wp-content\/uploads\/arduino-chicken-coop-contoller-labelled-700x722.jpg 700w, https:\/\/davenaves.com\/blog\/wp-content\/uploads\/arduino-chicken-coop-contoller-labelled-992x1024.jpg 992w, https:\/\/davenaves.com\/blog\/wp-content\/uploads\/arduino-chicken-coop-contoller-labelled.jpg 1200w\" data-sizes=\"auto\" data-orig-sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><p id=\"caption-attachment-6566\" class=\"wp-caption-text\">Arduino Chicken Coop Controller (labelled)<\/p><\/div>\n\n\t\t<style type=\"text\/css\">\n\t\t\t#gallery-1 {\n\t\t\t\tmargin: auto;\n\t\t\t}\n\t\t\t#gallery-1 .gallery-item {\n\t\t\t\tfloat: left;\n\t\t\t\tmargin-top: 10px;\n\t\t\t\ttext-align: center;\n\t\t\t\twidth: 33%;\n\t\t\t}\n\t\t\t#gallery-1 img {\n\t\t\t\tborder: 2px solid #cfcfcf;\n\t\t\t}\n\t\t\t#gallery-1 .gallery-caption {\n\t\t\t\tmargin-left: 0;\n\t\t\t}\n\t\t\t\/* see gallery_shortcode() in wp-includes\/media.php *\/\n\t\t<\/style>\n\t\t<div id='gallery-1' class='gallery galleryid-6560 gallery-columns-3 gallery-size-thumbnail'><dl class='gallery-item'>\n\t\t\t<dt class='gallery-icon portrait'>\n\t\t\t\t<a data-rel=\"iLightbox[postimages]\" data-title=\"Arduino Chicken Coop Controller with Door\" data-caption=\"Arduino Chicken Coop Controller with Door\" href='https:\/\/davenaves.com\/blog\/interests-projects\/chickens\/arduino-chicken-coop-controller\/attachment\/arduino-chicken-coop-controller-door\/'><img decoding=\"async\" width=\"150\" height=\"150\" src=\"https:\/\/davenaves.com\/blog\/wp-content\/uploads\/arduino-chicken-coop-controller-door-150x150.jpg\" class=\"attachment-thumbnail size-thumbnail lazyload\" alt=\"Arduino Chicken Coop Controller with Door\" aria-describedby=\"gallery-1-6563\" srcset=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20width%3D%271000%27%20height%3D%271172%27%20viewBox%3D%270%200%201000%201172%27%3E%3Crect%20width%3D%271000%27%20height%3D%271172%27%20fill-opacity%3D%220%22%2F%3E%3C%2Fsvg%3E\" data-orig-src=\"https:\/\/davenaves.com\/blog\/wp-content\/uploads\/arduino-chicken-coop-controller-door-150x150.jpg\" data-srcset=\"https:\/\/davenaves.com\/blog\/wp-content\/uploads\/arduino-chicken-coop-controller-door-64x64.jpg 64w, https:\/\/davenaves.com\/blog\/wp-content\/uploads\/arduino-chicken-coop-controller-door-100x100.jpg 100w, https:\/\/davenaves.com\/blog\/wp-content\/uploads\/arduino-chicken-coop-controller-door-150x150.jpg 150w\" data-sizes=\"auto\" \/><\/a>\n\t\t\t<\/dt>\n\t\t\t\t<dd class='wp-caption-text gallery-caption' id='gallery-1-6563'>\n\t\t\t\tArduino Chicken Coop Controller with Door\n\t\t\t\t<\/dd><\/dl><dl class='gallery-item'>\n\t\t\t<dt class='gallery-icon portrait'>\n\t\t\t\t<a data-rel=\"iLightbox[postimages]\" data-title=\"Arduino Chicken Coop Controller\" data-caption=\"Arduino Chicken Coop Controller\" href='https:\/\/davenaves.com\/blog\/interests-projects\/chickens\/arduino-chicken-coop-controller\/attachment\/arduino-chicken-coop-controller\/'><img decoding=\"async\" width=\"150\" height=\"150\" src=\"https:\/\/davenaves.com\/blog\/wp-content\/uploads\/arduino-chicken-coop-controller-150x150.jpg\" class=\"attachment-thumbnail size-thumbnail lazyload\" alt=\"Arduino Chicken Coop Controller\" aria-describedby=\"gallery-1-6562\" srcset=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20width%3D%271000%27%20height%3D%271238%27%20viewBox%3D%270%200%201000%201238%27%3E%3Crect%20width%3D%271000%27%20height%3D%271238%27%20fill-opacity%3D%220%22%2F%3E%3C%2Fsvg%3E\" data-orig-src=\"https:\/\/davenaves.com\/blog\/wp-content\/uploads\/arduino-chicken-coop-controller-150x150.jpg\" data-srcset=\"https:\/\/davenaves.com\/blog\/wp-content\/uploads\/arduino-chicken-coop-controller-64x64.jpg 64w, https:\/\/davenaves.com\/blog\/wp-content\/uploads\/arduino-chicken-coop-controller-100x100.jpg 100w, https:\/\/davenaves.com\/blog\/wp-content\/uploads\/arduino-chicken-coop-controller-150x150.jpg 150w\" data-sizes=\"auto\" \/><\/a>\n\t\t\t<\/dt>\n\t\t\t\t<dd class='wp-caption-text gallery-caption' id='gallery-1-6562'>\n\t\t\t\tArduino Chicken Coop Controller\n\t\t\t\t<\/dd><\/dl><dl class='gallery-item'>\n\t\t\t<dt class='gallery-icon portrait'>\n\t\t\t\t<a data-rel=\"iLightbox[postimages]\" data-title=\"Arduino Chicken Coop Controller (labelled)\" data-caption=\"Arduino Chicken Coop Controller (labelled)\" href='https:\/\/davenaves.com\/blog\/interests-projects\/chickens\/arduino-chicken-coop-controller\/attachment\/arduino-chicken-coop-contoller-labelled\/'><img decoding=\"async\" width=\"150\" height=\"150\" src=\"https:\/\/davenaves.com\/blog\/wp-content\/uploads\/arduino-chicken-coop-contoller-labelled-150x150.jpg\" class=\"attachment-thumbnail size-thumbnail lazyload\" alt=\"Arduino Chicken Coop Controller (labelled)\" aria-describedby=\"gallery-1-6566\" srcset=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20width%3D%271200%27%20height%3D%271238%27%20viewBox%3D%270%200%201200%201238%27%3E%3Crect%20width%3D%271200%27%20height%3D%271238%27%20fill-opacity%3D%220%22%2F%3E%3C%2Fsvg%3E\" data-orig-src=\"https:\/\/davenaves.com\/blog\/wp-content\/uploads\/arduino-chicken-coop-contoller-labelled-150x150.jpg\" data-srcset=\"https:\/\/davenaves.com\/blog\/wp-content\/uploads\/arduino-chicken-coop-contoller-labelled-64x64.jpg 64w, https:\/\/davenaves.com\/blog\/wp-content\/uploads\/arduino-chicken-coop-contoller-labelled-100x100.jpg 100w, https:\/\/davenaves.com\/blog\/wp-content\/uploads\/arduino-chicken-coop-contoller-labelled-150x150.jpg 150w\" data-sizes=\"auto\" \/><\/a>\n\t\t\t<\/dt>\n\t\t\t\t<dd class='wp-caption-text gallery-caption' id='gallery-1-6566'>\n\t\t\t\tArduino Chicken Coop Controller (labelled)\n\t\t\t\t<\/dd><\/dl><br style=\"clear: both\" \/>\n\t\t<\/div>\n<\/p>\n<h3>The Build<\/h3>\n<p>coming soon&#8230;<\/p>\n<h3>Parts List<\/h3>\n<p>(my affiliate links)<\/p>\n<p><a href=\"https:\/\/www.amazon.com\/Arduino-MEGA-2560-Board-R3\/dp\/B006UTBDGA\/ref=as_li_tf_mfw?&amp;linkCode=wey&amp;tag=arduino-automated-chicken-coop-door-20\">Arduino MEGA 2560 Board R3<\/a> &#8211; by Arduino<br \/>\n(The Arduino Micro Controller to control the entire coop, including the door)<\/p>\n<p><a href=\"https:\/\/www.amazon.com\/NEOMART-Original-Quality-Stepper-Controller\/dp\/B00E58EA90\/ref=as_li_tf_mfw?&amp;linkCode=wey&amp;tag=arduino-automated-chicken-coop-door-20\">NEOMART L298N Stepper Motor Driver Controller Board Module<\/a> &#8211; by Tontec<br \/>\n(The board that controls the motor)<\/p>\n<p><a href=\"https:\/\/www.amazon.com\/DFGB37RG-136i-Cylinder-Shape-Speed-Geared\/dp\/B00HG8DFC4\/ref=as_li_tf_mfw?&amp;linkCode=wey&amp;tag=arduino-automated-chicken-coop-door-20\">DFGB37RG-136i Cylinder Shape DC 24V Speed 20 RPM Geared Motor<\/a> &#8211; by Amico<br \/>\nThe motor it self (make sure to pick a motor that isn&#8217;t too fast.I chose the 20rpm model)<\/p>\n<p><a href=\"https:\/\/www.amazon.com\/White-Inbuilt-Contacts-Window-Switch\/dp\/B005CFQ1L0\/ref=as_li_tf_mfw?&amp;linkCode=wey&amp;tag=arduino-automated-chicken-coop-door-20\">White Inbuilt Type Alarm Contacts Door Window Reed Switch<\/a> &#8211; by Amico<br \/>\n(The Reed Switches (magnetic) which signals when to start\/top the motor)<\/p>\n<p><a href=\"https:\/\/www.amazon.com\/Sensitive-Resistor-Photoresistor-Optoresistor-GM5539\/dp\/B00AQVYWA2\/ref=as_li_tf_mfw?&amp;linkCode=wey&amp;tag=arduino-automated-chicken-coop-door-20\">20pcs Photo Light Sensitive Resistor Photoresistor Optoresistor 5mm GM5539 5539<\/a> &#8211; by sunkee-E<br \/>\n(The Photocell that continually reads light levels.In this project, it&#8217;s instructed to read ever 10mins)<\/p>\n<p><a href=\"https:\/\/www.amazon.com\/E-Projects-10k-Resistors-Watt-Pieces\/dp\/B00B5RJF1M\/ref=as_li_tf_mfw?&amp;linkCode=wey&amp;tag=arduino-automated-chicken-coop-door-20\">10k Ohm Resistors &#8211; 1\/4 Watt &#8211; 5% &#8211; 10K (25 Pieces)<\/a> &#8211; by E-Projects<br \/>\n(10k resistors for the photocell and the reed switches &#8211; refer to wiring diagram)<\/p>\n<p><a href=\"https:\/\/www.amazon.com\/BB830-Solderless-Plug-BreadBoard-tie-points\/dp\/B0040Z4QN8\/ref=as_li_tf_mfw?&amp;linkCode=wey&amp;tag=arduino-automated-chicken-coop-door-20\">BB830 Solderless Plug-in BreadBoard, 830 tie-points, 4 power rails<\/a> &#8211; by BusBoard Prototype Systems<br \/>\n(To connect all devices and wiring.Tip: apply hot glue to wired connections on breadboard once set)<\/p>\n<p><a href=\"https:\/\/www.amazon.com\/Polycom-SoundPoint-Universal-Power-Supply\/dp\/B002CT0822\/ref=as_li_tf_mfw?&amp;linkCode=wey&amp;tag=arduino-automated-chicken-coop-door-20\">Polycom SoundPoint IP Universal AC Power Supply 24V DC<\/a> &#8211; by Polycom Inc.<br \/>\n(power supply for 24v motor)<\/p>\n<p><a href=\"https:\/\/www.amazon.com\/Wall-Adapter-Power-Supply-650mA\/dp\/B003XZSZWO\/ref=as_li_tf_mfw?&amp;linkCode=wey&amp;tag=arduino-automated-chicken-coop-door-20\">Wall Adapter Power Supply &#8211; 9V DC 650mA<\/a> &#8211; by NKC Electronics<br \/>\n(power supply for arduino)<\/p>\n<p><a href=\"https:\/\/www.amazon.com\/Acrylic-Sheet-Transparent-Thickness-Length\/dp\/B0062R3RZA\/ref=as_li_tf_mfw?&amp;linkCode=wey&amp;tag=arduino-automated-chicken-coop-door-20\">Acrylic Sheet, Transparent Clear, 0.08&#8243; Thickness, 12&#8243; Width, 24&#8243; Length<\/a> &#8211; by Small Parts<br \/>\n(To cover door&#8217;s internal workings&#8230;prevents dust, shavings, feathers, etc.)<\/p>\n<p><script src=\"https:\/\/ws-na.amazon-adsystem.com\/widgets\/q?rt=tf_mfw&#038;ServiceVersion=20070822&#038;MarketPlace=US&#038;ID=V20070822%2FUS%2Fdaveworkswebd-20%2F8001%2F6a32ecd7-9e84-484b-a30f-ebfdd86553e9\" type=\"text\/javascript\" charset=\"utf-8\">\/\/ <!&#091;CDATA&#091; \/\/ &#093;&#093;><\/script><noscript><a href=\"https:\/\/ws-na.amazon-adsystem.com\/widgets\/q?rt=tf_mfw&#038;ServiceVersion=20070822&#038;MarketPlace=US&#038;ID=V20070822%2FUS%2Fdaveworkswebd-20%2F8001%2F6a32ecd7-9e84-484b-a30f-ebfdd86553e9&#038;Operation=NoScript\">Amazon.com Widgets<\/a><\/noscript><\/p>\n<ul>\n<li>Arduino Mega 2560 R3<\/li>\n<li>Real time clock<\/li>\n<li>L298N Motor Driver Dual H-Bridge<\/li>\n<li>16 x 2 LCD<\/li>\n<li>5 pin din male and female connectors<\/li>\n<li>RCA male and female connectors<\/li>\n<li>12 V cooling fan<\/li>\n<li>Wire ties<\/li>\n<li>Wire (yellow, read, black &amp; green)<\/li>\n<li>Tie downs<\/li>\n<li>Box<\/li>\n<li>Shrink tubing<\/li>\n<li>Bread board<\/li>\n<li>Resistors<\/li>\n<li>Relays<\/li>\n<li>Velcro<\/li>\n<li>9v power supply<\/li>\n<li>12v power supply<\/li>\n<li>24 volt power supply<\/li>\n<li>USB connector<\/li>\n<li>Cable labels<\/li>\n<\/ul>\n<h3>The Arduino Chicken Coop Code<\/h3>\n<div id=\"attachment_6738\" style=\"width: 160px\" class=\"wp-caption alignright\"><a href=\"https:\/\/davenaves.com\/blog\/interests-projects\/chickens\/chicken-coop\/code-for-arduino-chicken-coop-door\/attachment\/david-naves-headshot-rounded-corner\/\" rel=\"attachment wp-att-6738\"><img decoding=\"async\" aria-describedby=\"caption-attachment-6738\" class=\"lazyload size-thumbnail wp-image-6738\" src=\"https:\/\/davenaves.com\/blog\/wp-content\/uploads\/david-naves-headshot-rounded-corner-150x150.png\" data-orig-src=\"https:\/\/davenaves.com\/blog\/wp-content\/uploads\/david-naves-headshot-rounded-corner-150x150.png\" alt=\"David Naves\" width=\"150\" height=\"150\" srcset=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20width%3D%27150%27%20height%3D%27150%27%20viewBox%3D%270%200%20150%20150%27%3E%3Crect%20width%3D%27150%27%20height%3D%27150%27%20fill-opacity%3D%220%22%2F%3E%3C%2Fsvg%3E\" data-srcset=\"https:\/\/davenaves.com\/blog\/wp-content\/uploads\/david-naves-headshot-rounded-corner-64x64.png 64w, https:\/\/davenaves.com\/blog\/wp-content\/uploads\/david-naves-headshot-rounded-corner-100x100.png 100w, https:\/\/davenaves.com\/blog\/wp-content\/uploads\/david-naves-headshot-rounded-corner-150x150.png 150w, https:\/\/davenaves.com\/blog\/wp-content\/uploads\/david-naves-headshot-rounded-corner-300x297.png 300w, https:\/\/davenaves.com\/blog\/wp-content\/uploads\/david-naves-headshot-rounded-corner-500x496.png 500w, https:\/\/davenaves.com\/blog\/wp-content\/uploads\/david-naves-headshot-rounded-corner-700x694.png 700w, https:\/\/davenaves.com\/blog\/wp-content\/uploads\/david-naves-headshot-rounded-corner.png 976w\" data-sizes=\"auto\" data-orig-sizes=\"(max-width: 150px) 100vw, 150px\" \/><\/a><p id=\"caption-attachment-6738\" class=\"wp-caption-text\">David Naves<\/p><\/div>\n<p><em style=\"color: #000;\">I&#8217;m hoping that if you use or modify my code or ideas, you will share *your* coop project with me and the world (pictures, whatever) I&#8217;m big on sharing.<\/em><\/p>\n<p>Cheers,<br \/>\n\/\/D<\/p>\n<p><strong><a title=\"Download The Arduino Automated Chicken Coop Code\" href=\"https:\/\/davenaves.com\/blog\/wp-content\/uploads\/Dave_Naves_Chicken_Coop_Controller.zip\">Download The Arduino Automated Chicken Coop Code<\/a><\/strong> (zipped)<\/p>\n<\/div><style type=\"text\/css\" scopped=\"scopped\">.fusion-syntax-highlighter-1 > .CodeMirror, .fusion-syntax-highlighter-1 > .CodeMirror .CodeMirror-gutters {background-color:var(--awb-color1);}.fusion-syntax-highlighter-1 > .CodeMirror .CodeMirror-gutters { background-color: var(--awb-color2); }.fusion-syntax-highlighter-1 > .CodeMirror .CodeMirror-linenumber { color: var(--awb-color8); }<\/style><div class=\"fusion-syntax-highlighter-container fusion-syntax-highlighter-1 fusion-syntax-highlighter-theme-light\" style=\"opacity:0;margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:14px;border-width:1px;border-style:solid;border-color:#e0dede;\"><div class=\"syntax-highlighter-copy-code\"><span class=\"syntax-highlighter-copy-code-title\" data-id=\"fusion_syntax_highlighter_1\" style=\"font-size:14px;\">Copy to Clipboard<\/span><\/div><label for=\"fusion_syntax_highlighter_1\" class=\"screen-reader-text\">Syntax Highlighter<\/label><textarea class=\"fusion-syntax-highlighter-textarea\" id=\"fusion_syntax_highlighter_1\" data-readOnly=\"nocursor\" data-lineNumbers=\"1\" data-lineWrapping=\"\" data-theme=\"default\" data-mode=\"text\/x-sh\">\n<pre class=\"height-set:true height:100 height-unit:1 width-set:true width:100 width-unit:1 lang:default decode:true\" title=\"Arduino Chicken Coop Controller Code\">\n\/\/ libraries\n\n\n#include                      \/\/ load the SimpleTimer library to make timers, instead of delays &amp; too many millis statements\n#include                          \/\/ load the onewire library for thermometer\n\/\/ #include                            \/\/ load the servo library\n#include                    \/\/ load the liquid crystal library\n\n\n\n\/\/ print debug messages or not to serial \nconst boolean SerialDisplay = false;\n\n\/*\n* Copyright 2016, David Naves (http:\/\/daveworks.net, http:\/\/davenaves.com)\n*\n* This program is free software; you can redistribute it and\/or\n* modify it under the terms of the GNU General Public License\n* as published by the Free Software Foundation; either version 3\n* of the License, or (at your option) any later version.\n* \n* This program is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU General Public License for more details.\n* \n* You should have received a copy of the GNU General Public License\n* along with this program; if not, see \n \n*\/\n \n \/*\n* I'm hoping that if you use\/modify this code, you will share your\n* coop project with me and the world (pictures, whatever)\n* I'm big on sharing.\n* Cheers,\n* \/\/D\n*\/\n \n\n\n\/\/ pins assignments\n\n\/\/ temperature chip i\/o\nconst int photocellPin = A0;                 \/\/ photocell connected to analog 0\nconst int thermometer = 3;                   \/\/ thermometer DS18S20 on digital pin 3\n\nconst int relayHeat = 5;                     \/\/ heat lamp relay set to digital pin 5\nconst int relayFan = 6;                      \/\/ exhaust fan relay set to digital pin 6\nconst int enableCoopDoorMotorB = 7;          \/\/ enable motor b - pin 7\nconst int directionCloseCoopDoorMotorB = 8;  \/\/ direction close motor b - pin 8\nconst int directionOpenCoopDoorMotorB = 9;   \/\/ direction open motor b - pin 9\nconst int bottomSwitchPin = 26;              \/\/ bottom switch is connected to pin 26\nconst int topSwitchPin = 27;                 \/\/ top switch is connected to pin 27\nconst int coopDoorOpenLed = 40;              \/\/ led set to digital pin 40\nconst int coopDoorClosedLed = 41;            \/\/ led set to digital pin 41\n\/\/ const int relayElectricFence = 43;        \/\/ heat lamp relay set to digital pin 43\nconst int relayInteriorLight = 45;           \/\/ interior lights relay set to digital pin 45\n\n\n\/\/ variables\n\n\n\/\/ photocell\nint photocellReading;                            \/\/ analog reading of the photocel\nint photocellReadingLevel;                       \/\/ photocel reading levels (dark, twilight, light)\n\n\/\/ reed switches top and bottom of coop door\n\n\/\/ top switch\n\nint topSwitchPinVal;                   \/\/ top switch var for reading the pin status\nint topSwitchPinVal2;                  \/\/ top switch var for reading the pin delay\/debounce status\nint topSwitchState;                    \/\/ top switch var for to hold the switch state\n\n\/\/ bottom switch\n\nint bottomSwitchPinVal;                \/\/ bottom switch var for reading the pin status\nint bottomSwitchPinVal2;               \/\/ bottom switch var for reading the pin delay\/debounce status\nint bottomSwitchState;                 \/\/ bottom switch var for to hold the switch state\n\n\/\/ SimpleTimer objects\nSimpleTimer coopPhotoCellTimer;\n\n\n\/\/ debounce delay\nlong lastDebounceTime = 0;\nlong debounceDelay = 100;\n\n\n\/\/ temperature check delay\nlong lastTempCheckTime = 0;\nlong TempCheckDelay = 600000;           \/\/ 10 minutes\n\n\n\/\/ interior lights twighlight delay\nlong lastTwilightTime = 0;\nlong TwilightDelay = 300000;           \/\/ 5 minutes\n\n\n\/\/ temperature chip i\/o\nOneWire ds(thermometer);               \/\/ thermometer on digital pin 3\n\n\/\/ chicken cam servo \n\/\/ Servo chickenCamServo;              \/\/  servo object to control chickenCam\n\/\/ int chickenCamServoPos = 0;         \/\/ chickenCamServoPosition var\n\n\/\/ lcd\nLiquidCrystal lcd(38, 37, 36, 32, 33, 34, 35);   \/\/ lcd pin assignments\nint backLight = 13;                              \/\/ pin 13 controls backlight\n\/*\nLCD Pin\t &gt; arduino Pin\n \n lcd pin 1 VSS &gt;\t    gnd arduino pin\n lcd pin 2 VDD &gt;\t    +5v arduino pin\n lcd pin 3 VO(contrast) &gt;   330 ohm resistor to gnd arduino pin\n lcd pin 4 RS\t            arduino pin 38\n lcd pin 5 R\/W\t            arduino pin 37\n lcd pin 6 Enable\t    arduino pin 36\n lcd pin 7  -\t \n lcd pin 8  -\t \n lcd pin 9  -\t \n lcd pin 10 -\t \n lcd pin 11 (Data 4)    &gt;   arduino pin 32\n lcd pin 12 (Data 5)    &gt;   arduino pin 33\n lcd pin 13 (Data 6)    &gt;   arduino pin 34\n lcd pin 14 (Data 7)    &gt;   arduino pin 35\n lcd pin 15 Backlight + &gt;   arduino pin 13 (built-in resistor)\n lcd pin 16 Backlight   &gt;   arduino gnd pin\n *\/\n\n\n\n\n\/\/ ************************************** the setup **************************************\n\nvoid setup(void) {\n\n  Serial.begin(9600); \/\/ initialize serial port hardware\n\n\n  \/\/ welcome message\n  if(SerialDisplay){\n    Serial.println(\" Processes running:\");\n    Serial.println(\" Timer readPhotoCell every 10 minutes - light levels: open or close door\");\n  }\n  \/\/ coop hvac\n\n  pinMode(relayHeat, OUTPUT);   \/\/set heat lamp relay output\n  pinMode(relayFan, OUTPUT);    \/\/set exhaust fan relay output\n\n  \/\/ coop door  \n\n  \/\/ coop door motor\n  pinMode (enableCoopDoorMotorB, OUTPUT);           \/\/ enable motor pin = output\n  pinMode (directionCloseCoopDoorMotorB, OUTPUT);   \/\/ motor close direction pin = output\n  pinMode (directionOpenCoopDoorMotorB, OUTPUT);    \/\/ motor open direction pin = output\n\n  \/\/ coop door leds\n  pinMode (coopDoorOpenLed, OUTPUT);                \/\/ enable coopDoorOpenLed = output\n  pinMode (coopDoorClosedLed, OUTPUT);              \/\/ enable coopDoorClosedLed = output\n\n  \/\/ coop door switches\n  \/\/ bottom switch\n  pinMode(bottomSwitchPin, INPUT);                  \/\/ set bottom switch pin as input\n  digitalWrite(bottomSwitchPin, HIGH);              \/\/ activate bottom switch resistor\n\n  \/\/ top switch\n  pinMode(topSwitchPin, INPUT);                     \/\/ set top switch pin as input\n  digitalWrite(topSwitchPin, HIGH);                 \/\/ activate top switch resistor  \n\n  \/\/ interior lights relay\n  pinMode(relayInteriorLight, OUTPUT);\n  digitalWrite(relayInteriorLight, HIGH);\n\n  \/\/ electric fence relay\n  \/\/ pinMode(relayElectricFence, OUTPUT);                   \/\/ set electric fence relay as output\n\n  \/\/ timed actions setup\n  coopPhotoCellTimer.setInterval(600000, readPhotoCell);   \/\/ read the photocell every 10 minutes\n\n\n\n  \/\/ servo for interior chicken web cam  \n  \/\/  chickenCamServo.attach(11);                          \/\/ chickenCamServo on pin 11\n\n\n\n}\n\n\/\/ ************************************** functions **************************************\n\n\/\/ coop hvac\n\nvoid doCoopHVACHeat() {\n\n  float temperature = getTemp();                    \/\/ create temperature variable\n  float tempF = (temperature * 9.0)\/ 5.0 + 32.0;    \/\/ convert celcius to fahrenheit\n  if(SerialDisplay){\n    Serial.print(\" Coop Temperature:\");             \/\/ print out coop temperature \n    Serial.println(tempF);                          \/\/ print out the temperature \n  }\n\n  if ((millis() - lastTempCheckTime) &gt; TempCheckDelay) {    \/\/ check temperature every 10 minutes\n\n    \/\/ if cold, turn on heat lamps\n    if (tempF &lt;= 40) { \/\/ if temp drops below 40F turn on heat lamp(s) relay digitalWrite(relayHeat, HIGH); } else if (tempF &gt; 40) {\n      digitalWrite(relayHeat, LOW);                        \/\/ if temp remains above 40F turn off heat lamp(s) relay\n    }\n  }\n}\n\n\n\n\/\/ if hot, turn on cooling fans\n\nvoid doCoopHVACCool() {\n\n  float temperature = getTemp();                    \/\/ create temperature variable\n  float tempF = (temperature * 9.0)\/ 5.0 + 32.0;    \/\/ convert celcius to fahrenheit\n  if(SerialDisplay){\n    Serial.print(\" Coop Temperature:\");             \/\/ print out coop temperature \n    Serial.println(tempF);                          \/\/ print out the temperature \n  }\n\n  if ((millis() - lastTempCheckTime) &gt; TempCheckDelay) {    \/\/ check temperature every 10 minutes\n    if (tempF &gt;= 83) {                                      \/\/ if temp rises above 85F turn on cooling fan(s) relay\n      digitalWrite(relayFan, HIGH);\n    }\n\n    else if (tempF &lt; 83) {\n      digitalWrite(relayFan, LOW);\n    }\n  }\n}\n\n\n\n\/\/ credit: bildr.org\/2011\/07\/ds18b20-arduino\/\n\/\/ DS18S20 digital thermometer stuff\n\nfloat getTemp(){                 \/\/returns the temperature from one DS18S20 in DEG Celsius\n\n  byte data[12];\n  byte addr[8];\n\n  if ( !ds.search(addr)) {\n    \/\/no more sensors on chain, reset search\n    ds.reset_search();\n    return -1000;\n  }\n\n  if ( OneWire::crc8( addr, 7) != addr[7]) {\n    Serial.println(\"CRC is not valid!\");\n    return -1000;\n  }\n\n  if ( addr[0] != 0x10 &amp;&amp; addr[0] != 0x28) {\n    Serial.print(\"Device is not recognized\");\n    return -1000;\n  }\n\n  ds.reset();\n  ds.select(addr);\n  ds.write(0x44,1);                 \/\/ start conversion, with parasite power on at the end\n\n  byte present = ds.reset();\n  ds.select(addr);  \n  ds.write(0xBE);                   \/\/ Read Scratchpad\n\n\n  for (int i = 0; i &lt; 9; i++) {     \/\/ we need 9 bytes\n    data[i] = ds.read();\n  }\n\n  ds.reset_search();\n\n  byte MSB = data[1];\n  byte LSB = data[0];\n\n  float tempRead = ((MSB &lt;&lt; 8) | LSB); \/\/using two's compliment float TemperatureSum = tempRead \/ 16; return TemperatureSum; } \/\/ operate the coop door \/\/ photocel to read levels of exterior light void readPhotoCell() { \/\/ function to be called repeatedly - per coopPhotoCellTimer set in setup photocellReading = analogRead(photocellPin); if(SerialDisplay){ Serial.print(\" Photocel Analog Reading = \"); Serial.println(photocellReading); } \/\/ set photocel threshholds if (photocellReading &gt;= 0 &amp;&amp; photocellReading &lt;= 3) { photocellReadingLevel = '1'; if(SerialDisplay){ Serial.print(\" Photocel Reading Level:\"); Serial.println(\" - Dark\"); } } else if (photocellReading &gt;= 4 &amp;&amp; photocellReading &lt;= 120){ photocellReadingLevel = '2'; if(SerialDisplay){ Serial.print(\" Photocel Reading Level:\"); Serial.println(\" - Twilight\"); } } else if (photocellReading &gt;= 125 ) {\n    photocellReadingLevel = '3';\n    if(SerialDisplay){\n      Serial.print(\" Photocel Reading Level:\");\n      Serial.println(\" - Light\");\n    }\n  }\n}\n\n\/\/debounce bottom reed switch\n\nvoid debounceBottomReedSwitch() { \n\n  \/\/debounce bottom reed switch\n  bottomSwitchPinVal = digitalRead(bottomSwitchPin);       \/\/ read input value and store it in val\n  \/\/ delay(10);\n\n  if ((millis() - lastDebounceTime) &gt; debounceDelay) {    \/\/ delay 10ms for consistent readings\n\n    bottomSwitchPinVal2 = digitalRead(bottomSwitchPin);    \/\/ read input value again to check or bounce\n\n    if (bottomSwitchPinVal == bottomSwitchPinVal2) {       \/\/ make sure we have 2 consistant readings\n      if (bottomSwitchPinVal != bottomSwitchState) {       \/\/ the switch state has changed!\n        bottomSwitchState = bottomSwitchPinVal;\n      }\n      if(SerialDisplay){\n        Serial.print (\" Bottom Switch Value: \");           \/\/ display \"Bottom Switch Value:\" \n        Serial.println(digitalRead(bottomSwitchPin));      \/\/ display current value of bottom switch;\n      }\n    }\n  }\n}\n\n\n\n\/\/ debounce top reed switch\nvoid debounceTopReedSwitch() {\n\n  topSwitchPinVal = digitalRead(topSwitchPin);             \/\/ read input value and store it in val\n  \/\/  delay(10);\n\n  if ((millis() - lastDebounceTime) &gt; debounceDelay) {     \/\/ delay 10ms for consistent readings\n\n    topSwitchPinVal2 = digitalRead(topSwitchPin);          \/\/ read input value again to check or bounce\n\n    if (topSwitchPinVal == topSwitchPinVal2) {             \/\/ make sure we have 2 consistant readings\n      if (topSwitchPinVal != topSwitchState) {             \/\/ the button state has changed!\n        topSwitchState = topSwitchPinVal;\n      }\n      if(SerialDisplay){\n        Serial.print (\" Top Switch Value: \");              \/\/ display \"Bottom Switch Value:\" \n        Serial.println(digitalRead(topSwitchPin));         \/\/ display current value of bottom switch;\n      }\n    }\n  }\n}\n\n\n\/\/ stop the coop door motor\nvoid stopCoopDoorMotorB(){\n  digitalWrite (directionCloseCoopDoorMotorB, LOW);      \/\/ turn off motor close direction\n  digitalWrite (directionOpenCoopDoorMotorB, LOW);       \/\/ turn on motor open direction\n  analogWrite (enableCoopDoorMotorB, 0);                 \/\/ enable motor, 0 speed\n}\n\n\n\n\/\/ close the coop door motor (motor dir close = clockwise) \nvoid closeCoopDoorMotorB() {  \n  digitalWrite (directionCloseCoopDoorMotorB, HIGH);     \/\/ turn on motor close direction\n  digitalWrite (directionOpenCoopDoorMotorB, LOW);       \/\/ turn off motor open direction\n  analogWrite (enableCoopDoorMotorB, 255);               \/\/ enable motor, full speed \n  if (bottomSwitchPinVal == 0) {                         \/\/ if bottom reed switch circuit is closed\n    stopCoopDoorMotorB();\n    if(SerialDisplay){\n      Serial.print(\" Coop Door Closed - no danger\");\n    }\n  }\n}\n\n\n\n\/\/ open the coop door (motor dir open = counter-clockwise)\nvoid openCoopDoorMotorB() { \n  digitalWrite(directionCloseCoopDoorMotorB, LOW);       \/\/ turn off motor close direction\n  digitalWrite(directionOpenCoopDoorMotorB, HIGH);       \/\/ turn on motor open direction\n  analogWrite(enableCoopDoorMotorB, 255);                \/\/ enable motor, full speed\n  if (topSwitchPinVal == 0) {                            \/\/ if top reed switch circuit is closed\n    stopCoopDoorMotorB();\n    if(SerialDisplay){\n      Serial.print(\" Coop Door open - danger!\");\n    }\n  }\n}\n\n\/\/ blink coop door red led if door is stuck \n\n\/\/ blink  CoopDoorLedOpen (red)\n\/\/ void doCoopDoorLedError(){\n\/\/ digitalWrite (coopDoorOpenLed, HIGH);                  \/\/ blinks coopDoorOpenLed\n\/\/  }\n\n\n\/\/  coop door status: red if open, green if closed, blinking red if stuck \n\nvoid doCoopDoorLed() {\n  if (bottomSwitchPinVal == 0) {                         \/\/ if bottom reed switch circuit is closed\n    digitalWrite (coopDoorClosedLed, HIGH);              \/\/ turns on coopDoorClosedLed (green)\n    digitalWrite (coopDoorOpenLed, LOW);                 \/\/ turns off coopDoorOpenLed (red)\n  }\n  else if(topSwitchPinVal == 0) {                        \/\/ if top reed switch circuit is closed \n    digitalWrite (coopDoorClosedLed, LOW);               \/\/ turns off coopDoorClosedLed (green)\n    digitalWrite (coopDoorOpenLed, HIGH);                \/\/ turns on coopDoorOpenLed (red)\n  }\n  \/\/    else if (topSwitchPinVal != 0)  &amp;&amp; if (bottomSwitchPinVal != 0) {                \/\/ if bottom and top reed switch circuits are open \n  \/\/            doCoopDoorLedError();                         \/\/ blink the coopDoorOpenLed\n  \/\/         }\n  \/\/         }\n  else {\n    digitalWrite (coopDoorClosedLed, LOW);              \/\/ turns off coopDoorClosedLed (green)\n    digitalWrite (coopDoorOpenLed, LOW);                \/\/ turns off coopDoorOpenLed (red)\n  }\n}\n\n\n\n\/\/  turn on interior lights at dusk and turn off after door shuts\n\nvoid doCoopInteriorLightDusk() {\n\n  if ((millis() - lastTwilightTime) &gt; TwilightDelay) {     \/\/ delay 5 mins\n\n    readPhotoCell();\n    bottomSwitchPinVal = digitalRead(bottomSwitchPin);\n    if (bottomSwitchPinVal == 1 &amp;&amp; photocellReading  &gt;= 4 &amp;&amp; photocellReading &lt;= 120) {   \/\/ if bottom reed switch circuit is open and it's twilight\n      digitalWrite (relayInteriorLight, HIGH);\n      if (SerialDisplay) {\n        Serial.println(\" Interior Light: On\");\n      }\n    }\n    else if (bottomSwitchPinVal == 0) {\n      digitalWrite (relayInteriorLight, LOW);\n      if (SerialDisplay) {\n        Serial.println(\" Interior Light: Off\");\n      }\n    }\n  }\n}\n\n\n\n\n\/\/ do the coop door\nvoid doCoopDoor(){\n  if (photocellReadingLevel  == '1') {              \/\/ if it's dark\n    if (photocellReadingLevel != '2') {             \/\/ if it's not twilight\n      if (photocellReadingLevel != '3') {           \/\/ if it's not light \n        debounceTopReedSwitch();                    \/\/ read and debounce the switches\n        debounceBottomReedSwitch();\n        closeCoopDoorMotorB();                      \/\/ close the door\n      }\n    }\n  } \n  if (photocellReadingLevel  == '3') {              \/\/ if it's light\n    if (photocellReadingLevel != '2') {             \/\/ if it's not twilight\n      if (photocellReadingLevel != '1') {           \/\/ if it's not dark \n        debounceTopReedSwitch();                    \/\/ read and debounce the switches\n        debounceBottomReedSwitch();\n        openCoopDoorMotorB();                       \/\/ Open the door\n      }\n    }\n  }\n}\n\n\/\/ chickenCamServo\n\/*\nvoid doChickenCamServo() {\n for (chickenCamServoPos = 0; chickenCamServoPos &lt; 75; chickenCamServoPos += 1) { \/\/ turns servo 0 to 75 degrees; 1 degree at a time chickenCamServo.write(chickenCamServoPos); \/\/ read chickenCamServoPosition variable chickenCamServoPos } for(chickenCamServoPos = 75; chickenCamServoPos&gt;=1; chickenCamServoPos-= 1){      \/\/ return from 75 degrees to 0 degrees; 1 degree at a time\n chickenCamServo.write(chickenCamServoPos);                                    \/\/ read chickenCamServoPosition variable chickenCamServoPos\n }\n }\n \n *\/\n\n\/\/  lcd\nvoid doLcdMsg() {\n\n  float temperature = getTemp();                 \/\/ create temperature variable\n  float tempF = (temperature * 9.0)\/ 5.0 + 32.0; \/\/ convert celcius to fahrenheit\n\n  pinMode(backLight, OUTPUT);            \/\/ backlight pin set as output\n  digitalWrite(backLight, HIGH);         \/\/ backlight on\n  lcd.begin(16,2);                       \/\/ columns, rows\n  lcd.clear();                           \/\/ start with blank screen\n  lcd.setCursor(0,0);                    \/\/ set cursor to column 0, row 0\n  lcd.print(\"Coop Temp:\");               \/\/ show \"Temp\"\n  lcd.print (tempF) ;                    \/\/ show temperature of interior coop\n  lcd.print(\"F\");                        \/\/ show \"F\" \n  lcd.setCursor(0,1);                    \/\/ set cursor to column 0, row 1\n  lcd.print(\"Coop Door:\");               \/\/ show \"Coop Door\"\n\n  if (bottomSwitchPinVal == 0) {         \/\/ if coop door bottom switch is closed\n    lcd.print(\"Closed\");                 \/\/ display \"Closed\"\n  } \n  else if (topSwitchPinVal == 0) {     \/\/ if coop door bottom switch is open\n    lcd.print(\"Open\");  \/\/ display \"Open\"\n  }\n}\n\n\n\n\/\/ ************************************** the loop **************************************\n\nvoid loop() {\n  coopPhotoCellTimer.run();      \/\/ timer for readPhotoCell\n  doCoopHVACCool();\n  doCoopHVACHeat();\n  doCoopDoor();\n  \/\/ doChickenCamServo();\n  doCoopDoorLed();\n  doCoopInteriorLightDusk();\n  doLcdMsg();\n\n}\n\n\n<\/pre><\/textarea><\/div><\/div><\/div><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":2,"featured_media":6562,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[128,18,4],"tags":[183,150,149,166,165],"class_list":["post-6560","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino","category-chicken-coop","category-chickens","tag-arduino","tag-arduino-chicken-coop-controller","tag-chicken-coop-controller","tag-diy-arduino-chicken-coop-controller","tag-diy-chicken-coop-controller"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/davenaves.com\/blog\/wp-json\/wp\/v2\/posts\/6560","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/davenaves.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/davenaves.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/davenaves.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/davenaves.com\/blog\/wp-json\/wp\/v2\/comments?post=6560"}],"version-history":[{"count":39,"href":"https:\/\/davenaves.com\/blog\/wp-json\/wp\/v2\/posts\/6560\/revisions"}],"predecessor-version":[{"id":8397,"href":"https:\/\/davenaves.com\/blog\/wp-json\/wp\/v2\/posts\/6560\/revisions\/8397"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/davenaves.com\/blog\/wp-json\/wp\/v2\/media\/6562"}],"wp:attachment":[{"href":"https:\/\/davenaves.com\/blog\/wp-json\/wp\/v2\/media?parent=6560"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/davenaves.com\/blog\/wp-json\/wp\/v2\/categories?post=6560"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/davenaves.com\/blog\/wp-json\/wp\/v2\/tags?post=6560"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}