Hi all,
I have been playing with ultrasound distance measurement module. Nice little module that does basic distance measurement in the range of 3 mm to up to 3 meters or more.
I have used this module.
Bascom-AVR program is very simple:
$regfile = "m324padef.dat"'$regfile = "m16def.dat"$crystal = 8000000Config Pind.3 = InputConfig Portd.4 = OutputPortd.3 = 0Portd.4 = 0Dim Distance As Word , W As Word , I As Byte
Config Lcd = 16 * 2Config Lcdbus = 4'Config Lcdpin = Pin , Db7 = Porta.7 , Db6 = Porta.6 , Db5 = Porta.5 , Db4 = Porta.4 , E = Porta.2 , Rs = Porta.1'Config Lcdpin = Pin , Db7 = Portb.7 , Db6 = Portb.6 , Db5 = Portb.5 , Db4 = Portb.4 , E = Portb.2 , Rs = Portb.1Config Lcdpin = Pin , Db7 = Portc.7 , Db6 = Portc.6 , Db5 = Portc.5 , Db4 = Portc.4 , E = Portc.2 , Rs = Portc.1'Config Lcdpin = Pin , Db7 = Portd.7 , Db6 = Portd.6 , Db5 = Portd.5 , Db4 = Portd.4 , E = Portd.2 , Rs = Portd.1Cursor Off
Distance= 0Cls
Do Pulseout Portd , 4 , 20 'Min. 10us pulse 'Waitms 100 'meant for testing error Pulsein W , Pind , 3 , 1 'read distance Incr I If Err = 0 Then W = W * 10 'calcullate to W = W / 58 ' centimeters 'W = W / 6 ' milimeters Distance = W Else Distance = 0 End If
Locate 1 , 1 If Distance > 0 Then Lcd "D= " ; Distance; " " Locate 1 , 7 Lcd "cm" Else Lcd "*ERROR**" End If
Waitms 200
I did not complicate with designing a PCB, because module's connection to MiniPin is pretty straight forward with 4 wires like this:
Module works great. At measuring long distances one has to take care to disable unwanted echoes from the side of the module. My friend Vilko has put on sensors plastic tubes and achieved distance measurement of 4m.