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.
-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
-
60.1 KB Views: 245
-
82.3 KB Views: 346