SRF06: a cheap range finder

SRF06: a cheap range finder

We are often asked if we have any plan for a range finder. Well, the answer is "no, not a this time". However, we do have some reasonable alternatives.

Making a range finder would require some know-how we don't have (yet). That's why, when we are asked for a Yocto-RangeFinder, we suggest to use a range finder with a 4-20mA output and to connect it to a Yocto-4-20mA-Rx. We usually suggest the FADK 14 from Baumer. It's an industrial sensor, precise and waterproof. However, with a 250€ price tag, it tends to frighten the most enthusiastic customers. We did some research, but it seems that all industrial range finders are very expensive. So we looked for a cheaper alternative, and we found the SRF06 from Devantech.

top  bottom
The SRF06, an ultra-sonic range finder with a 4-20mA output.

It's a tiny 43x20mm board with on one side both the ultrasonic transmitter and the receiver. On the other side you find the electronic part. It can measure ranges from 2cm to 5.1m. Unlike the Sharp sensor that we tested some time ago, it provides a calibrated 4-20mA output, not an approximate voltage output.

As the SRF06 is powered directly from the current loop, we only need 2 wires to connect it to a Yocto-4-20mA-Rx, the only pitfall is the polarity. You have to read the user manual to know the right polarity: there is no marking on the board.

How to connect a SRF06 to a Yocto-4-20mA-RX.
How to connect a SRF06 to a Yocto-4-20mA-RX.

When the SRF06 is connected, the Yocto-4-20mA-Rx needs to be configured to make sure it reports correct values. This is dead easy to achieve with the VirtualHub. The unit is cm, 4mA is mapped to 0cm, 20mA is mapped to 510cm, that's it.

How to configure a Yocto-4-20mA-RX to work with a  SRF06
How to configure a Yocto-4-20mA-RX to work with a SRF06

In order to test the SRF06, we built a camera trap. This is almost trivial: we just connected a SRF06 to a Yocto-4-20mA-Rx, that Yocto-4-20mA-Rx is also connected to a Raspberry PI. That Raspberry PI also controls a camera through a Yocto-Relay as we did here. We placed the whole system in a box to make sure it can be moved easily, and powered it with a big USB battery.

How the camera trap parts are connected together
How the camera trap parts are connected together

We put the system in a box fixed on a tripod
We put the system in a box fixed on a tripod

The Raspberry PI is controlled with a simple Python script: We installed a callback on the range measured by the sensor. If the range in between 2 and 4m, then the camera is triggered. A breeze.

from yocto_api import *
from yocto_relay import *
from yocto_genericsensor import *

def distanceChangeCallback(fct,value):
    global camera
    # if the distance is between 2 and 4 meters, trigger
    # the relay for 200 ms
    if  200<float(value)<400: camera.pulse(200)

# Setup the API to use local USB devices
if YAPI.RegisterHub("usb", errmsg)!= YAPI.SUCCESS:
    sys.exit("init error"+errmsg.value)

# find the relay controling the camera
camera = YRelay.FindRelay("shutter")
if  not camera.isOnline(): sys.exit("no camera")

# find the distance from the camera
distSensor = YGenericSensor.FindGenericSensor("distance")
if  not distSensor.isOnline(): sys.exit("no distance sensor")

# distanceChangeCallback is called automatically
# each time the distance changes significantly

# do nothing except handling events
while True:

Unfortunately we were out of wild animals to test our camera trap. So we performed some tests by throwing buckets of water in front of the system. It works remarkably well, it is however a bit slow: several tries were required until we got the picture bellow. But taking a picture of people walking in front of the system is no problem at all.



The SRF06 works pretty well for a 15€ range finder. Output is stable. But frequency is on the low side: approximately 10 measures per second. This might cripple applications needing a short reaction time. We do regret the missing marking on the board, as this forces us to consult the documentation each time we need to connect it. Obviously,it is not waterproof, but for that price, you cannot have everything. It is a very useful sensor for quick DIY projects. If you know about other cheap range finders with a 4-20mA or 0-10V output, just tell us in the comments, we are very interested.

Add a comment No comment yet Back to blog

Yoctopuce, get your stuff connected.