SRF05 detector
Adding ultrasonic detection
There are many ways of adding ultrasonic sensors to a project.
This page describes one way, hopefully generic enough to be of use to everyone.
This example uses a Picaxe and SRF05. (See the link).
First, establish the units you wish to use (mm, cm or inches)
I tracked objects using multiple sensors They point to either left, right or center.
My algorithm here describes the steps used in the software below.
- Send pulse from ultrasonic sensor and start timer
- Receive reflected pulse to sensor and stop timer.
- Take timer value and divide by value to get distance.
- Store distance value in memory.
- Do same for left and right side sensors and store in different memory location.
- Compare the 3 different values and do something.
- Start again
These steps can be seen in the following ultrasonic code.
I used the following code to make the Dalek head swing left right or return to the center.
The example code is written in Picaxe Basic.
One Picaxe is continually reading pins on the other. When a pattern appears it turns the head.
There are plenty of ways to accomplish the same end result. I chose this way because I am essentially lazy and also because it’s modular.
Example ultrasonic code PDF
In my case, when I round the values in my code, the sensor looks and checks if there is an object greater than x distance from the sensor, but also less than y distance. This is my zone. The yes-no answer is recorded in memory and compared.
Schematic
Example of servo\ultrasonic schematic PDF
In my schematic I have 3 sensors.
If you just need one sensor then just use the basic
send – store – divide – code.
‘ultra sonic sensor code
‘send out pulse
pulsout 0, 2
‘receive pulse store
pulsin 5,1,w1
‘ store the length of a pulse on pin 5 into W1
‘dividing by 58 will give you the distance in cm, or dividing by 148 will ‘give the distance in inches. uS/58=cm or uS/148=inches.
let w2 = w1 /15 ;save result in w2 –
I have used 15 instead of 148 and this gives me a rounded value