Parking Sensor Project?
S
Posts: 8
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
Thanks,
S
Comments
Here's a link to a nice tutorial: www.uoguelph.ca/~antoon/gadgets/555/555.html
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
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
' *** 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?
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
' {$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
Thanks again,
S
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, nn5i@arrl.net
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$