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
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,
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)