I am buiding an Object Avoidance car using one of those inexpensive HC-HR04 Sonar Units. To see if a unit is working properly, I build a small circuit to test them. I am using an 08M2, with the following code. The idea is to use an 28X2 as a main chip for other functions while the 08M2 is checking the surroundings independently, and signalling the 28X2 if there is an obstruction in its path by pulling an input port up (or down).
Unfortunately, I have encountered several problems with these units. First of all, they seem to be quite irratic in use. In the program used above, I get often random readings of the same object inbetween the correct ones. Also, I bought 10 units, of which 7 would not work and would display "0"s as the range, without changing the figure when the object was moved.
On the ones which worked, this range would vary depending on where the object was located, with a "255" if the object was several feet away.
Has anyone used these units with any better results? Or is it something I am missing?
Code:
;Here is the code for testing the ultrasonic sensor HC-SR04 Sonar unit
;with the terminal windows displaying the distance result in centimetres.
;The sonar has a 2K2 resistor connected between Echo and Trigger
;terminals with C.2 connected to the Trigger terminal.
;
;Uses the ULTRA command.
#picaxe 08M2
symbol ping = C.2
pause 100
main:
ultra ping,b1 ;measure the distance
sertxd("The range is ",#b1,13,10) ;print it
pause 300
goto main ;loop
On the ones which worked, this range would vary depending on where the object was located, with a "255" if the object was several feet away.
Has anyone used these units with any better results? Or is it something I am missing?