boyoh
Posts: 1175
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: Automated light controlled door, motors and limit switches

Wed Jan 24, 2018 11:06 am

You are getting good advice on this project from PCMANBOB , Each time you said you have
tried that. Yes you have tried it because he as just told what to do, This is not being fair withe him
If you are waiting for some one to draw a compleat circuit for you , this will never happen
You can talk about it and wright about it . But not able to put it in to practice.

Regards BoyOh
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

PingoBags
Posts: 47
Joined: Mon Nov 06, 2017 10:53 pm
Location: NS, Canada

Re: Automated light controlled door, motors and limit switches

Wed Jan 24, 2018 12:38 pm

N_Aguiar wrote:
Tue Jan 23, 2018 11:54 pm
I have kind of thought about that and the door is basically a thin piece of wood that's not all that heavy. When it is built i will have to stick my arm in there and see how heavy it really is and how the whole thing would react. If it turns out to be heavy i would have to figure out some kind of ir setup such as a garage door would have.

Do you have anything in mind to address that? All input is greatly appreciated here.
You want a heavy strong door. The chickens are more likely to get killed by a predator then the door.
A thin light door won't protect them.

I still think your best solution is to use sunset times, rather than the light sensor.
Have the door close just after sunset. All the chickens will be roosting, no chance of getting caught in the door or getting locked outside.

An IR sensor in theory is a good idea but not with chickens.
Do you have your chickens yet, or are you getting set up first?
Mine are very dusty, everything gets dirty fast. I'm guessing the sensor will stop working after a day.

N_Aguiar
Posts: 46
Joined: Sat Jan 20, 2018 7:25 pm

Re: Automated light controlled door, motors and limit switches

Wed Jan 24, 2018 4:55 pm

I have the chickens already but they are getting a new coop built, and more added to the flock. This is all planning for their new home

N_Aguiar
Posts: 46
Joined: Sat Jan 20, 2018 7:25 pm

Re: Automated light controlled door, motors and limit switches

Wed Jan 24, 2018 5:01 pm

boyoh wrote:
Wed Jan 24, 2018 11:06 am
You are getting good advice on this project from PCMANBOB , Each time you said you have
tried that. Yes you have tried it because he as just told what to do, This is not being fair withe him
If you are waiting for some one to draw a compleat circuit for you , this will never happen
You can talk about it and wright about it . But not able to put it in to practice.

Regards BoyOh
I have provided wiring diagram, code and mechanical drawing so what exactly are you talking about?

And just incase pcmambob is unaware of how extremely grateful i am for the changes he has made to my code and advice given, thank you so much without you this project would still be stalled and i would still be banging my head on the keyboard

N_Aguiar
Posts: 46
Joined: Sat Jan 20, 2018 7:25 pm

Re: Automated light controlled door, motors and limit switches

Wed Jan 24, 2018 5:04 pm

As for the chicken blocking door situation i am thinking maybe some kind of bar that can slide up and make a contact like momentary switch of sorts, if the ir is not feasible

PingoBags
Posts: 47
Joined: Mon Nov 06, 2017 10:53 pm
Location: NS, Canada

Re: Automated light controlled door, motors and limit switches

Wed Jan 24, 2018 5:51 pm

I've seen some good videos on youtube for self locking coop doors, like this one for example.
Looks like a simple design and I'm sure it would stop most things from getting in.

I can't really think of a reliable way to check if there's a chicken in the doorway.
Sensors would work but as you already know, chickens create a lot of dust, which covers everything.
You could try one of those slow worm drive motors, they are cheap on ebay and amazon.
The door would close so slow, it would give the chickens time to move out of the way just in case it ever happens.

N_Aguiar
Posts: 46
Joined: Sat Jan 20, 2018 7:25 pm

Re: Automated light controlled door, motors and limit switches

Wed Jan 24, 2018 7:08 pm

if i decided to go the ir method, would the following code work of would i have to indent everything after the pass statement?

Code: Select all

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(7,GPIO.IN)   # ldr
GPIO.setup(11,GPIO.IN)  # top switch
GPIO.setup(12,GPIO.IN)  # bottom switch
GPIO.setup(15,GPIO.OUT)
GPIO.setup(13,GPIO.OUT)
GPIO.setup(22,GPIO.IN)

delay1 = .2  # time between checks when door moving for switch operation may need to be shorter 
delay2 = 1  # time between checks of LDR

