Page History: Vehicle Reversing Assistant
Compare Page Revisions
Page Revision: 2018/04/12 16:51
The following is a tiny trinket to provide the retro-fit your vehicle with reversing sensors (or fix a crappy Chinese kit) using 40KHz ultra-sound sensor modules available off ebay etc. for about £5. Be careful with buying these - there are two versions that I can find. One has a trigger and output pin so you can get a reading when you want it, the other type has a serial output that is free-running. The code below works with the former. The latter type presents a problem because despite claims of anti-jamming, all these modules suffer from picking up ultrasound pulses from neighbouring modules and will provide false readings. To illustrate, consider that you are some distance from an object and a pulse is initiated. A neighbouring module also sends a pulse shortly after but it "hears" the return from the first module - it can't tell this is not the reflection of its pulse and now calculates a much shorter distance than reality. OK this is fail safe but it makes for a lot of false readings and generally results in a useless system - you have to be able to control the when the pulses are sent and wait for any return. If the modules are free-running, it's mayhem.
There is a wayt ot tell these modules apart... if you apply power and the LED flickers constantly, it is free-running. These are fine for solitary use and give a serial output with the direct reading of the distance. If the LED gives a single flash, it is waiting to be triggered and these are the ones you can use in groups. It is a blunt instrument but these tend to have a blue PCB while the free-running ones have a green PCB. Here are pictures of teh two types - note there is also a differernce int he built-in microcontroller. You will have to source the appropriate modules.
My particular situation has three sensors. The trigger and outputs of each sensor need to be connected to appropriate pins of your MicroMite.
The code works by measuring all three sensors and then choosing the shortest distance. This is then compared to the timer and if the timer is greater then a beep is issued and the timer set to zero. The closer the object, the faster the beeps. There is a lock-up zone of 400mm - any closer than this and the sounder emits a continuous tone. This has the nice effect that the value for the timer changes in real time and any changes are reflected by the rapidity of the beeps fairly quickly. Also, because the time between beeps is the same number of milli-seconds as millimeters from the nearest obstacle, you become accustomed to judging distance - 1000mm means the beeps are a second apart. I have become quite good at judging distance with this.
You need a 12V to 3V PSU and iff you connect this to the supply to the reversing lights of your vehicle, the circuit comes on as you need it.
Beeps are emitted via PWM1A but you can change this if you need. You will need to provide a suitable audio device - a piezo sounder with a FET driver at 12V is good.
DependenciesDistance CSUB (in the embedded modules section of the MMBasic distribution)
CPU 48 ' need to be fairly on-the-ball
PWM 1,800,50:pause 50 ' emit some beeps on start up
PWM 1,800,0:pause 50
PWM 1,800,50:pause 50
PWM 1,800,0:pause 200
Option Base 0
Option Baudrate 9600 ' debug output is available to the console
Dim Integer n,SP(5)=(3,2,16,8,9,14),SR(2),a,a1' SP is the pins for the Distance function - adjust as required
a1=1000000 ' dummy first value
Do
For n=0 To 5 Step 2 ' each group of sensor pins
If x<0 Then x=2000 Else x=10*Distance(SP(n),SP(n+1)) ' mm
SR(n\2)=x
Next
a=Min(SR(0)),SR(1),SR(2)) ' choose closest reading
if a<>a1 then a1=a
Print SR(0),SR(1),SR(2),a;"mm"
If a<400 Then ' < 400mm then lockup
PWM 1,800,50 ' constant tone
Else
If Timer>=Max(a1-400,0) Then Beep: Timer=0
EndIf
Pause 100
Loop
Sub Beep
PWM 1,800,50
Pause 250
PWM 1, Stop
End Sub
CFunction DISTANCE(integer, integer) float
0000002D 27BDFFF8 AFBF0004 00852023 03E42021 ACC40000 8FBF0004 03E00008
27BD0008 27BDFFE0 AFBF001C 00002021 3C059D00 24A50040 27A60010 0411FFF1
00000000 8FA30010 3C029D00 8C4200BC 3C049D00 24840310 0040F809 00832021
8FBF001C 03E00008 27BD0020 000410C0 00041A00 00621823 00031180 00431823
00641821 00031980 3C029D00 8C420000 3C047735 34849400 8C420000 0082001B
004001F4 00002012 0064001B 008001F4 03E00008 00001012
27BDFFD8 AFBF0024 AFB40020 AFB3001C AFB20018 AFB10014 AFB00010 00809021
3C029D00 8C420000 8C430000 3C020098 34429680 0062102B 10400003 00A08821
0411FFCA 00000000 8E220000 14400003 3C109D00 8E420000 AE220000 8E020010
8E240000 24050002 0040F809 2406000E 8E02001C 8E440000 0040F809 24050005
8E020010 8E440000 24050008 0040F809 00003021 8E02001C 8E440000 0040F809
24050006 8E020004 0040F809 24040014 8E02001C 8E440000 0040F809 24050005
8E020004 0040F809 24040032 8E020010 8E240000 24050002 0040F809 2406000E
8E020004 0040F809 24040032 0411FFB1 24040005 00409821 0000A021 40944800
00008021 10000005 3C129D00 40104800 0270102B 1440001E 24050002 8E420020
0040F809 8E240000 1440FFF8 24040064 10000025 00000000 40104800 0270102B
14400013 24050002 8E420020 0040F809 8E240000 1040FFF8 24040020 1000001F
00000000 40104800 0270102B 14400008 24050001 8E420020 0040F809 8E240000
1440FFF8 00000000 1000001A 3C119D00 00052823 3C029D00 8C420080 00A02021
0040F809 00052FC3 8FBF0024 8FB40020 8FB3001C 8FB20018 8FB10014 8FB00010
03E00008 27BD0028 0411FF7A 00000000 00409821 1000FFDC 3C129D00 0411FF75
00000000 00409821 40944800 1000FFE1 3C129D00 8E320064 8E220000 3C037735
34639400 8C420000 0062001B 004001F4 00001012 72028002 24021696 0202001B
004001F4 00002012 8E220080 0040F809 00002821 00408021 8E220080 2404000A
0040F809 00002821 02002021 0240F809 00402821 1000FFD5 8FBF0024
20555043 65657073 6F742064 6F6C206F 000A0D77
End CFunction