Connect with us

Chicken Coop Door Opener

Discussion in 'General Electronics Discussion' started by Supercap2F, Aug 5, 2014.

Scroll to continue with content
  1. Supercap2F

    Supercap2F

    550
    150
    Mar 22, 2014
    Hello Everyone! :)

    So recently, a friend of mine asked for me to help him build a automatic chicken coop door opener. What he wants to do is, have a garage door opener hooked up to his chicken coop door, so he can just push a button and the chicken door will open/close. He also wants a mechanism that briefly switches on a relay, went it gets dark/light. the relay will be hooked up on the garage door opener, just like the switch would be on your wall. So I designed this circuit for him:

    CDOCIRCUIT.jpg
    Some of the values remain blank, because I still don't know what the supply voltage will be (he will inform me later today or tomorrow). J1 is where the switch will be. So my questions are:
    1. Is there any improvements that I could make to this circuit? Like to make it simpler, cheeper, safer etc.
    2. What's the formula to calculate the on time of the 74HC221?
    3. I hate to say it, but I still don't know how to calculate the wattage of resistors. Can someone enlighten me with a formula?

    Thanks for your time! :)
    Dan
     
  2. Arouse1973

    Arouse1973 Adam

    5,164
    1,081
    Dec 18, 2013
    Hi Dan Looks good. Couple of things.

    1) What's the purpose of the second mono stable? is it to open the door again when it's light enough in the morning? I am guessing the controller for the door takes a signal of the same polarity for both close and open. See it once for close and see it again for open. Your Op-amp shows no power connections, this implies +/-15V operation. Add some power leads if this is not the case. Put the resistor the other side of LED D4 and D5, it's safer that way.

    Pull down resistor on relay transistor Q1 and you know what value that should be don't you :). I assume you will be using a voltage regulator or a PSU of some kind to ensure consistent operation of the circuit. You could do with some bulk support capacitance also, my preference is 1uF-10uF for each IC connected across the power pins and a 0.001uF-0.1uF ceramic for each IC. I see you have some 0.1uF on your diagram.

    The ranges for capacitors I use depend on the technology, 0.1uF has been used for decades but it's no good for very fast switching circuits which in some cases 33pF is used. The 0.1uF is as old as TTL technology which is what is was used for and everyone's carried on since.

    2) I think it's 0.7*Cext*Rext from the data sheet. But I have never used these devices before.

    3) Power: If you know the current through the resistor then you square this and multiply by the resistance. If you know the voltage across the resistor then you square this and divide by the resistance. If you know the voltage and current and not resistor value you just multiply the current by the voltage.

    Cheers
    Adam
     
    Supercap2F likes this.
  3. Supercap2F

    Supercap2F

    550
    150
    Mar 22, 2014
    Wow, that's great Adam!:)

    Yes, U2.1 is hooked up to trigger on the low to high transition of the op-amp, U2.2 is the high to low transition.

    Yes, that's how it works. :)

    That's the only thing I don't like about Diptrace, the power connection for op-amps are shone as a little box to the side. :confused:

    OK, cool! I never knew that.:)

    So put a 1-10uF capacitor in parallel with the 0.1uF ceramic ones on the ICs?

    OK, let me see if I can get this:

    R1 and R2 are 10K resistors. Assuming the voltage is 5VDC, the max current would be: 5/10,000= 0.5mA So the wattage would be: 0.0005*0.0005*10,000=2.5mW Would that be right?

    Thanks for the help Adam!!:)
    Dan
     
  4. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,270
    Nov 28, 2011
    The system won't be reliable unless it knows the state of the door. If your friend presses his remote control button during daylight hours to close the door, when darkness falls, the automatically generated pulse will open it, and it will be in the opposite of the expected state until another event comes along. That is only one example of how the door state could become the opposite of the intended state.

    The door state can be detected using one or both of the limit switches that tell the garage door opener when the door has reached its fully open or fully closed limit, so that it can stop the motor. These limit switches may be attached to the door, or they may be inside the door opener's case. If the opener doesn't use limit switches, you may need to install one or two.

    Since the required actions aren't urgent, commands can be delayed for at least long enough for the door to reach one limit when it was previously at the other limit. So you don't need immediate feedback. So you could work with just one limit switch - either fully open, or fully closed.

    You haven't defined how you want the manual operation to interact with the light-controlled operation. I imagine you would want something like this: Whenever the manual control button is pressed, the circuit should stop controlling the door until the next change from night to day or day to night. This can be done quite simply as long as the logic is properly thought through.

    Do you want the circuit to retry after a while if the door is not in the expected position? If so, do you want it to give up and stop retrying after a certain number of attempts?

    Is the manual control simply done with a hard-wired pushbutton as shown on your diagram?

    Your daylight comparator needs hysteresis - and probably quite a lot of it, or a time-based lockout. That's because the detected light level will vary from second to second and minute to minute, and if you have a fixed threshold, as the average light level gets close to it, those small variations will cause it to cross the threshold multiple times. This will cause the door to open and close many times during the time that the detected light level is crossing the threshold.

    Your monostables can be replaced with various simpler circuits.

    If you answer those questions, I'll draw up a suggested circuit.
     
    Supercap2F likes this.
  5. Supercap2F

    Supercap2F

    550
    150
    Mar 22, 2014
    Great points you raised, Kris! :) All right I will try to answer your questions.:)

    Yes, that would work good.

    First let me tell you that the limit switches are in the garage door opener. It's a old analog garage door opener, so it is really little switches inside of the case. The light sensor will not know when the door is down/up, all it does is switch a relay on and then off. The relay will be hooked up where the push button, that is normally how you would open you door, would be. So to answer your question, no it would not retry because it assumes that the door went down OK. Hope that made since!:)

    Yes, thats the plan.

    You don't have to go to all that work if you don't want to. I think I could make something that would get the job done. But if you do want to go to that much trouble, then I would be very grateful. :)

    Some more stuff you should know: He is going to tell me what supply voltage it should work off of tonight (right now where I am, it's 10:26 AM). If you want to make it use microcontrollers then I have some PICAXEs. If you have never used them, then tell me what it would need to do and I think I could cook up some code. I can't do PICs. because I still don't have a PICKIT, or any PICs at that! If you wanted to make it work off of discreet logic, that would be fine.

    Thanks so much for your time!!!!!:D
    Dan
     
  6. Arouse1973

    Arouse1973 Adam

    5,164
    1,081
    Dec 18, 2013
    I was just going to say I forgot Hysteresis I thought about it but then forgot. Good point about the switches though. :)
    Adam
     
  7. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,270
    Nov 28, 2011
    I should have mentioned using a microcontroller. This is a really obvious case where a microcontroller could hugely simplify the hardware required, improve the behaviour, and provide opportunities for improvement.

    A little 8-pin device would be plenty. A PIC12F675 for example. The I/O could be:
    • 1x analogue input driven from a voltage divider formed by the LDR and a trimpot; the trimpot would be used to adjust the brightness threshold. Firmware would provide a timed lock-out so hysteresis wouldn't be needed. When the input passes the half-supply-voltage threshold, this would be actioned and changes would be ignored for several hours.
    • 1x digital input driven from a limit switch. Doesn't matter which limit switch you use. So firmware can detect the door state and make sure it's as expected. Firmware would need to wait a little while after commanding the door to move towards the limit that you are monitoring, because the state of that limit switch won't change until the door reaches the end of its travel.
    • 1x digital input for the manual control pushbutton.
    • 1x digital output to the garage door opener.
    • 1x optional digital output to drive a LED to display the ADC comparison result for the LDR, to simplify adjustment of the light threshold trimpot.
    The last two outputs could be the ICSP data and clock signals. The internal clock would be plenty accurate enough. This leaves one spare pin on the PIC12F675.
     
  8. Supercap2F

    Supercap2F

    550
    150
    Mar 22, 2014
    I can't use a PIC though. I don't have a PICKIT or any PICs.:confused: How about I redraw the circuit to use a PICAXE, write up some code, and have you guys aprove it. Unless you can think of something better, I think that's what I will do.

    Thanks Kris!:)
    Dan
     
  9. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,270
    Nov 28, 2011
    Yes, go for it.
     
  10. Supercap2F

    Supercap2F

    550
    150
    Mar 22, 2014
    All right, here's what I came up with:

    CCCDO.jpg

    And here's the code:

    Code:
    ;***************************************************************;
    ;* This program assumes that the door is up when it is started *;
    ;***************************************************************;
    
    main:
        readadc c.2,b0
        if b0<128 then
            do
            pause 1000
            inc b1
            loop until b1=10
            let b1=0
            let b0=0
            readadc c.2,b0
                if b0<128 then
                    high c.4
                    pause 2000
                    low c.4
                    let b0=0
                    goto main2
                endif
        endif
        if pinc.3=1 then
            high c.4
            pause 2000
            low c.4
            goto main2
        endif
        goto main
    main2:   
        readadc c.2,b0
        if b0>128 then
            do
            pause 1000
            inc b1
            loop until b1=10
            let b1=0
            let b0=0
            readadc c.2,b0
                if b0>128 then
                    high c.4
                    pause 2000
                    low c.4
                    let b0=0
                    goto main
                endif
        endif
        if pinc.3=1 then
            high c.4
            pause 2000
            low c.4
            goto main
        endif
        goto main2
    
    Sorry about the schematic being all over the place. See anything that could stand improving?

    Thanks
    Dan
     
  11. Arouse1973

    Arouse1973 Adam

    5,164
    1,081
    Dec 18, 2013
    Dan that looks very good well done. One question, when it is dark you are only going to get half supply max on the port pin, is this ok? I guess your using the A to D? I can't really comment on the code, I'll leave that for Kris. One other thing I noticed is the switch is a low to high active, it's better practice to go from high to low. So 10K pull up and switch to 0V, but it's up to you. Not sure about what serial in out is doing so I can't comment.
    Thanks
    Adam
     
    Supercap2F likes this.
  12. Supercap2F

    Supercap2F

    550
    150
    Mar 22, 2014
    Hey Adam!:)

    Yes I planed for that. But now that you bring it up, I don't know if it's such a good idea. I have the trigger level set to about half of the supply voltage. Once it triggers it waits 10 seconds and then makes sure it's still lower then half the supply. Do you think that would be OK?

    Yes I'm using the 'read ADC' function.

    Really? I have never heard that before. Would you mind explaining why that is?:)

    It's just the way to program the PICAXE.

    Thanks for the help!!:D
    Dan
     
  13. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,270
    Nov 28, 2011
    Yeah the schematic looks good.

    Re the pushbutton input being active low instead of active high, there's no technical reason for it. Doing it that way is slightly more common; the only reasons I can think of is having 0V on the pushbutton is a bit more convenient - you may be able to avoid an extra pin on your I/O connector - and a bit safer - if either side of the pushbutton shorts to earth, you won't short out your power supply.

    Personally I would put the LDR at the 0V side of the voltage divider (put the trimpot from the I/O pin to VCC) for the same reasons.

    It's a good idea to put a small capacitor (e.g. 0.1 µF film e.g. http://www.digikey.com/product-detail/en/R82DC3100AA50J/399-5863-ND/2571298) from the ADC input pin to 0V. This reduces the impedance of the driving signal and helps you get cleaner ADC conversions.

    As for the code, you will need a much longer lockout period than 10 seconds to avoid witter around the night/day decision threshold - at least an hour. The delay needs to be long enough that second-to-second and minute-to-minute variations in ambient light - due to cloud movement, for example - don't cause the LDR voltage to cross back over the threshold.

    I would implement that with a separate timer; can you do that with PICaxe? When you detect a change in the light/dark result from comparing the ADC value, act on it, and start the timer. While the timer is active, ignore any other changes in the result of that comparison. Or just skip the whole conversion and comparison.

    I haven't checked the rest of the logic. I think a bit of experimentation will be needed when you have the hardware ready.
     
    Supercap2F likes this.
  14. Supercap2F

    Supercap2F

    550
    150
    Mar 22, 2014
    OK, that makes since.

    OK, will do. :)

    Well the thing about having such a long delay is, for that one hour, when the door is not shut, the chickens are at risk of being eaten. The whole idea of this project is to protect his chickens. Do you think that that would be a issue?

    I doubt it. That's why I'm switching to PICs. The best I could do is something like this:

    Code:
     
    do 
    pause 1000             
    inc w0
    loop until w0=1000
    let w0=0 
    do 
    pause 1000
    inc w0
    loop until w0=1000
    let w0=0 
    do 
    pause 1000
    inc w0
    loop until w0=1000
    let w0=0 
    do 
    pause 1000
    inc w0
    loop until w0=500
    let w0=0 
    
    That would do nothing for about 58 minutes. Or what I could do, is have it read the ADC, and if it says that it's dark, then wait 10 seconds. If it still says that it's dark, after the 10 seconds, then close the door. Then wait 58 minutes, read the ADC again, and if it still says that it's dark, then have it switch over to waiting for it to be light (if it does not say that it's still dark, then have it open the door). And when it's light have it repeat the cycle. Do you think that would work?

    Thanks for all the time you guys have put into this!!:)
    Dan
     
  15. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,270
    Nov 28, 2011
    The delay doesn't delay the closing or opening of the door.

    Think about what happens in the evening. As it gets darker, the ADC voltage increases (assuming the LDR is at the bottom of the voltage divider, as I suggested). So the value you read from the ADC represents "darkness", if you like.

    At a certain time, the "darkness" value reaches half scale (128, assuming an 8-bit conversion). This is your signal that it's dark, and the door needs to be closed. So you do that - generate a command to close the door. No delay there.

    But now, if you keep monitoring the ADC and waiting for sunrise, what happens if a cloud moves and the sun shines through again? The darkness value will drop below 128 and your program will think it's morning again, and it will open the doors. This is what we have to avoid.

    One way to avoid this problem is with hysteresis. With this method, you move the threshold according to the current state. For example, if it's currently daytime, darkness has to go over, say, 160 before you regard it as nighttime. But once you've detected that condition, and decided that it's nighttime, darkness has to go under, say, 96 before you regard it as daytime again.

    You choose the amount of hysteresis so that it's greater than the short-term variation due to clouds and other factors. That's fine, but it means that the nightfall and sunrise brightness thresholds are quite a long way apart.

    If you have the benefit of a microcontroller that can perform timing, you can just lock out detection of a change for a certain amount of time (I suggest 4 hours) after a change has been detected and acted on.

    So when the darkness value reaches 128 and you decide it's nightfall, you close the door, then you ignore the values you read from the ADC for four hours. If a cloud moves away and the darkness value drops below 128, it doesn't matter, because you're ignoring the ADC conversions.

    Four hours after nightfall, when you start reading the ADC again, the darkness value is going to be quite high, and small variations in darkness won't bring it below 128. It will only go below 128 at sunrise.

    This will work well in practice but it makes it hard to adjust the threshold. That's why I suggested a separate output that shows the raw result of the comparison of the raw ADC value. Then you just wait until it's about the right brightness outside to be considered nighttime, and adjust the trimpot until the LED just changes state.

    As for implementing the timer, I expect the PICaxe can do it. You need a "background process" that is executed periodically (for this case, once per second is plenty fast enough) and decrements a 16-bit "time counter" variable unless that variable is already zero. Then when you read the ADC and compare the result against the fixed threshold of 128, you check the "time counter" variable; if it's not zero, you ignore the comparison result. If it is zero, and the comparison result is different from the current day/night status, you update the status, send a pulse to the door opener, and set the "time counter" variable to the number of seconds in four hours.
     
    Supercap2F likes this.
  16. Arouse1973

    Arouse1973 Adam

    5,164
    1,081
    Dec 18, 2013
    Hey Kris, there is a good technical reason for using active low and that is false triggering. An EMI event is more likely to induce a positive spike than a negative spike. This is the reason that reset lines and chip select lines are active low. I know it can be factored out in software but you might not always be able to do this. If you have a the long cable with a switch on the end this is more prone to this sort of event because of the length of cable.
    Thanks
    Adam
     
    Supercap2F likes this.
  17. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,270
    Nov 28, 2011
    Where do you get that from? Reference please.
    No it isn't!
     
  18. Arouse1973

    Arouse1973 Adam

    5,164
    1,081
    Dec 18, 2013
    A lecturer of mine who used to work for IBM once told me that about the chip select and reset lines. But I will have a dig about and see if I can find something. Unfortunately I don't have a reference for everything I know, whether right or wrong. :) It makes perfect sense to me about the majority of spikes being more positive if you think about a very common event of high power load switching and the inductance of the PCB traces or cables. But I'll see if I can do some calculations.
    Cheers
    Adam
     
  19. Arouse1973

    Arouse1973 Adam

    5,164
    1,081
    Dec 18, 2013
    Found something in the Art of Electronics that explains what I mean.

    TTL chips (and their HC and AC counterparts)tend to be designed with active LOW control inputs; for instance, flip-flops generally have SET and RESET inputs that are enabled when LOW.

    External digital signals used as inputs will therefore nearly always have a pull-up resistor and will pull LOW (sinking current) when active, a convenient arrangement, because switches, etc., can use a common ground return. It also leads to greater noise immunity, since a line held near +5 volts has 3 volts of noise immunity, as compared with the 0.8 volt of noise immunity of a line held near ground.

    This intrinsic weakness of TTL logic (poor noise immunity in the LOW state) is particularly apparent when you realize that a negative 0.5 volt spike on the chip's ground line can be interpreted as a HIGH input by the chip. Such spikes are not uncommon, since they can be generated by short current spikes through the ground-line inductance.

    Cheers
    Adam
     
    Supercap2F likes this.
  20. Supercap2F

    Supercap2F

    550
    150
    Mar 22, 2014
    All right here's the updated schematic:
    CCCDO2.jpg

    I tried to clean it up a bit, but it's still all over the place. :confused: I will clean it up somemore later.

    OK, I see your point quite well. I'm going to have the darkness level set so low, that the only way it could trigger in the day, is if there's an eclipse. And if it does false trigger, then he can just push the switch to open it.

    OK, that's a very good idea. I updated the schematic for that.

    I don't get what your saying. :confused: Could you draw up a text diagram? Something like this: Do this -> now do this-> do this now-> and this-> etc.

    Thanks again!:)
    Dan
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-