try:
        while True:
                if GPIO.input(7) == True:
                        GPIO.output(13,False)
                        GPIO.output(15,False)
                        time.sleep(30)
                else:
                        pass
                while GPIO.input(7) == False:
                        if GPIO.input(11) == False:
                                print ("Day")
                                print ("Opening door")
                                GPIO.output(15,True)
                                print ("drive motor")

                        elif GPIO.input(11) == True:
                                GPIO.output(15,False)
                                print ("STOP door is open")
                        time.sleep(delay1)        
                time.sleep(delay2)                        
        
        
                while GPIO.input(7) == True:
                        if GPIO.input(12) == False:
                                print ("Night")
                                print ("Closing door")
                                GPIO.output(13,True) 
                                print ("drive motor")

                        elif GPIO.input(12) == True:
                                GPIO.output(13,False)
                                print ("STOP door is closed")
                        time.sleep(delay1)       
                time.sleep(delay2)
finally:
        GPIO.cleanup()
        

pcmanbob
Posts: 4461
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Automated light controlled door, motors and limit switches

Wed Jan 24, 2018 7:50 pm

So looking at your code 4 things wrong with it.

Code: Select all

                if GPIO.input(7) == True:
                        GPIO.output(13,False)
                        GPIO.output(15,False)
                        time.sleep(30)
                        

1. you are checking the LDR sensor input you should be checking I guess gpio 22.

2. the else: statement is point less as it does nothing so why have you included it.

3. the code will only get run once at the start each time the main loop is run once you start closing the door you loop round the close loop until the door is closed so you will not run your new code

4. there is no point in using try: because you are not trapping any errors so your finally: code will never get run because you are running in a constant loop.
Remember we want information.......................no information no help
The use of crystal balls & mind reading is not supported

N_Aguiar
Posts: 46
Joined: Sat Jan 20, 2018 7:25 pm

Re: Automated light controlled door, motors and limit switches

Wed Jan 24, 2018 7:59 pm

Ok i see, i will work on it a little more and see what i come up with. The pin 22 would be the ir switch. I was thinking by putting that at the beginning it would check to see if the ir was tripped and if it was- kill all motor operation for 30 seconds if the ir switch (gpio 22) was no longer triped after the time.sleep (30) then resume normal operation with the pass statement. I havnt tested the code or anything, it was just something i thought of while pondering an ir setup. But thank you for pointing out the errors

pcmanbob
Posts: 4461
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Automated light controlled door, motors and limit switches

Wed Jan 24, 2018 8:09 pm

OK so removed your attempt and try/finally, added some more comments to identify parts of the code.

So we have this.

Code: Select all

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(7,GPIO.IN)   # ldr
GPIO.setup(11,GPIO.IN)  # top switch
GPIO.setup(12,GPIO.IN)  # bottom switch
GPIO.setup(22,GPIO.IN)  # IR sensor
GPIO.setup(15,GPIO.OUT)
GPIO.setup(13,GPIO.OUT)


delay1 = .2  # time between checks when door moving for switch operation may need to be shorter 
delay2 = 1  # time between checks of LDR (set to a reasonable number of mins ( 10-30 )to slow checking of LDR )


while True:
    # open door loop   
    while GPIO.input(7) == False:
            if GPIO.input(11) == False:
                    print ("Day")
                    print ("Opening door")
                    GPIO.output(15,True)
                    print ("drive motor")

            elif GPIO.input(11) == True:
                    GPIO.output(15,False)
                    print ("STOP door is open")
            time.sleep(delay1)        
    time.sleep(delay2)                        

    # close door loop
    while GPIO.input(7) == True:
            if GPIO.input(12) == False:
                    print ("Night")
                    print ("Closing door")
                    GPIO.output(13,True) 
                    print ("drive motor")

            elif GPIO.input(12) == True:
                    GPIO.output(13,False)
                    print ("STOP door is closed")
            time.sleep(delay1)       
    time.sleep(delay2)

now to stop the door closing which is all you need to do ( chicken cant be sat under door if its closed ! ) you only need this small bit of code

Code: Select all

# check IR sensor and stop door if obstructed.
while GPIO.input(22) == True:
    GPIO.output(13,False)
    print "E stop door blocked"
    time.sleep(2)
    
    
so it checks the IR sensor and if its obstructed it stops the motor until the IR sensor is clear.

