<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: Chicken Fever	</title>
	<atom:link href="https://davenaves.com/blog/interests-projects/chickens/chicken-fever/feed/" rel="self" type="application/rss+xml" />
	<link>https://davenaves.com/blog/interests-projects/chickens/chicken-fever/</link>
	<description>Dave Naves - maker - upcycler -  enthusiast</description>
	<lastBuildDate>Wed, 23 Jul 2025 04:49:47 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>
		By: David Naves		</title>
		<link>https://davenaves.com/blog/interests-projects/chickens/chicken-fever/#comment-174</link>

		<dc:creator><![CDATA[David Naves]]></dc:creator>
		<pubDate>Sun, 20 Apr 2014 04:22:52 +0000</pubDate>
		<guid isPermaLink="false">http://davenaves.com/blog/?p=1#comment-174</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://davenaves.com/blog/interests-projects/chickens/chicken-fever/#comment-173&quot;&gt;Mike&lt;/a&gt;.

hi mike,

really appreciate your nice words and comments about the code.  so i think i hear what you&#039;re saying, but maybe i&#039;m misunderstanding...  the way i wrote the function doCoopDoor in order was:

read the photocel, read and debounce the switches, then operate the motor

but you&#039;re thinking that the actual open or close functions might help the clicking if:

void openCoopDoorMotorB() { 
       if (topSwitchPinVal == 0) {                       // if top reed switch circuit is closed
          stopCoopDoorMotorB();
          Serial.print(&quot; Coop Door open - danger!&quot;);
      }
    digitalWrite(directionCloseCoopDoorMotorB, LOW);    // turn off motor close direction
    digitalWrite(directionOpenCoopDoorMotorB, HIGH);    // turn on motor open direction
    analogWrite(enableCoopDoorMotorB, 255);           // enable motor, full speed
      
    }
 
it&#039;s making sense to me... i can&#039;t really test since my motor isn&#039;t clicking but maybe your idea can help chip.  if so, he owes you!!  =)    chip, if you&#039;re still checking the post, try&#039;er out and keep us posted.

