Hen House Autodoor problem

Hi all. I found this sketch on a website and have been using it to open and close my hen house door. It is working fine but I would like to add an override switch to open the door when its dark for when the hens forget to go in, and also to keep the door closed when its light etc.
I am a complete newbie with the Arduino and have been trying to add/modify the code to do this but with no success.
Can someone please help me.
I have attached the sketch.
Regards Ron.

New_chickendoor.ino (9.65 KB)

If you need to sense light, you need, for example, a LDR. Then, using an analog input you can read the "level of light". It may be some shields with LDR's assembled to be more simple to someone that don't have experience in electronics. What do you have do already?

If you want to be able to override the controller to make the door open or close, I think you need a three position switch (open/auto/close). There is already some code to initialise overrideSwitchPin but no code to read it or do anything with the result - in any case a single digital input won't give you the three states. I suggest you look for a three position switch and then connect it either to two digital pins, or an analog pin.

Once you have the hardware sorted you will need to modify doCoopDoor() to consider the override switch before checking the light level.

By the way, storing the light level as an ascii character value is rather strange, and the logic in doCoopDoor to check the light level is largely redundant since your ascii value could never be equal to '3', '2' and '1' at the same time.

Thanks for the advice Peter That was me trying to add my bit of code that didn't work and I must have left the ref. to the override switch in. I have tried many ways to achieve what I want but will try to fathom it out, things don't come so easily now I'm older...

You only need 2 buttons. One to open it and one to close it. These buttons must bypass the LDR

I also need to bypass the 10 minute timer so the buttons will operate immediately. Regards Ron

BigRon: I have tried many ways to achieve what I want but will try to fathom it out

Suggest you sort out the physical switch first, because the details of that would affect the software needed to write to it. The simplest approach IMO would be to get a three position (SPDT) latching rocker switch and then connect it up so that the common terminal is connected to ground, and two terminals which were connected to it in the extreme positions were connected to digital pins. Then your sketch just needs to enable the internal pull-up for those two pins, and read them in doCoopDoor().

if(manual open is active)
    open door
else if(manual close is active)
    close door
    your original logic based on light levels goes here

Thanks Peter for pointing me in the right direction . Regards Ron.

@BigRon, please do not cross-post.