Shop OBEX P1 Docs P2 Docs Learn Events
newbie FIRST project- automatic chicken door — Parallax Forums

newbie FIRST project- automatic chicken door

danharrdanharr Posts: 10
edited 2010-05-18 14:25 in BASIC Stamp
I bought a bunch of stuff from Parallax but somehow never managed to find a use for it, until now...

My wife got some chicks, I made a nice house for them in the backyard. I decided to make an automatic door opener/closer, using a Firgelli automations linear actuator. The idea is to close the chicken coop door at night to protect the birds from predators (EVERYBODY likes chicken!), and open it again at dawn hopefully long before I wake up. I wrote the following code, and while it didn't work last night (I think I set the light sensor to be too insensitive to light), I'm hoping it will work tonight. I'm confused about "goto" vs "gosub" and I'm wondering if my use of these commands makes sense.

I also want to add a "chicken squeezer" routine using the Ping- so the girls don't get squished by the door as it closes. Is the Ping the way to go here, or should I use an IR emitter/receiver pair like they had in stores to let the proprietors know when somebody came in the door? I want to make sure that the door stays open if a chicken is in the way.

I can/will add some long pauses to wait for 30-40 minutes after dark before the door closes. Shorter pauses are in there now. The birds know to go inside when it gets dark, but I want to be sure all three are in there before the door shuts. I figure foxes and raccoons won't come around until midnight -3am.

Any suggestions would be appreciated- this is my first project, probably full of issues...

' {$STAMP BS2}
' {$PBASIC 2.5}
time VAR Word 'this sets rc time variable
morn VAR Nib 'morning counter so it only runs morning routine once per day
evening VAR Nib 'evening counter same reason
DO
HIGH 5
PAUSE 100
RCTIME 5, 1, time 'sets up photo resistor and capacitor on pin 5 for light sensing
DEBUG CLS, HOME, ? time, " " ' shows rc time- higher number = lower light
IF time > 200 THEN GOSUB night
IF time < 200 THEN GOSUB morning
LOOP

night:
DEBUG "night", CR
IF evening>0 THEN GOTO rest ' if evening counter has already run once- don't run again
PAUSE 10000
DEBUG "warning... CLOSING", CR
HIGH 1 'closes relay shuts chicken coop door
PAUSE 10000
LOW 1 'turns off relay -door is shut
evening=evening+1 'prevents running more than once a day
morn=0 'resets morning counter so it can run
RETURN

morning:
DEBUG "day", CR
IF morn>0 THEN GOTO rest 'morning counter has run- don't run again
PAUSE 2000
HIGH 2 'open door
PAUSE 10000 'relay stays on while door opens
LOW 2 'stops relay -door is open
morn = morn +1 'sets counter so sequence runs just once a day
evening=0 'resets night relay counter for night sequence
RETURN

rest: 'want to use a low current resting cycle for an hour or so at a time
DEBUG "resting", CR
PAUSE 10000
PAUSE 10000
RETURN

