Troubleshooting Chicken Coop Automation

Hello all. As an avid Arduino user for 4 years now, I have used this forum extensively to learn and troubleshoot my codes; so I want to say thanks to everyone who helps out on here. This is my first post.

I have a chicken coop that I have instrumented with an automatic feeder, waterer, lights, and door that is powered via a 12V battery and solar panel. Arduino components include
Arduino Mega,
2 voltage regulators stepping down from 12V to 7V (arduino) and 5V(externals),
DS18B20 temp sensor,
2 12v lights and relays,
L298N motor driver and 12v gearmotor,
SD module,
20x4 IIC LCD screen.

I’ve been stacking things on gradually successfully over the last 5 months and recently ran into an issue after trying to run millis() timers for the lights and door motor simultaneously. The door and lights functions are written identically with the exception of an additional timer on the door function for the motor.

The automatic door worked fine by itself, then I added the lights and things seemed to quit working properly. I first noticed something was wrong when I uploaded the code and the automatic lights function worked, but the automatic door only closed after the “startinterval” then quit functioning and never opened or closed again.

I’m interested to see if anyone can find a fault in my code. I had some switches on the system for manual control that started acting erratically, so I removed them, but found there is nothing wrong with the switches themselves. This makes me think I may have a hardware issue somewhere on the Arduino board (or an issure with the IDE?). I have checked all the wiring and external hardware individually.

I am suspect of this part of the SD card intialization

boolean running = false;

I’m not sure that the SD card function needs this, but it’s been in there for months with no issues. I’m assuming there is something in the SD library that requires this. I’m just suspect that it is interfering with my volatile bool true/false statements for the AUTODOOR and AUTOLIGHTS functions.

Earlier today I combed through the code and spot checked all the hardware and wiring. I uploaded the attached code which should have closed the door and began the automatic door timer after 10 seconds (the “startinterval”), but it never executed the AUTODOOR function at all as the door did not close and the status of the door (open/closed) never changed on the LCD screen. The AUTOLIGHTS function executed when I set the start timer for it to 10 seconds.

I’ve troubleshooted (troubleshot?) many things in the last few years but I’ve been reading for hours now with no definite answers. I’m thinking maybe I’m misusing one of my variable types or functions.

I suppose the simple answer would be to purchase a GPS or RTC module and use the actual time from that to control the door and lights, but this format has worked for me thus far on my aquaponics system and chicken coop, so I want to troubleshoot this if possible before I go the GPS/RTC route.

Thanks in advance.
(Seems the code is too long to include so it is attached)

poultry3-16-21.ino (9.41 KB)

Can we assume ALL you wiring is either soldered or using screw terminals for ALL connections?

Yes! solder, screw terminals, and bullet connectors. Double checked all externals and wires

Yes! solder, screw terminals, and bullet connectors. Double checked all externals and wires

Then it is time for you to begin to trace the logic of your program. Don’t rely on others to test your logic. Use the serial print capability to follow the logic and see where it fails and why.

I would def put the serial print around and within the 2 parts of the logic you combined to see what it may be. Also check variable names are not being overwritten, if by chance you have the same names within the 2 portions you combined.

As noted, Serial prints will tell you the story.

This doesn't look good though:

      doorpreviousMillis = doorcurrentMillis;
      if (!dooropen)
        unsigned long doorcurrentMillis = millis();
        if (doorcurrentMillis - doorpreviousMillis >= downinterval)

You're sharing doorpreviousMillis between the when to move the door function and how long it takes to move it.

In that part you've set previous to millis and then you test to see if they differ by 6000. Obviously they never will.

Either set previous later in the code, or better, use separate variables.

Thanks for the input. Using the same variable has worked thus far but I thought maybe I was abusing it a bit. Tonight I will make more separate variables and add some more serial.print/lcd.print to ID the section that is going awry.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.