Shop OBEX P1 Docs P2 Docs Learn Events
Parking Sensor Project? — Parallax Forums

Parking Sensor Project?

SS Posts: 8
edited 2008-12-03 08:22 in BASIC Stamp
I am working on a parking sensor for my project and am stuck.· Any ideas on how, once the car is parked in the garage, I can turn the RED LED off that comes on when the car reaches the proper distance?· Right now it just stays on until the car is moved out of the garage.· Any help on this is greatly appreciated...

Thanks,
S

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-11-30 21:23
    How about a simple timer? What you want is, when the red LED comes on, it only stays on for 3 to 5 minutes, then turns off. How you do it depends on your existing circuitry. If you've got some kind of logic signal to turn on the LED, use that to trigger a 555 timer circuit wired in monostable (one-shot) mode with a timeout of 3 to 5 minutes. Look at any CMOS 555 timer datasheet for circuits and parts values for the circuit. The 555 can nicely drive the LED as well.

    Here's a link to a nice tutorial: www.uoguelph.ca/~antoon/gadgets/555/555.html
  • SS Posts: 8
    edited 2008-11-30 21:30
    Right now the ciruit is simple.· The Red LED is on Pin 10 of the Basic Stamp 2, when the distance equals the parkdistance stored in EEPROM, PIN 10 goes HIGH and stays HIGH until the vehicle is moved again...
  • Carl HayesCarl Hayes Posts: 841
    edited 2008-11-30 21:30
    Why not turn it on (I assume you're using an output pin to turn it on) and then do a loop for, say, one minute, then turn it off?

    Then loop endlessly until the car is moved (I assume you detect this), then go again ino the code that detects entry into the garage.

    Your program would always be in one of three states:

    (State 1) Out of garage, driving around. LED is off. Program is looping, waiting to detect car-in-garage.
    Each time through loop, it turns the LED off and tests for car-in-garage.
    If car-in-garage is detected, change to State 2.

    (State 2) In garage. LED is on. Looping for one minute. You can time the loop with a simple counter that you reset
    once on entering State 2.
    Each time through loop, turn the LED on and test to detect car-out-of-garage.
    If car-out-of-garage is detected, change to State 1.
    If in this loop for one minute and car still in garage, Change to State 3.

    (State 3) In garage, LED is off. Looping endlessly.
    Each time through loop, turn LED off and test to detect car-out-of-garage.
    If car-out-of-garage is detected, change to State 1.

    Thus, with three simple loops you have built a deterministic automaton with three internal states. It ought to take no more than twenty lines of code, perhaps many fewer, plus any code in a subroutine that detects car-in-garage.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i@arrl.net
  • SS Posts: 8
    edited 2008-11-30 21:30
    I was hoping to add something to my code to turn it off.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-11-30 21:40
    When the distance measured is greater than the parking distance (by some amount), your code initializes a variable to some count (say 60000).

    When the distance measured is less than or equal to the parking distance and the variable is greater than zero, the variable is decreased by 1 and the LED is turned on.

    When the variable is zero, the LED is turned off
  • SS Posts: 8
    edited 2008-11-30 23:11
    Here is the LED control code as of right now:

    ' *** LED CONTROL ***
    '
    IF inDistance > ParkDistance + 15 THEN
    LOW GREENLED
    LOW YELLOWLED
    LOW REDLED
    '
    ELSEIF inDistance = ParkDistance + 15 THEN
    HIGH GREENLED
    LOW YELLOWLED
    LOW REDLED
    '
    ELSEIF inDistance = ParkDistance + 5 THEN
    HIGH YELLOWLED
    LOW GREENLED
    LOW REDLED
    '
    ELSEIF inDistance = ParkDistance THEN
    HIGH REDLED
    LOW GREENLED
    LOW YELLOWLED

    ENDIF

    Where should I insert the counter?
  • Mike GreenMike Green Posts: 23,101
    edited 2008-11-30 23:47
    Whereever you declare your other variables, put a declaration for "counter VAR WORD"
    ' *** LED CONTROL ***
    '
    IF inDistance > ParkDistance + 15 THEN
       counter = 60000 ' This value depends on how often you measure inDistance
       LOW GREENLED
       LOW YELLOWLED
       LOW REDLED
    '
    ELSEIF inDistance = ParkDistance + 15 THEN
       HIGH GREENLED
       LOW YELLOWLED
       LOW REDLED
    '
    ELSEIF inDistance = ParkDistance + 5 THEN
       HIGH YELLOWLED
       LOW GREENLED
       LOW REDLED
    '
    ELSEIF inDistance = ParkDistance THEN
       if counter > 0 then
          counter = counter - 1
          HIGH REDLED
       else
          LOW REDLED
       endif
       LOW GREENLED
       LOW YELLOWLED
    ENDIF
    


    Note: Think about what happens as you move closer to ParkDistance and particularly what happens when you back out and maybe go in again. I think you'll find that the above logic doesn't handle this case well. You either want the system to go back to yellow, green, then off as you back out or you want the system to turn off if you stay in any position for too long and either turn back on as you move in either direction or require you to completely back out to reset things.

    Post Edited (Mike Green) : 11/30/2008 11:57:10 PM GMT
  • SS Posts: 8
    edited 2008-11-30 23:57
    Ok, got it to turn off using a LOOP UNTIL command, now I need to turn it back on here is all of my code thus far please keep in mind I am a beginner at this:

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    '
    '
    '
    '
    '
    InConstant CON 890
    inDistance VAR Word
    ParkDistance VAR Word
    time VAR Word
    eepromAddress VAR Byte
    GREENLED PIN 6
    YELLOWLED PIN 8
    REDLED PIN 10

    '
    MAIN:

    DO
    IF (IN2 = 1) THEN
    GOSUB CALIBRATION_SUBROUTINE
    ENDIF
    '
    IF (IN2 = 0) THEN

    PULSOUT 15, 5
    PULSIN 15, 1, time
    inDistance = inConstant ** time
    DEBUG CR, DEC3 inDistance, " in"
    PAUSE 100

    '
    FOR eepromAddress = 0 TO 0 STEP 2
    READ eepromAddress, Word ParkDistance
    NEXT

    ' *** LED CONTROL ***
    '
    IF inDistance > ParkDistance + 15 THEN
    LOW GREENLED
    LOW YELLOWLED
    LOW REDLED
    '
    ELSEIF inDistance = ParkDistance + 15 THEN
    HIGH GREENLED
    LOW YELLOWLED
    LOW REDLED
    '
    ELSEIF inDistance = ParkDistance + 5 THEN
    HIGH YELLOWLED
    LOW GREENLED
    LOW REDLED
    '
    ELSEIF inDistance = ParkDistance THEN
    HIGH REDLED
    LOW GREENLED
    LOW YELLOWLED

    ENDIF

    ENDIF

    LOOP UNTIL (inDistance = ParkDistance)
    '
    PAUSE 15000
    LOW REDLED
    END
    CALIBRATION_SUBROUTINE:
    DEBUG "Calibrating Park Position..."

    FOR eepromAddress = 0 TO 0 STEP 2
    PULSOUT 15, 5
    PULSIN 15, 1, time
    ParkDistance = inConstant ** time
    DEBUG CR, DEC3 eepromaddress,CR,
    "Park Position ", DEC3 ParkDistance, " in"
    WRITE eepromAddress, Word ParkDistance
    '
    NEXT
    DEBUG CR, "ALL DONE!"

    PAUSE 15000
    RETURN
  • SS Posts: 8
    edited 2008-12-01 00:21
    Thank you very much Mr. Green! I now have a working Parking Sensor!!!

    Thanks again,
    S
  • GeorgeLGeorgeL Posts: 131
    edited 2008-12-02 06:16
    what else you could have done is use this component (forgot the name) that reacts to magnets making a complete circuit. Put the magnet under your car, then the part changes color when you get to proper spot. Or a simple Ir pair would work.
  • SRLMSRLM Posts: 5,045
    edited 2008-12-02 07:00
    A reed switch... Parallax has recently added one to their inventory, or you could make one yourself fairly easily. One thing to keep in mind though is that either a) the switch would have to be elevated fairly high off the floor to get close enough to be triggered, or the magnet on the car would have to big, in which case it picks up debris from the road.

    As long as alternatives are being suggested, S could make a IR beacon like emergency vehicles have (and some buses). That would give you a "in the general area, not in the general area" type of information, good for opening the garage door (and turn on the heat, start the hot chocolate machine, and find something interesting on tv...)
  • Carl HayesCarl Hayes Posts: 841
    edited 2008-12-03 04:10
    Me, now, I use a tennis ball on a string.· When the windshield moves the tennis ball, I've pulled in far enough.· It uses less electricity, too.· But it isn't near as much fun.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i@arrl.net
  • GeorgeLGeorgeL Posts: 131
    edited 2008-12-03 05:58
    "A reed switch... Parallax has recently added one to their inventory, or you could make one yourself fairly easily. One thing to keep in mind though is that either a) the switch would have to be elevated fairly high off the floor to get close enough to be triggered, or the magnet on the car would have to big, in which case it picks up debris from the road.

    As long as alternatives are being suggested, S could make a IR beacon like emergency vehicles have (and some buses). That would give you a "in the general area, not in the general area" type of information, good for opening the garage door (and turn on the heat, start the hot chocolate machine, and find something interesting on tv...)"


    Dont buy reed switches off of Parallax's site though, go to eBay. Just read someone get it 50 for 3$
  • SRLMSRLM Posts: 5,045
    edited 2008-12-03 08:22
    Ouch, GeorgeL. I was trying not to say it so bluntly, but it does seem like they are pretty highly priced... Still, it does have the advantage of being Parallax Testedtm
Sign In or Register to comment.