Garage parking sensor

MORA99

Senior Member
Mounted on the back of a garage to help indicate when the car is far enough (and yet not hit the wall).
-Ofcause drivers still have to look themselves, not rely on the thingy always working.

Code:
SYMBOL RANGE = 0 'Maxsonar EZ (Dont remember which of them, one with a narrow beam is probaly best)
SYMBOL ADC = 4   '22k pot to adjust the alert range from 35cm to 255cm
SYMBOL LED = 1   '8 cheapo leds driven by a PNP, sets of 2 with a resistor each

SYMBOL DISTANCE = w1 'Distance to nearest object, converted into metric
SYMBOL TARGET   = b1 'Readout from pot
SYMBOL TEMP     = b0 'Temporary variable used in loops

HIGH LED 'Driven by PNP transistor, HIGH=OFF

do
  GOSUB updateDistance
  
  if DISTANCE < TARGET then
    for TEMP=0 to 100 '100*0,1sec=10sec
      toggle LED
      pause 100
    next
    HIGH LED
  
  
    debounce:
    sleep 1 '~2.3seconds low power mode
    GOSUB updateDistance    
    
    if DISTANCE < TARGET then debounce 'Wont trigger again untill object has moved away
    
  endif
  
  
  if DISTANCE > 250 then 'Over 2.5meters away, low power mode
    sleep 1
  endif


loop

updateDistance:
 pulsin RANGE,1,DISTANCE
 DISTANCE = DISTANCE / 58 '147uS per inch, 1inch=2.54cm, 147/2.54=57.874 per cm
 readadc ADC,TARGET

 if TARGET<30 then '30 is the least sensor can measure
   TARGET=35
 endif
 
 sertxd(#DISTANCE," ",#TARGET,CR,LF)
RETURN




#rem
69bytes used - PICAXE 14-M - Current usage without leds 1-2mA acording to my DMM.

Possible power optimization
* Sonar-Datasheet "Sensor operates at 42KHz & Readings can occur up to every 50mS, (20-Hz rate)" - underclocking possible.
* 1 high brightness LED instead of 8 (with 4 resistors)
* Control RX line of the sonar, bring LOW to stop it from rangeing, then HIGH and wait 20us before reading.
* ...
#endrem
 

Attachments

MORA99

Senior Member
@Mora99,

Do you have a 10 kOhm resistor between the stereo programming socket Serial In terminal and ground?
Its a long time since I made it, but from the picture I cant see it.
Theres the 22k and one for base to transistor and a few for leds.

Ofcause it should be mounted to prevent the picaxe from jumping to program loading, when not needed.

The 22k is only needed when using rs232 right ?
So if programming using a ttl cable, it could be left out
 

westaust55

Moderator
The 22k is only needed when using rs232 right ?
So if programming using a ttl cable, it could be left out
Yes the 22 kOhm is primarily for voltage protection when using an RS232 comms port.
If you use an USB port based cable (eg AXE027) then unless different from the norm in terms of voltage (and we can never exclude the inventiveness of some) the 22 kOhm resistor is not essential.
 
Top