now you workout were you need to put this :?: I will give you a clue its only need when you close the door. ;)
Remember we want information.......................no information no help
The use of crystal balls & mind reading is not supported

N_Aguiar
Posts: 46
Joined: Sat Jan 20, 2018 7:25 pm

Re: Automated light controlled door, motors and limit switches

Wed Jan 24, 2018 8:22 pm

Ok thank you ill se what i come up with after i do a little testing. I will use another push switch and resistors in place of the ir sensor.

To be clear, the way i had it wouldn't work because it would only check once in the beginning and then it would get stuck checking the ldr loop?

And was the try and finally a bad thing? I have heard that you should clean up gpios on exit of script and that was the only way i could think of doing it with my limited knowledge of python.

pcmanbob
Posts: 4461
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Automated light controlled door, motors and limit switches

Wed Jan 24, 2018 8:50 pm

To be clear, the way i had it wouldn't work because it would only check once in the beginning and then it would get stuck checking the ldr loop?
NO the way you had it it would not have been checked while the door was being closed it would have been check at the start of the main loop and only once.
And was the try and finally a bad thing? I have heard that you should clean up gpios on exit of script and that was the only way i could think of doing it with my limited knowledge of python.
Not so much a bad thing as point less you only clean up the gpio's on program exit , your program will never exit because it will run the main loop for ever, to get out of your program you need to ctrl-c and you were not trapping any errors anyway so finally would never have run.

now you could trap the ctrl-c key combination but no real advantage as you set up your gpio on program start anyway, and cleanup.gpio only resets the gpio to all inputs on exit, but if you restart you code without setting the gpio up again you gpio will just be set to what it was before you ran cleanup.gpio anyway.
Remember we want information.......................no information no help
The use of crystal balls & mind reading is not supported

N_Aguiar
Posts: 46
Joined: Sat Jan 20, 2018 7:25 pm

Re: Automated light controlled door, motors and limit switches

Wed Jan 24, 2018 10:00 pm

ok i think i see what you are saying. Thank you for all your help and here is how i inserted your piece of code and got it to work. Thanx again

Code: Select all

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(7,GPIO.IN)   # ldr
GPIO.setup(11,GPIO.IN)  # top switch
GPIO.setup(12,GPIO.IN)  # bottom switch
GPIO.setup(22,GPIO.IN)  # IR sensor
GPIO.setup(15,GPIO.OUT)
GPIO.setup(13,GPIO.OUT)


delay1 = .2  # time between checks when door moving for switch operation may need to be shorter 
delay2 = 1  # time between checks of LDR (set to a reasonable number of mins ( 10-30 )to slow checking of LDR )


while True:
    # open door loop   
    while GPIO.input(7) == False:
            if GPIO.input(11) == False:
                    print ("Day")
                    print ("Opening door")
                    GPIO.output(15,True)
                    print ("drive motor")

            elif GPIO.input(11) == True:
                    GPIO.output(15,False)
                    print ("STOP door is open")
            time.sleep(delay1)        
    time.sleep(delay2)
    
     
        
    # close door loop
    while GPIO.input(7) == True:       
                    
            if GPIO.input(12) == False:
                    print ("Night")
                    print ("Closing door")
                    # check IR sensor and stop door if obstructed.
                    while GPIO.input(22) == True:
                        GPIO.output(13,False)
                        print ("E stop door blocked")
                        time.sleep(2)                    
                    GPIO.output(13,True) 
                    print ("drive motor")

            elif GPIO.input(12) == True:
                    GPIO.output(13,False)
                    print ("STOP door is closed")
            time.sleep(delay1)       
    time.sleep(delay2)

N_Aguiar
Posts: 46
Joined: Sat Jan 20, 2018 7:25 pm

Re: Automated light controlled door, motors and limit switches

Thu Jan 25, 2018 1:20 am

Code: Select all

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(7,GPIO.IN)   # ldr
GPIO.setup(11,GPIO.IN)  # top switch
GPIO.setup(12,GPIO.IN)  # bottom switch
GPIO.setup(22,GPIO.IN)  # IR sensor
GPIO.setup(15,GPIO.OUT)
GPIO.setup(13,GPIO.OUT)


delay1 = .2  # time between checks when door moving for switch operation may need to be shorter 
delay2 = 1  # time between checks of LDR (set to a reasonable number of mins ( 10-30 )to slow checking of LDR )