thanks again,
//d]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://davenaves.com/blog/interests-projects/chickens/chicken-fever/#comment-173">Mike</a>.</p>
<p>hi mike,</p>
<p>really appreciate your nice words and comments about the code.  so i think i hear what you&#8217;re saying, but maybe i&#8217;m misunderstanding&#8230;  the way i wrote the function doCoopDoor in order was:</p>
<p>read the photocel, read and debounce the switches, then operate the motor</p>
<p>but you&#8217;re thinking that the actual open or close functions might help the clicking if:</p>
<p>void openCoopDoorMotorB() {<br />
       if (topSwitchPinVal == 0) {                       // if top reed switch circuit is closed<br />
          stopCoopDoorMotorB();<br />
          Serial.print(&#8221; Coop Door open &#8211; danger!&#8221;);<br />
      }<br />
    digitalWrite(directionCloseCoopDoorMotorB, LOW);    // turn off motor close direction<br />
    digitalWrite(directionOpenCoopDoorMotorB, HIGH);    // turn on motor open direction<br />
    analogWrite(enableCoopDoorMotorB, 255);           // enable motor, full speed</p>
<p>    }</p>
<p>it&#8217;s making sense to me&#8230; i can&#8217;t really test since my motor isn&#8217;t clicking but maybe your idea can help chip.  if so, he owes you!!  =)    chip, if you&#8217;re still checking the post, try&#8217;er out and keep us posted.</p>
<p>thanks again,<br />
//d</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Mike		</title>
		<link>https://davenaves.com/blog/interests-projects/chickens/chicken-fever/#comment-173</link>

		<dc:creator><![CDATA[Mike]]></dc:creator>
		<pubDate>Sat, 12 Apr 2014 06:26:27 +0000</pubDate>
		<guid isPermaLink="false">http://davenaves.com/blog/?p=1#comment-173</guid>

					<description><![CDATA[Hi Dave, Great job on your Coop Controller. I&#039;m inspired! We are just getting into chickens here and I&#039;ve been tinkering with Arduino for a year or so. Naturally I googled auto door and arduino and found you.  I was looking at your code as I&#039;m about to start my build and think maybe I&#039;ve found why Chip&#039;s motor is clicking...When you &#039;doCoopDoor&#039; and call either &#039;close&#039; or &#039;openCoopDoorMotorB&#039;, the first thing those processes do is start the motor then it checks to see if the switch is closed and calls stopCoopDoorMotorB.  I think that the if statement that checks the reed switch pin value should be first so that if the door is already open/closed the motor is sent &#039;stop&#039; else open/close. This is what I&#039;m going to experiment with when i finally get around to building it.  What do you guys think?]]></description>
			<content:encoded><![CDATA[<p>Hi Dave, Great job on your Coop Controller. I&#8217;m inspired! We are just getting into chickens here and I&#8217;ve been tinkering with Arduino for a year or so. Naturally I googled auto door and arduino and found you.  I was looking at your code as I&#8217;m about to start my build and think maybe I&#8217;ve found why Chip&#8217;s motor is clicking&#8230;When you &#8216;doCoopDoor&#8217; and call either &#8216;close&#8217; or &#8216;openCoopDoorMotorB&#8217;, the first thing those processes do is start the motor then it checks to see if the switch is closed and calls stopCoopDoorMotorB.  I think that the if statement that checks the reed switch pin value should be first so that if the door is already open/closed the motor is sent &#8216;stop&#8217; else open/close. This is what I&#8217;m going to experiment with when i finally get around to building it.  What do you guys think?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: David Naves		</title>
		<link>https://davenaves.com/blog/interests-projects/chickens/chicken-fever/#comment-168</link>

		<dc:creator><![CDATA[David Naves]]></dc:creator>
		<pubDate>Fri, 04 Apr 2014 04:43:20 +0000</pubDate>
		<guid isPermaLink="false">http://davenaves.com/blog/?p=1#comment-168</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://davenaves.com/blog/interests-projects/chickens/chicken-fever/#comment-166&quot;&gt;Chip&lt;/a&gt;.

figured... not exactly sure why.  i took a close listen to my motor after you mentioning that and mine is silent as it should be using my code:
// stop the coop door motor
  void stopCoopDoorMotorB(){
    digitalWrite (directionCloseCoopDoorMotorB, LOW);        // turn off motor close direction
    digitalWrite (directionOpenCoopDoorMotorB, LOW);         // turn on motor open direction
    analogWrite (enableCoopDoorMotorB, 0);                   // enable motor, 0 speed
  }]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://davenaves.com/blog/interests-projects/chickens/chicken-fever/#comment-166">Chip</a>.</p>
<p>figured&#8230; not exactly sure why.  i took a close listen to my motor after you mentioning that and mine is silent as it should be using my code:<br />
// stop the coop door motor<br />
  void stopCoopDoorMotorB(){<br />
    digitalWrite (directionCloseCoopDoorMotorB, LOW);        // turn off motor close direction<br />
    digitalWrite (directionOpenCoopDoorMotorB, LOW);         // turn on motor open direction<br />
    analogWrite (enableCoopDoorMotorB, 0);                   // enable motor, 0 speed<br />
  }</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: David Naves		</title>
		<link>https://davenaves.com/blog/interests-projects/chickens/chicken-fever/#comment-167</link>

		<dc:creator><![CDATA[David Naves]]></dc:creator>
		<pubDate>Fri, 04 Apr 2014 04:40:45 +0000</pubDate>
		<guid isPermaLink="false">http://davenaves.com/blog/?p=1#comment-167</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://davenaves.com/blog/interests-projects/chickens/chicken-fever/#comment-165&quot;&gt;Chip&lt;/a&gt;.

gotcha...

and for me, i need the arduino to continue reading the switch values, b/c i have other functions triggering based on the value (the visual aid led light and a new electric fence, among other things)  i keep going back to thinking that using simpleTimer would do the trick for you.  (like create another timer to deal with shutting off debounce once the door has bully opened or closed.  read this http://playground.arduino.cc/Code/SimpleTimer#.Uz42HqhdUrU  and look for &quot;once&quot; withing the content... you&#039;ll see some examples of what i&#039;m referring to.

and yes, please do send some pics... looking forward to seeing what you&#039;re doing.

cheers!]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://davenaves.com/blog/interests-projects/chickens/chicken-fever/#comment-165">Chip</a>.</p>
<p>gotcha&#8230;</p>
<p>and for me, i need the arduino to continue reading the switch values, b/c i have other functions triggering based on the value (the visual aid led light and a new electric fence, among other things)  i keep going back to thinking that using simpleTimer would do the trick for you.  (like create another timer to deal with shutting off debounce once the door has bully opened or closed.  read this <a href="http://playground.arduino.cc/Code/SimpleTimer#.Uz42HqhdUrU" rel="nofollow ugc">http://playground.arduino.cc/Code/SimpleTimer#.Uz42HqhdUrU</a>  and look for &#8220;once&#8221; withing the content&#8230; you&#8217;ll see some examples of what i&#8217;m referring to.</p>
<p>and yes, please do send some pics&#8230; looking forward to seeing what you&#8217;re doing.</p>
<p>cheers!</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Chip		</title>
		<link>https://davenaves.com/blog/interests-projects/chickens/chicken-fever/#comment-166</link>

		<dc:creator><![CDATA[Chip]]></dc:creator>
		<pubDate>Mon, 31 Mar 2014 19:45:42 +0000</pubDate>
		<guid isPermaLink="false">http://davenaves.com/blog/?p=1#comment-166</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://davenaves.com/blog/interests-projects/chickens/chicken-fever/#comment-165&quot;&gt;Chip&lt;/a&gt;.

oh - and its the motor clicking, not the arduino]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://davenaves.com/blog/interests-projects/chickens/chicken-fever/#comment-165">Chip</a>.</p>
<p>oh &#8211; and its the motor clicking, not the arduino</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Chip		</title>
		<link>https://davenaves.com/blog/interests-projects/chickens/chicken-fever/#comment-165</link>

		<dc:creator><![CDATA[Chip]]></dc:creator>
		<pubDate>Mon, 31 Mar 2014 18:55:54 +0000</pubDate>
		<guid isPermaLink="false">http://davenaves.com/blog/?p=1#comment-165</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://davenaves.com/blog/interests-projects/chickens/chicken-fever/#comment-158&quot;&gt;David Naves&lt;/a&gt;.

Hi Dave - thanks for the reply.  I will eventually have my door mechanics mounted to a solar panel and deep cycle marine battery for power (I live in AZ so that&#039;s a no brainer).   I don&#039;t know if the clicks would drain a deep cycle marine battery - but I would rather get rid of the arduino pinging the bounce/debounce.

Hooking up the breadboard and arduino to the serial monitor, after I get a successful open or close door function, the serial monitor just continues to print: 
Close Switch Value: 0
Coop Door OPEN Open Switch Value: 1
and continues to print these two states on the switch values coinciding with every &#039;click&#039; I hear on my DC motor.
Just wondering if there is a way to stop this, if your serial monitor does this, and how I might be able to stop it...

I&#039;ll send pics once I get everything installed.

Thanks for thinking!]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://davenaves.com/blog/interests-projects/chickens/chicken-fever/#comment-158">David Naves</a>.</p>
<p>Hi Dave &#8211; thanks for the reply.  I will eventually have my door mechanics mounted to a solar panel and deep cycle marine battery for power (I live in AZ so that&#8217;s a no brainer).   I don&#8217;t know if the clicks would drain a deep cycle marine battery &#8211; but I would rather get rid of the arduino pinging the bounce/debounce.</p>
<p>Hooking up the breadboard and arduino to the serial monitor, after I get a successful open or close door function, the serial monitor just continues to print:<br />
Close Switch Value: 0<br />
Coop Door OPEN Open Switch Value: 1<br />
and continues to print these two states on the switch values coinciding with every &#8216;click&#8217; I hear on my DC motor.<br />
Just wondering if there is a way to stop this, if your serial monitor does this, and how I might be able to stop it&#8230;</p>
<p>I&#8217;ll send pics once I get everything installed.</p>
<p>Thanks for thinking!</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: David Naves		</title>
		<link>https://davenaves.com/blog/interests-projects/chickens/chicken-fever/#comment-158</link>

		<dc:creator><![CDATA[David Naves]]></dc:creator>
		<pubDate>Sat, 22 Mar 2014 06:30:47 +0000</pubDate>
		<guid isPermaLink="false">http://davenaves.com/blog/?p=1#comment-158</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://davenaves.com/blog/interests-projects/chickens/chicken-fever/#comment-155&quot;&gt;Chip&lt;/a&gt;.

hi chip,

thanks for writing in...

hmmm, clicking... are you sure it&#039;s the arduino making the noise? i would think maybe the motor? (or maybe that&#039;s what you&#039;re saying)  but i&#039;m not sure why it would click.  is the motor actually moving?  i kept that delay to 10ms to not bother the tons of other functions i have for the main coop, but to be honest, it has been bothering me. ( i was just getting tired of testing and left it) =)   i&#039;m wondering now if the debounce should be included within another function so that it only debounces during a very specific period of time.i probably should write another ref to simpleTimer for that debounce to get rid of that delay.  (maybe a 1x only timer at dark or light)  

thinking...



as far as wearing anything out, the only thing to worry about would be the battery.  (which i never even considered, since i have a ac power down at my coop) 

also, i see you&#039;re checking the photocell every minute... any problems with your motor misfiring (back and forth) because of inconsistent light readings?  i check every 10 mins to avoid that.  (just curious)

i&#039;ll post back when i come up with something...  you can also check with the pros at the ardiuno forums if i&#039;m too pokey with a solution.  &lt;a href=&quot;http://forum.arduino.cc/&quot; title=&quot;arduino forum&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;http://forum.arduino.cc/&lt;/a&gt;

thanks again for writing in.  post some pics of your project when you can.  would love to see your coop.
//d]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://davenaves.com/blog/interests-projects/chickens/chicken-fever/#comment-155">Chip</a>.</p>
<p>hi chip,</p>
<p>thanks for writing in&#8230;</p>
<p>hmmm, clicking&#8230; are you sure it&#8217;s the arduino making the noise? i would think maybe the motor? (or maybe that&#8217;s what you&#8217;re saying)  but i&#8217;m not sure why it would click.  is the motor actually moving?  i kept that delay to 10ms to not bother the tons of other functions i have for the main coop, but to be honest, it has been bothering me. ( i was just getting tired of testing and left it) =)   i&#8217;m wondering now if the debounce should be included within another function so that it only debounces during a very specific period of time.i probably should write another ref to simpleTimer for that debounce to get rid of that delay.  (maybe a 1x only timer at dark or light)  </p>
<p>thinking&#8230;</p>
<p>as far as wearing anything out, the only thing to worry about would be the battery.  (which i never even considered, since i have a ac power down at my coop) </p>
<p>also, i see you&#8217;re checking the photocell every minute&#8230; any problems with your motor misfiring (back and forth) because of inconsistent light readings?  i check every 10 mins to avoid that.  (just curious)</p>
<p>i&#8217;ll post back when i come up with something&#8230;  you can also check with the pros at the ardiuno forums if i&#8217;m too pokey with a solution.  <a href="http://forum.arduino.cc/" title="arduino forum" target="_blank" rel="nofollow">http://forum.arduino.cc/</a></p>
<p>thanks again for writing in.  post some pics of your project when you can.  would love to see your coop.<br />
//d</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Chip		</title>
		<link>https://davenaves.com/blog/interests-projects/chickens/chicken-fever/#comment-155</link>

		<dc:creator><![CDATA[Chip]]></dc:creator>
		<pubDate>Mon, 17 Mar 2014 19:47:10 +0000</pubDate>
		<guid isPermaLink="false">http://davenaves.com/blog/?p=1#comment-155</guid>

					<description><![CDATA[Hey Dave - thanks for the code and schematic - I altered both to use an Arduino Motor Shield to drive a cordless screwdriver that opens and shuts a horizontal door on my coop.  The code works great with one exception, I am hearing a clicking noise from the Arduino to the cordless screwdriver after the coop door has either opened or closed.  I am ASSUMING that this is the reed switch debouncing, because it &quot;clicks&quot; at the same cadence set in the code, and I changed the delay in that section of the code and it clicks to whatever I set the delay rate to.  

How do I stop this?  I think this constant debouncing of the switches will wear any battery/motor/arduino out over extended periods of time...maybe not?

It does NOT happen if I get a &#039;TWILIGHT&#039; reading, only after the coop door opens or closes.
  
Any help greaty appreciated - I am an Arduino newbie.  Below is my altered code.  Thanks!

***********************************************************************************************************************
// libraries
 
  #include                      // load the SimpleTimer library to make timers, instead of delays &#038; too many millis statements
 
/*
* Copyright 2013, David Naves (http://daveworks.net, http://davenaves.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, see 
 
*/
 
 /*
* I&#039;m hoping that if you use/modify this code, you will share your
* coop project with me and the world (pictures, whatever)
* I&#039;m big on sharing.
* Cheers,
* //D
*/
 
//pins
  const int photocellPin = A0;                 // photocell is connected to analog 0  
  const int closeSwitchPin = 6;                // close reed switch is connected to pin 6
  const int openSwitchPin = 7;                 // open reed switch is connected to pin 7
 
// vars
 
// photocell
  int photocellReading;                        // analog reading of the photocell
  int photocellReadingLevel;                   // photocell reading levels (dark, twilight, light)
 
// reed switches open and close with coop door
 
// open switch
  int openSwitchPinVal;                   // open switch var for reading the pin status
  int openSwitchPinVal2;                  // open switch var for reading the pin delay/debounce status
  int openSwitchState;                    // open switch var for to hold the switch state
 
// close switch
  int closeSwitchPinVal;                // close switch var for reading the pin status
  int closeSwitchPinVal2;               // close switch var for reading the pin delay/debounce status
  int closeSwitchState;                 // close switch var for to hold the switch state
 
// just need 1 SimpleTimer object
  SimpleTimer coopTimer;
// ************************************** the setup **************************************
 
void setup(void) {
  Serial.begin(9600);
 
// welcome message
  Serial.println(&quot; Checking doCoopDoor: every 1 minute for light levels to open or close door&quot;);
  Serial.println();
 
// coop door  
 
// coop door motor
  pinMode (12, OUTPUT);            // Initiates motor pin for channel A
  pinMode (9, OUTPUT);             // Initiates break pin for channel A
 
// disengage the motor brakes
  digitalWrite(9, LOW);            // Disengage the Brake for Channel A

// coop door switches
// close switch
  pinMode(closeSwitchPin, INPUT);                   // set close switch pin as input
  digitalWrite(closeSwitchPin, HIGH);               // activate close switch resistor
 
// open switch
  pinMode(openSwitchPin, INPUT);                      // set open switch pin as input
  digitalWrite(openSwitchPin, HIGH);                  // activate open switch resistor  
 
  // timed actions setup
  coopTimer.setInterval(60000, readPhotoCell);      // read the photocell every 1 minute
 
}
 
// functions
 
// operate the coop door
 
// photocell to read levels of exterior light
 
 void readPhotoCell() { // function to be called repeatedly - per cooptimer set in setup
 
    photocellReading = analogRead(photocellPin);
      Serial.print(&quot; Photocell Analog Reading = &quot;);
      Serial.println(photocellReading);
 
//  set photocell threshholds
        if (photocellReading &#062;= 0 &#038;&#038; photocellReading = 15 &#038;&#038; photocellReading = 25 ) {
         photocellReadingLevel = &#039;3&#039;;
         Serial.print(&quot; Photocell Reading Level:&quot;);
         Serial.println(&quot; - Light&quot;);
       }
     }
 
//debounce close reed switch
 
  void debounceCloseReedSwitch() { 
 
    //debounce close reed switch
    closeSwitchPinVal = digitalRead(closeSwitchPin);        // read input value and store it in val
    delay(100);
    closeSwitchPinVal2 = digitalRead(closeSwitchPin);       // read input value again to check or bounce
 
      if (closeSwitchPinVal == closeSwitchPinVal2) {        // make sure we got 2 consistant readings!
        if (closeSwitchPinVal != closeSwitchState) {        // the switch state has changed!
          closeSwitchState = closeSwitchPinVal;
        }
        Serial.print (&quot; Close Switch Value: &quot;);             // display &quot;Close Switch Value:&quot; 
        Serial.println(digitalRead(closeSwitchPin));        // display current value of close switch;
      }
    }
 
 // debounce open reed switch
  void debounceOpenReedSwitch() {
 
    openSwitchPinVal = digitalRead(openSwitchPin);               // read input value and store it in val
    delay(100);
    openSwitchPinVal2 = digitalRead(openSwitchPin);              // read input value again to check or bounce
 
      if (openSwitchPinVal == openSwitchPinVal2) {               // make sure we got 2 consistant readings!
        if (openSwitchPinVal != openSwitchState) {               // the switch state has changed!
          openSwitchState = openSwitchPinVal;
        }
        Serial.print (&quot; Open Switch Value: &quot;);                // display &quot;Open Switch Value:&quot; 
        Serial.println(digitalRead(openSwitchPin));           // display current value of close switch;
      }
    }
 
// stop the coop door motor
  void stopCoopDoor(){
    digitalWrite (9, HIGH);          // engages brake
    analogWrite (3,0);               // motor is on zero speed
  }
 
// close the coop door motor (motor dir close = counter-clockwise) 
  void closeCoopDoor() {  
    digitalWrite (9, LOW);              // disengages brake
    digitalWrite (12, HIGH);            // turn on motor close direction
    analogWrite (3, 255);               // enable motor, full speed 
      if (closeSwitchPinVal == 1) {     // if close reed switch circuit is closed
        stopCoopDoor();
        Serial.print(&quot; Coop Door CLOSED &quot;);
      }
    }
 
  // open the coop door (motor dir open = clockwise)
  void openCoopDoor() { 
    digitalWrite (9, LOW);          // disengages brake
    digitalWrite(12, LOW);          // turn on motor open direction
      analogWrite(3, 255);           // enable motor, full speed
      if (openSwitchPinVal == 1) {   // if open reed switch circuit is closed
          stopCoopDoor();
          Serial.print(&quot; Coop Door OPEN&quot;);
      }
    }
 
  void doCoopDoor(){
 
      if (photocellReadingLevel  == &#039;1&#039;) {              // if it&#039;s dark
        if (photocellReadingLevel != &#039;2&#039;) {             // if it&#039;s not twilight
          if (photocellReadingLevel != &#039;3&#039;) {           // if it&#039;s not light 
            debounceOpenReedSwitch();                    // read and debounce the switches
            debounceCloseReedSwitch();
            closeCoopDoor();                      // close the door
          }
        }
      } 
       if (photocellReadingLevel  == &#039;3&#039;) {             // if it&#039;s light
        if (photocellReadingLevel != &#039;2&#039;) {             // if it&#039;s not twilight
          if (photocellReadingLevel != &#039;1&#039;) {           // if it&#039;s not dark 
            debounceOpenReedSwitch();                    // read and debounce the switches
            debounceCloseReedSwitch();
            openCoopDoor();                       // Open the door
          }
        }
      }
    }
 
// ************************************** the loop **************************************
void loop() {
  //  polling occurs
  coopTimer.run();
  doCoopDoor();]]></description>
			<content:encoded><![CDATA[<p>Hey Dave &#8211; thanks for the code and schematic &#8211; I altered both to use an Arduino Motor Shield to drive a cordless screwdriver that opens and shuts a horizontal door on my coop.  The code works great with one exception, I am hearing a clicking noise from the Arduino to the cordless screwdriver after the coop door has either opened or closed.  I am ASSUMING that this is the reed switch debouncing, because it &#8220;clicks&#8221; at the same cadence set in the code, and I changed the delay in that section of the code and it clicks to whatever I set the delay rate to.  </p>
<p>How do I stop this?  I think this constant debouncing of the switches will wear any battery/motor/arduino out over extended periods of time&#8230;maybe not?</p>
<p>It does NOT happen if I get a &#8216;TWILIGHT&#8217; reading, only after the coop door opens or closes.</p>
<p>Any help greaty appreciated &#8211; I am an Arduino newbie.  Below is my altered code.  Thanks!</p>
<p>***********************************************************************************************************************<br />
// libraries</p>
<p>  #include                      // load the SimpleTimer library to make timers, instead of delays &amp; too many millis statements</p>
<p>/*<br />
* Copyright 2013, David Naves (<a href="http://daveworks.net" rel="nofollow ugc">http://daveworks.net</a>, <a href="http://davenaves.com" rel="ugc">http://davenaves.com</a>)<br />
*<br />
* This program is free software; you can redistribute it and/or<br />
* modify it under the terms of the GNU General Public License<br />
* as published by the Free Software Foundation; either version 3<br />
* of the License, or (at your option) any later version.<br />
*<br />
* This program is distributed in the hope that it will be useful,<br />
* but WITHOUT ANY WARRANTY; without even the implied warranty of<br />
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br />
* GNU General Public License for more details.<br />
*<br />
* You should have received a copy of the GNU General Public License<br />
* along with this program; if not, see </p>
<p>*/</p>
<p> /*<br />
* I&#8217;m hoping that if you use/modify this code, you will share your<br />
* coop project with me and the world (pictures, whatever)<br />
* I&#8217;m big on sharing.<br />
* Cheers,<br />
* //D<br />
*/</p>
<p>//pins<br />
  const int photocellPin = A0;                 // photocell is connected to analog 0<br />
  const int closeSwitchPin = 6;                // close reed switch is connected to pin 6<br />
  const int openSwitchPin = 7;                 // open reed switch is connected to pin 7</p>
<p>// vars</p>
<p>// photocell<br />
  int photocellReading;                        // analog reading of the photocell<br />
  int photocellReadingLevel;                   // photocell reading levels (dark, twilight, light)</p>
<p>// reed switches open and close with coop door</p>
<p>// open switch<br />
  int openSwitchPinVal;                   // open switch var for reading the pin status<br />
  int openSwitchPinVal2;                  // open switch var for reading the pin delay/debounce status<br />
  int openSwitchState;                    // open switch var for to hold the switch state</p>
<p>// close switch<br />
  int closeSwitchPinVal;                // close switch var for reading the pin status<br />
  int closeSwitchPinVal2;               // close switch var for reading the pin delay/debounce status<br />
  int closeSwitchState;                 // close switch var for to hold the switch state</p>
<p>// just need 1 SimpleTimer object<br />
  SimpleTimer coopTimer;<br />
// ************************************** the setup **************************************</p>
<p>void setup(void) {<br />
  Serial.begin(9600);</p>
<p>// welcome message<br />
  Serial.println(&#8221; Checking doCoopDoor: every 1 minute for light levels to open or close door&#8221;);<br />
  Serial.println();</p>
<p>// coop door  </p>
<p>// coop door motor<br />
  pinMode (12, OUTPUT);            // Initiates motor pin for channel A<br />
  pinMode (9, OUTPUT);             // Initiates break pin for channel A</p>
<p>// disengage the motor brakes<br />
  digitalWrite(9, LOW);            // Disengage the Brake for Channel A</p>
<p>// coop door switches<br />
// close switch<br />
  pinMode(closeSwitchPin, INPUT);                   // set close switch pin as input<br />
  digitalWrite(closeSwitchPin, HIGH);               // activate close switch resistor</p>
<p>// open switch<br />
  pinMode(openSwitchPin, INPUT);                      // set open switch pin as input<br />
  digitalWrite(openSwitchPin, HIGH);                  // activate open switch resistor  </p>
<p>  // timed actions setup<br />
  coopTimer.setInterval(60000, readPhotoCell);      // read the photocell every 1 minute</p>
<p>}</p>
<p>// functions</p>
<p>// operate the coop door</p>
<p>// photocell to read levels of exterior light</p>
<p> void readPhotoCell() { // function to be called repeatedly &#8211; per cooptimer set in setup</p>
<p>    photocellReading = analogRead(photocellPin);<br />
      Serial.print(&#8221; Photocell Analog Reading = &#8220;);<br />
      Serial.println(photocellReading);</p>
<p>//  set photocell threshholds<br />
        if (photocellReading &gt;= 0 &amp;&amp; photocellReading = 15 &amp;&amp; photocellReading = 25 ) {<br />
         photocellReadingLevel = &#8216;3&#8217;;<br />
         Serial.print(&#8221; Photocell Reading Level:&#8221;);<br />
         Serial.println(&#8221; &#8211; Light&#8221;);<br />
       }<br />
     }</p>
<p>//debounce close reed switch</p>
<p>  void debounceCloseReedSwitch() { </p>
<p>    //debounce close reed switch<br />
    closeSwitchPinVal = digitalRead(closeSwitchPin);        // read input value and store it in val<br />
    delay(100);<br />
    closeSwitchPinVal2 = digitalRead(closeSwitchPin);       // read input value again to check or bounce</p>
<p>      if (closeSwitchPinVal == closeSwitchPinVal2) {        // make sure we got 2 consistant readings!<br />
        if (closeSwitchPinVal != closeSwitchState) {        // the switch state has changed!<br />
          closeSwitchState = closeSwitchPinVal;<br />
        }<br />
        Serial.print (&#8221; Close Switch Value: &#8220;);             // display &#8220;Close Switch Value:&#8221;<br />
        Serial.println(digitalRead(closeSwitchPin));        // display current value of close switch;<br />
      }<br />
    }</p>
<p> // debounce open reed switch<br />
  void debounceOpenReedSwitch() {</p>
<p>    openSwitchPinVal = digitalRead(openSwitchPin);               // read input value and store it in val<br />
    delay(100);<br />
    openSwitchPinVal2 = digitalRead(openSwitchPin);              // read input value again to check or bounce</p>
<p>      if (openSwitchPinVal == openSwitchPinVal2) {               // make sure we got 2 consistant readings!<br />
        if (openSwitchPinVal != openSwitchState) {               // the switch state has changed!<br />
          openSwitchState = openSwitchPinVal;<br />
        }<br />
        Serial.print (&#8221; Open Switch Value: &#8220;);                // display &#8220;Open Switch Value:&#8221;<br />
        Serial.println(digitalRead(openSwitchPin));           // display current value of close switch;<br />
      }<br />
    }</p>
<p>// stop the coop door motor<br />
  void stopCoopDoor(){<br />
    digitalWrite (9, HIGH);          // engages brake<br />
    analogWrite (3,0);               // motor is on zero speed<br />
  }</p>
<p>// close the coop door motor (motor dir close = counter-clockwise)<br />
  void closeCoopDoor() {<br />
    digitalWrite (9, LOW);              // disengages brake<br />
    digitalWrite (12, HIGH);            // turn on motor close direction<br />
    analogWrite (3, 255);               // enable motor, full speed<br />
      if (closeSwitchPinVal == 1) {     // if close reed switch circuit is closed<br />
        stopCoopDoor();<br />
        Serial.print(&#8221; Coop Door CLOSED &#8220;);<br />
      }<br />
    }</p>
<p>  // open the coop door (motor dir open = clockwise)<br />
  void openCoopDoor() {<br />
    digitalWrite (9, LOW);          // disengages brake<br />
    digitalWrite(12, LOW);          // turn on motor open direction<br />
      analogWrite(3, 255);           // enable motor, full speed<br />
      if (openSwitchPinVal == 1) {   // if open reed switch circuit is closed<br />
          stopCoopDoor();<br />
          Serial.print(&#8221; Coop Door OPEN&#8221;);<br />
      }<br />
    }</p>
<p>  void doCoopDoor(){</p>
<p>      if (photocellReadingLevel  == &#8216;1&#8217;) {              // if it&#8217;s dark<br />
        if (photocellReadingLevel != &#8216;2&#8217;) {             // if it&#8217;s not twilight<br />
          if (photocellReadingLevel != &#8216;3&#8217;) {           // if it&#8217;s not light<br />
            debounceOpenReedSwitch();                    // read and debounce the switches<br />
            debounceCloseReedSwitch();<br />
            closeCoopDoor();                      // close the door<br />
          }<br />
        }<br />
      }<br />
       if (photocellReadingLevel  == &#8216;3&#8217;) {             // if it&#8217;s light<br />
        if (photocellReadingLevel != &#8216;2&#8217;) {             // if it&#8217;s not twilight<br />
          if (photocellReadingLevel != &#8216;1&#8217;) {           // if it&#8217;s not dark<br />
            debounceOpenReedSwitch();                    // read and debounce the switches<br />
            debounceCloseReedSwitch();<br />
            openCoopDoor();                       // Open the door<br />
          }<br />
        }<br />
      }<br />
    }</p>
<p>// ************************************** the loop **************************************<br />
void loop() {<br />
  //  polling occurs<br />
  coopTimer.run();<br />
  doCoopDoor();</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