Comments

  • W9GFOW9GFO Posts: 4,010
    edited 2010-05-10 22:39
    Interesting project. I have something similar in mind but for cats.

    When you use a GOSUB, the subroutine will have a "RETURN" at the end of it which tells it to come back to the code which called it. In other words, do that, then come back here to continue with the code.

    GOTO means to go do that, and don't come back. Not sure what happens to the "RETURN" statement when you use a GOTO. If I use a GOTO, the routine which it calls may have another GOTO at then end of it to tell it where to go when it is done, not a "RETURN".

    Rich H

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Simple Servo Tester, a kit from Gadget Gangster.
  • ercoerco Posts: 20,256
    edited 2010-05-10 23:00
    I·got·3 Easter chicks last year, lots of fun raising them first inside the house, living in a plastic storage tub, then in a coop I·built out back. Turned·out to be RI Reds, one rooster & two hens.·I had some plans to automate the coop & feeding/water delivery, but the city came by and made me get rid of 'em at 4 months. They started laying eggs·the week after·after I gave them to a farmer!

    http://www.youtube.com/watch?v=nuqlXCa03g0
    http://www.youtube.com/watch?v=ofvi2Ls-fzk

    Don't underestimate the strength & abilities of· raccoons & skunks. Wiley critters! Built a good locking mechanism.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2010-05-11 00:54
    Rule # 1· Always write you code not hurt any human or chicken or the like
    Rule # 2· Always Check to see if you can make it fail if you can not make it fail then you are OK

    ·You could use an Optic sensor pair and you which way the chicken are going in or out how ever

    ·I will have to try to see how far apart you can have them and they ·still work


    It·would also help if you an few switches to let you know if your door is open or closed could be very important to know

    You could ·write your code in such a way that if the door is close or open then it would just loop and wait until the state changed from light to dark or dark to light

    As far as the 30-40 minutes after dark before the door closes

    I would do something like this

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}


    night··············· · VAR··· ·Word
    time················· ·VAR···· Word

    closed_switch···· ·VAR··· ·IN0
    open_switch······ ·VAR··· ·IN3


    DO

    FOR night = 0 TO 365·············· ' The Value of 365 can be changed to get the time that you want

    NEXT

    IF time > 200 THEN··············· ·' Do not be temped to put this like IF time > 200· AND· IN0 = 0 may not work the way you want it to work
    IF closed_switch·= 0 THEN·······'·This would your switch for door closed ·

    ···
    PAUSE 500
    ELSE

    IF night = 364 THEN··············· ' The value need to be one less than in the FOR· value
    HIGH 2

    ENDIF
    ENDIF

    ENDIF

    LOOP





    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·Now wanting to learn Spin· Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 5/11/2010 1:02:33 AM GMT
  • danharrdanharr Posts: 10
    edited 2010-05-11 01:24
    Hi
    They are great pets- we hope to get eggs from them in the late summer...


    Thanks, Sam for the tips- I don't understand them, but I'm going to take out my syntax manual and study them! Does the "night" variable use up time just as a for/next loop, running 365 times until it ends the loop? I'm going to try to figure it out...
  • danharrdanharr Posts: 10
    edited 2010-05-11 02:01
    thanks too, Rich- I missed seeing your post before. Seems like people prefer "gosub", but I might try some goto's to make sure my code comes back to check ambient light...
  • ercoerco Posts: 20,256
    edited 2010-05-11 02:24
    If you've ever read my favorite book from childhood, "Andy Buckram's Tin Men" (yes, I've been a robot freak my whole life), inventive young Andy lives on a farm and makes everything automated. He makes the chicken coop door spring-loaded so that it automatically opens & closes. It is adjusted to close exactly from the combined weight of all the chickens on the roost.

    Later in the story, he builds 4 different robots from tin cans, all with different functions. Magical things happen when they all get hit by lightning...

    And just like the Professor on Gilligan's Island, Andy the mechanical genius never quite fixes the boat...

    A great read for your youngsters or you! By Carol Ryrie Brink, ~1966. Occasionally on Ebay for $20-30.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2010-05-11 02:46
    I don't understand them, but I'm going to take out my syntax manual and study them! Does the "night" variable use up time just as a for/next loop, running 365 times until it ends the loop? I'm going to try to figure it out...

    night:

    DO

    FOR night = 0 TO 365·············· ' The Value of 365 can be changed to get the time that you want

    NEXT

    IF time > 200 THEN··············· ·' Do not be temped to put this like IF time > 200· AND· IN0 = 0 may not work the way you want it to work
    IF closed_switch·= 0 THEN·······'·This would your switch for door closed ·

    ···
    PAUSE 500
    ELSE

    This routine look at [noparse][[/noparse]time] and if·it·= (Dark) and then looks at·[noparse][[/noparse]closed_switch] and if it·= (Open) and both are TRUE THEN runs PAUSE 500



    IF night = 364 THEN··············· ' The value need to be one less than in the FOR· value

    Once the value reaches 364 THEN it runs HIGH 1 which then would close your door

    HIGH 1

    ____________________________________________________________________________________________________________________
    ·I can/will add some long pauses to wait for 30-40 minutes after dark before the door closes

    One Note It is not a good· idea.gif·to use a PAUSE command for that long· because your doing nothing but pausing
    With the routine above you are looking·about every 1·/2 second at your photo cell to see if there is a change or not ( or ) or ·(and )·could count the amout of chicken that have come in the coop

    This is·what I would use for what you want to do what have above
    ____________________________________________________________________________________________________________________
    night:
    DEBUG "night", CR
    IF evening>0 THEN GOTO rest ' if evening counter has already run once- don't run again
    PAUSE 10000
    DEBUG "warning... CLOSING", CR
    HIGH 1 'closes relay shuts chicken coop door
    PAUSE 10000
    LOW 1 'turns off relay -door is shut
    evening=evening+1 'prevents running more than once a day
    morn=0 'resets morning counter so it can run
    RETURN
    __________________________________________________________________________________________________________________

    I hope this helps




    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·Now wanting to learn Spin· Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 5/11/2010 3:05:49 AM GMT
  • W9GFOW9GFO Posts: 4,010
    edited 2010-05-11 05:26
    Here is another approach...

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    trigger   CON   200
    
    workVal   VAR  Word     ' temporary, reuseable variable
    time      VAR  Word     ' this sets rc time variable
    i         VAR  Byte     ' index variable
    
    DoorState VAR   Bit     ' 1 = open, 0 = closed
    
    Main:
    
      GOSUB CheckLightSensor
      DEBUG CLS, HOME, ? time, " "     ' shows rc time- higher number = lower light
      IF time >= trigger THEN GOTO Night
      IF time < trigger THEN GOTO Morning
    
    Night:
      DEBUG "Night", CR
      IF DoorState = 0 THEN GOTO rest  ' if door is closed - don't run again
      DEBUG "Warning... CLOSING", CR
      GOTO Close
    
    Morning:
      DEBUG "Day", CR
      IF DoorState = 1 THEN GOTO rest   ' if door is open - don't run again
      GOTO Open
    
    CheckLightSensor:
      time = 0
      FOR i = 1 TO 10          ' average light sensor over 10 seconds
        HIGH 5
        PAUSE 100
        RCTIME 5, 1, workVal
        time = time + workVal
        PAUSE 900
      NEXT
      time = time/10
      RETURN
    
    Open:
      HIGH 2                 'open door
      PAUSE 10000            'relay stays on while door opens
      LOW 2                  'stops relay -door is open
      DoorState = 1
      GOTO Rest
    
    Close:
      HIGH 1                 'closes relay shuts chicken coop door
      PAUSE 10000
      LOW 1                  'turns off relay -door is shut
      DoorState = 0
      GOTO Rest
    
    Rest:                    ' Go into low power mode for one hour
      DEBUG "resting", CR
      FOR i = 1 TO 60
        SLEEP 60
      NEXT
      GOTO Main
    



    Rich H

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Simple Servo Tester, a kit from Gadget Gangster.

    Post Edited (W9GFO) : 5/11/2010 5:32:27 AM GMT
  • danharrdanharr Posts: 10
    edited 2010-05-11 13:33
    Thanks very much!
    This is great info- when I get home from work, I'm going to check these ideas out and report back... The door didn't close again last night, so I'm thinking my current setup still needs work. It works fine at my desk but not outside. I'm thinking the ambient outdoor light at night is higher than in the workshop.


    Even the book mentioned sounds good for my 3 1/2 year old- the combined weight of the chickens closing the door... hmmmm
    800 x 534 - 151K
    800 x 533 - 146K
    800 x 531 - 119K
  • MoskogMoskog Posts: 554
    edited 2010-05-11 16:07
    Sam's and W9GFO's code said...
    DEBUG "warning... CLOSING", CR
    Will the chicken understand and keep clear?
  • danharrdanharr Posts: 10
    edited 2010-05-12 11:54
    Everybody knows that chickens can't read!
    I hired my dog to read the monitor and bark out the warning to the chickens-
    You'd think this would be expensive, but my dog works for scratch...
  • danharrdanharr Posts: 10
    edited 2010-05-12 12:09
    Had some drama here last night... I finally tweaked the settings on my original program so it appeared to work outside. Unfortunately I had to work late and learned from the family that the door closed too soon and locked the birds outside. My mother in law put them inside through the back door, and then the door opened again, letting the birds back out! Then ir closed again, locking them out again. When I got home after dark, I found the door open, the chickens were asleep DIRECTLY IN THE PATH of the DOOR!!! At any second I imagined the door closing guillotine-like and squishing at least one bird http://forums.parallax.com/forums/emoticons/freaked.gif...

    I pulled the fuse, and this morning removed the device. Like Sam says, I do believe the long pauses are unreliable-
    I'm now trying Rich's example on my workbench- it has some really elegant code- I particularly like the idea of averaging the data coming from the light sensor. Using the RC time constant to measure daylight does seem unreliable, at least the way I was doing it. I have it set up with LED's showing activity and will definitely set up a Ping or IR pair to verify the door isn't blocked before it closes.

    Thanks for all your help! I'll keep you updated
    -Dan
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2010-05-12 12:40
    I use this instead of a photo cell
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    '
    ' -----[noparse][[/noparse] I/O Definitions ]-------------------------------------------------
     
    'This use two Basic Stamp I/O pins for one LED use a[color=green]'green LED[/color] for this 
    
    led             PIN     0               'To LED anode        
    chg             PIN     1               'To LED cathode
    ' -----[noparse][[/noparse] Variables ]-------------------------------------------------------
    dly1            VAR     Byte
    dly2            VAR     Byte
    dly3            VAR     Byte
    cntr            VAR     Word
    '--------Initialize:-------------------------------------------------------
    dly1 = 1
    dly2 = 50 '<<<<<<<<<<<<<<<<<......................Changing This Value Will Change The Light Level Respone 50 to 150 or so
    dly3 = 100
    
    '-----[noparse][[/noparse] Program Code ]----------------------------------------------------
    Run:
    
    cntr = 0             '  File Name    Dual LED Switch
    DO                   '  Author....   Sid Weaver
    HIGH led             '  Some changes where made for this this code to work
    LOW chg              '  In My Project I would like to Thank Sid For Posting
    PAUSE dly1           '  His Code This made this part easer for me to make this work
    
                         ' charge               
    
    LOW led              '  This is One LED Switch
    HIGH chg
    PAUSE dly1
                         'input
    LOW led
    INPUT chg
    PAUSE dly2            'Changing This Value Will Change The Light Level Respone
     
     
     
     
    
    DEBUG CR, DEC ? chg, DEC ? cntr
     
       [color=blue] cntr = cntr + 1 * (1 - Chg)[/color]
    
        IF (cntr = 300) THEN EXIT    ' This line (cntr = 300) control the pause before it dose the line bellow in [color=red]red[/color]
                                     [color=black]' If you light level changes before the count ([color=#000033]cntr)[/color] get to (= 300 ) THEN the count start over 
    [/color]PAUSE dly3
    LOOP
    [color=red]DO
    HIGH 14
    PAUSE 500
    LOW 14
    PAUSE 500
    LOOP [/color]
    

    Here is a second version of the same code how ever it dose not work the same try both
    The line in blue is what is different in this code
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    '
    ' -----[noparse][[/noparse] I/O Definitions ]-------------------------------------------------
    led             PIN     0               'To LED anode
    chg             PIN     1               'To LED cathode
    ' -----[noparse][[/noparse] Variables ]-------------------------------------------------------
    dly1            VAR     Byte
    dly2            VAR     Byte
    dly3            VAR     Byte
    cntr            VAR     Word
    '--------Initialize:-------------------------------------------------------
    dly1 = 1
    dly2 = 50         'Changing This Value Will Change The Light Level Respone
    dly3 = 100
    
    '-----[noparse][[/noparse] Program Code ]----------------------------------------------------
    Run:
    
    cntr = 0             '  File Name    Dual LED Switch
    DO                   '  Author....   Sid Weaver
    HIGH led             '  Some changes where made for this this code to work
    LOW chg              '  In My Project I would like to Thank Sid For Posting
    PAUSE dly1           '  His Code This made this part easer for me to make this work
    
                         'charge 
                 
    LOW led              '  This is One LED Switch
    HIGH chg
    PAUSE dly1
                         'input
    LOW led
    INPUT chg
    PAUSE dly2            'Changing This Value Will Change The Light Level Respone
    DEBUG CR, DEC ? chg, DEC ? cntr
     
    [color=blue]cntr = cntr + 1 * Chg  ' This line is to check if state has changed[/color]
    
    IF (cntr = 300) THEN EXIT
    PAUSE dly3
    LOOP
     
    DO
    HIGH 14
    PAUSE 500
    LOW 14
    PAUSE 500
    LOOP 
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·Now wanting to learn Spin· Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 5/12/2010 1:01:51 PM GMT
  • danharrdanharr Posts: 10
    edited 2010-05-12 13:35
    Hi Sam-
    Are you saying that the LED works as a light sensing photo cell?
  • sumdawgysumdawgy Posts: 167
    edited 2010-05-12 15:42
    Disclaimer: I only just saw this thread and didn't / don't have time YET to read the code snippets/completes posted.

    But, I did read the comments and had a couple of quick thoughts..(don't crucify me if I missed them being addressed I'll study this thread later tonite...I still wouldn't mind knowing if it was addresssed tho.)
    1--"Light/Dark & storms" or "Soft Set Clock"
    2--Door Safety Sensors
    3--RFid dark entry (curfew permissions)
    4--Inside the house override

    "Light/Dark & storms" or "Soft Set Clock"
    If sensing light/dark...what happens for bad storms?· Since you're not using a Real time clock you COULD let a Word keep track of elapsed minutes someway.· Since time isonly going to be an approximation anyway so you could set a group of buttons that tell the code to set the word to say 7am/noon/4pm/6pm.· My train of thought is that if somone pressed the button (at the appropriate time)·and got a confirmation light then you know the unit has reset it's "clock" to that time.· Then as long as you daily or, everyother daily press the right button (say when you leave for work, when the kids get home from school, or you get home from work. [noparse][[/noparse]
    Redundancy..kids get a chace to be responsible...while you can still do it in am/pm in case they misssed.].·Much easier to track day night.

    Say·you paused 5 seconds thru each loop then track that with a byte to approximate a minute then use a word to track total minutes (Off the top of my head, that should cover 24 hours.) as long as you use the programmed·"Change time to X:00 (ie 7am/noon/4pm/6pm)" buttons every so often.....you could make the time check a more accurate before the unit starts looking for darkness
    ONE caveat, the stamps not going to be responsive to door signals duing 5 sec pauses.
    I would use pause·285 (300·- estimated interpreter delays)·& count it to 200 in the byte counter to approxmate a minute.· (oh, tweak it in testing!).· Allowing more frequent looping.

    Door Safety Sensors
    I would·also install ·elevator style door sensors. I'm safety paranoid, so I would use at least 4 break beam i/r sensors & a pressure sensor. (adjusting the door closer to stop before pressure sensor actuates. One of my favorites is a small·pipe insulation tube (foam) with strips of foil glued to the inside. set the door to reverse action during close if either system signals. (But·only·during closing.)·The stamp can check door closed status with a magnet switch. (Just me i didn't see how you do it now.).

    RFid dark entry (curfew permissions)
    Maybe·a floor mounted RFid sensor in the middle of the gantry (sealed in waterproofing plastic).· could pickup the chicks leg bracelet chips?·That could provide a·1 minute door open signal to allow admittance.· (assuming·one of the others won't want to go wandering.)·If the chicks get smart enough.....they could create a revolving door policy. (possibly over the top disclaimer)So, you could make the ramp a fenced tunnel & use a ir system to track an entry (closing an outer door) & wait for a valid chip response. (What would be the odds it would be a "tagged" piece of wildlife that comes after the henhouse...these days?)· Keep the outer door closed *& sound an alarm (in the house) if no RFid tag is found.·unless you're not going to be monitoring that often then, it would be safer to reopen the outer door after a few·minutes.

    Inside the house override
    Nothing fancy. wired signals that allow you to force the door into open/close mode as you require.
    AND/OR Buy a garage door remote and hook it up as you please.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Before you criticize someone, walk a mile in his shoes. That way if he gets angry, he'll be a mile away and barefoot. - unknown
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2010-05-12 17:44
    danhar

    It works kind like photo switch meaning that the code dose the work to make an led act like a switch

    I will see if I can find the post where it talk about how an LED can sense light changes with a litte help

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·Now wanting to learn Spin· Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam
  • danharrdanharr Posts: 10
    edited 2010-05-13 16:53
    Thanks for the great ideas!

    I tried Sam's programs but can't figure how the LED acts as a light sensor- will still research this as the photocell/cap isn't that reliable...
    I've been trying Rich's program on the workbench with really promising results so far. Thanks Rich!!! Averaging the photocell helps A LOT! I'm thinking about averaging it at two different times during the late afternoon/ evening (to check for storm darkness). Then, waiting for an hour (or two) and finally closing the door but only after getting the OK from an IR safety beam as described by Sumdawgy. I don't mind if the door closes at 10PM, just so it shuts, especially in the cold winter months. Our run is pretty secure now so I'm not so worried about predators right now...

    The birds sleeping in the doors' path kinda freaked me out. I prefer round to flattened birds! I've also been thinking about inside-the-house control, but hadn't thought of the garage door opener idea. Maybe a house alarm remote, as these are cheap too... Going to put it back in service this weekend after I make the IR beam safety trigger...
  • danharrdanharr Posts: 10
    edited 2010-05-17 13:38
    How lousy is RCTIME?

    I have tried numerous combinations of photo resistor, photo transistor and capacitor with no reliable results using RCTIME. I'll get a reading of 1 or 2 next to my worklight and two minutes later get a reading in the hundreds from exactly the same position. Even averaging out the input over ten or a hundred samples is unreliable. I thought about getting an A to D converter or a different type of light sensor, but I've now decided to use an op amp, like the 741, working as a comparator. I'll feed the photo resistor in a ladder into the positive input of the op-amp, and run the output into a stamp input. I will (hopefully) be able to give the STAMP a 5 volt and near zero volt input at sunrise and sunset. Any concerns I should have interfacing the 741 with a stamp input?
    Very disappointing about RCTIME- which seems to be the only way to put analog directly into a stamp.
  • FranklinFranklin Posts: 4,747
    edited 2010-05-17 14:26
    One thing about RCTIME is it will depend on the resistance and capacitor you choose how well it works. There is a sweet spot where everything works better than other combinations. Not sure where to point you but the manual may have some insight.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • ercoerco Posts: 20,256
    edited 2010-05-17 16:32
    danharr: As you surmised, outdoor light levels are gargantuan compared to typical indoor levels, and light sensors get saturated easily outdoors. You can probably use a plain old photocell just as well as a photo transistor, but you will definitely want to shade your sensor from direct sunlight, and/or put it in a dark container with a small viewing hole that looks horizontally. And you will have to calibrate it with the right capacitor outdoors. I find RCTIME to be extremely useful and consistent when used properly. Consider making the light-sensing variable a word variable instead of a byte variable for a wider range (0-65535 instead of 0-255)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
  • danharrdanharr Posts: 10
    edited 2010-05-18 00:29
    Thanks,
    I'm going to try this comparator idea next- I think going digital into the stamp must be more reliable.

    I just can't understand why exactly the same distance from a light source would vary by a value of 200 or more from one moment to the next. As you say, I will have to experiment more with RCTIME and different caps if my comparator idea fails.
  • JomsJoms Posts: 279
    edited 2010-05-18 03:14
    Dont know if your open to this idea or not...

    But maybe move on from the 'building a photocell' idea and just buy one from your local hardware store. They make one that is used on outdoor lighting and controls 120 directly. Just use a 120 volt relay from the output of the photocell and have that control a stamp pin. They have built in delay of about 5 minutes, and only cost around $10.

    You might be able to even open it up and change the timing resistor value to make the time delay longer and bypass the stamp all together... Any way you can make the door go very slow, (up to a minute to close) so if a little one is in the way, he would have time to move?

    Just an idea...
  • ercoerco Posts: 20,256
    edited 2010-05-18 04:18
    A comparator like the 393 (dual) or 339 (quad) is pretty straightforward to use. Ground all unused inputs to eliminate oscillation. Use photocells, resistors & pots as voltage dividers. And you'll need a 1-10 meg hysteresis resistor to prevent oscillation. But that will only give you one snap transition level. A photocell and a cap can do exactly what you want with software-adjustable light levels. Might be different for dawn & dusk. I'd double check your circuit before giving up. If you just had things plugged into a breadboard socket, something may have come loose or shorted out to change your results. Solder everything together and retry it. If you are using a Stamp anyway, minimize external hardware as much as you can.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
  • sumdawgysumdawgy Posts: 167
    edited 2010-05-18 14:25
    erco said...
    A comparator like the 393 (dual) or 339 (quad) is pretty straightforward to use. Ground all unused inputs to eliminate oscillation. Use photocells, resistors & pots as voltage dividers. And you'll need a 1-10 meg hysteresis resistor to prevent oscillation. But that will only give you one snap transition level. A photocell and a cap can do exactly what you want with software-adjustable light levels.
    This page has an very useful comparator primer.· http://www.sullivan-county.com/ele/pd.html#comparator
    erco said...
    Might be different for dawn & dusk.
    Yeah that's why the Stamp needs to track AM/PM & a rough time. Cloudy days could cause premature closing.
    I came across an old manual alarm clock I used in service.· They still sell these things as kits & in stores fairly cheaply.·

    The clock has an alarm-output switch that can be wired to the stamp to update the estimated clock time.· They usually activate for 30-60minutes every 12 hours.· To Set/Reset the stamp there should be some sort of AM/PM indicator & a button to toggle AM/PM.· After that, set the clock's alarm to whatever time the stamp expects and....Concievably, it should run for months.

    Although I'd recomend a more aggresive maintenace schedule [noparse]:)[/noparse]

    PS. It occurred to me that setting the clock could trigger an alarm signal ...Have to workaround.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Before you criticize someone, walk a mile in his shoes. That way if he gets angry, he'll be a mile away and barefoot. - unknown

    Post Edited (sumdawgy) : 5/18/2010 2:48:48 PM GMT
Sign In or Register to comment.