while True:
    # open door loop   
    while GPIO.input(7) == False:
            if GPIO.input(11) == False:
                    print ("Day")
                    print ("Opening door")
                    GPIO.output(15,True)
                    print ("drive motor")

            elif GPIO.input(11) == True:
                    GPIO.output(15,False)
                    print ("STOP door is open")
            time.sleep(delay1)        
    time.sleep(delay2)
    
    # check IR sensor and stop door if obstructed.
    while GPIO.input(22) == True:
        GPIO.output(13,False)
        print ("E stop door blocked")
        time.sleep(2)    
        
    # close door loop
    while GPIO.input(7) == True:       
                    
            if GPIO.input(12) == False:
                    print ("Night")
                    print ("Closing door")
                    # check IR sensor and stop door if obstructed.
                    while GPIO.input(22) == True:
                        GPIO.output(13,False)
                        print ("E stop door blocked")
                        time.sleep(2)                    
                    GPIO.output(13,True) 
                    print ("drive motor")

            elif GPIO.input(12) == True:
                    GPIO.output(13,False)
                    print ("STOP door is closed")
            time.sleep(delay1)       
    time.sleep(delay2)
This is actually the code that worked, i notice i have it in 2 spots now. I will have to fix that

N_Aguiar
Posts: 46
Joined: Sat Jan 20, 2018 7:25 pm

Re: Automated light controlled door, motors and limit switches

Thu Jan 25, 2018 1:40 am

After some trial and error i have a code that works in every test. Is this the proper way to structure this? I will adjust the delays later.

Code: Select all

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(7,GPIO.IN)   # ldr
GPIO.setup(11,GPIO.IN)  # top switch
GPIO.setup(12,GPIO.IN)  # bottom switch
GPIO.setup(22,GPIO.IN)  # IR sensor
GPIO.setup(15,GPIO.OUT)
GPIO.setup(13,GPIO.OUT)


delay1 = .2  # time between checks when door moving for switch operation may need to be shorter 
delay2 = 1  # time between checks of LDR (set to a reasonable number of mins ( 10-30 )to slow checking of LDR )


while True:
    # open door loop   
    while GPIO.input(7) == False:
            if GPIO.input(11) == False:
                    print ("Day")
                    print ("Opening door")
                    GPIO.output(15,True)
                    print ("drive motor")

            elif GPIO.input(11) == True:
                    GPIO.output(15,False)
                    print ("STOP door is open")
            time.sleep(delay1)        
    time.sleep(delay2)    
        
    # close door loop
    while GPIO.input(7) == True:                     
            if GPIO.input(12) == False: 
                
                # check IR sensor and stop door if obstructed.
                while GPIO.input(22) == True:
                    GPIO.output(13,False)
                    print ("E Stop door is blocked")
                    time.sleep(5)                
                print ("Night")
                print ("Closing door")                                                       
                GPIO.output(13,True) 
                print ("drive motor")

            elif GPIO.input(12) == True:
                    GPIO.output(13,False)
                    print ("STOP door is closed")
            time.sleep(delay1)       
    time.sleep(delay2)

pcmanbob
Posts: 4461
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Automated light controlled door, motors and limit switches

Thu Jan 25, 2018 11:11 am

You got there in the end, while testing it I would have put the test of the IR sensor after the 2 print statements night & closing door just so you know were the loop has got to as you don't have any motor connected and you a relying on the print statements to see the code executing correctly , this wont matter one you have all the hardware connected.
Remember we want information.......................no information no help
The use of crystal balls & mind reading is not supported

N_Aguiar
Posts: 46
Joined: Sat Jan 20, 2018 7:25 pm

Re: Automated light controlled door, motors and limit switches

Thu Jan 25, 2018 12:34 pm

It prints everything as it did prior to the addition of your piece of code. Are you saying i should put the print statements "night" and "drive motor" above it but leave the stop door and door is closed under?

pcmanbob
Posts: 4461
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Automated light controlled door, motors and limit switches

Thu Jan 25, 2018 2:28 pm

if you are happy with the way it works then just leave it as it is , I was only expressing my thoughts not saying you were wrong.

but for clarity this is what I was suggesting

Code: Select all

    # close door loop
    while GPIO.input(7) == True:                     
            if GPIO.input(12) == False: 
                print ("Night")
                print ("Closing door")
                
                # check IR sensor and stop door if obstructed.
                while GPIO.input(22) == True:
                    GPIO.output(13,False)
                    print ("E Stop door is blocked")
                    time.sleep(5)                
                                                   
                GPIO.output(13,True) 
                print ("drive motor")
                
Remember we want information.......................no information no help
The use of crystal balls & mind reading is not supported

N_Aguiar
Posts: 46
Joined: Sat Jan 20, 2018 7:25 pm

Re: Automated light controlled door, motors and limit switches

Thu Jan 25, 2018 10:15 pm

it works both ways but i'll leave it the way you have it. I have changed the delay for the ldr and it brought up yet another question. I set it to check the ldr every 90 seconds as to try and test every scenario i could think of. Now the thing is that once it it starts to "Stop door closed" it just repeats that over and over forever until untill the status of the ldr changes like so:

Code: Select all

STOP door is closed
STOP door is closed
STOP door is closed
STOP door is closed
STOP door is closed
STOP door is closed
STOP door is closed
STOP door is closed
STOP door is closed
STOP door is closed
STOP door is closed
^CTraceback (most recent call last):
  File "testir.py", line 53, in <module>
    time.sleep(delay1)
KeyboardInterrupt
so my question is, is that ok for that to keep going on like that for hours at a time? is there a way to have anothe while statement like while door is closed/open sleep for however long?

I of course am going to try it out anyway lol but just lmk if i am just way and should leave well enough alone

pcmanbob
Posts: 4461
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Automated light controlled door, motors and limit switches

Thu Jan 25, 2018 10:24 pm

Yes it's ok to leave the code running in the loop.

You don't need to check the LDR that often, any change will be very slow as the light level drops or rises ( sun rise or sun set ) so could could check the LDR once every 15 min or may be even longer.
That would mean you code would only loop 4 times an hour.
Remember we want information.......................no information no help
The use of crystal balls & mind reading is not supported

N_Aguiar
Posts: 46
Joined: Sat Jan 20, 2018 7:25 pm

Re: Automated light controlled door, motors and limit switches

Thu Jan 25, 2018 10:41 pm

I was thinking every half an hour but the stop door is closed happening over and over again threw me off. Dont know why but i assumed it would print stop door closed once and then do nothing until the next ldr check. If its not broke dont fix it. Thanx for all the help😊

Dualxeon
Posts: 5
Joined: Thu Mar 08, 2018 8:20 am

Re: Automated light controlled door, motors and limit switches

Thu Mar 08, 2018 8:48 am

Good Morning, I'm new with the coding and the Pi, but I do have chickens and love the idea of the automated door. I have done a lot of googling there is a lot of info using the Arduino, not much with the Pi. Mr. N_Aguiar could you post or send me your complete setup, wiring diagram, parts used etc. (if this is allowed). I would love to copy what you have and build from there. I see a lot of people have commented and helped you make a lot of changes in coding and design. This is about the most complete info I have found so far.
Thanks Dualxeon

N_Aguiar
Posts: 46
Joined: Sat Jan 20, 2018 7:25 pm

Re: Automated light controlled door, motors and limit switches

Wed Oct 17, 2018 7:53 pm

I have been working out all of the bugs and finally have the project built and working. I will start getting a parts list put together and will upload the code and photos as soon as i have some time. I ended up doing away with the light sensor because on nights when there is a really bright moon or on days it was over cast and dark, the door would open/close when it wasnt supposed to. So i ended up just writing an open and a close script.

N_Aguiar
Posts: 46
Joined: Sat Jan 20, 2018 7:25 pm

Re: Automated light controlled door, motors and limit switches

Wed Oct 24, 2018 10:01 pm

OK, i will start off with some pictures of the finished product because that;s what i have handy. I will upload more of the technical pictures tonight...

Almost everything was purchased on ebay


Finished Door Link - https://photos.app.goo.gl/EppXnn6qTmoTQGgD9

N_Aguiar
Posts: 46
Joined: Sat Jan 20, 2018 7:25 pm

Re: Automated light controlled door, motors and limit switches

Wed Oct 24, 2018 11:41 pm

Here are Some Detail Photos with Labels and a video showing the locking mechanism working. I will get started on a parts list

https://photos.app.goo.gl/1ZpUaDLQNqt1WQb89
Last edited by N_Aguiar on Thu Oct 25, 2018 1:48 am, edited 1 time in total.

Return to “Beginners”