0

There's only 1 raspberry pi shop in my country and he offers only two ultra sonic sensors HC - SR04 and RB URF02 there's a pdf on the pages I linked to for more information. RB URF02 is so much more expensive.

I have tried HC - SR04, and it gives false distances sometimes, precision is important in my project. I have never tried RB URF02 but it looks the same to me, only much more expensive. Money is no problem if the sensor is that good. Is it? Cause I have to buy 4 of them

Have anyone tried RB URF02? Is it reliable? Does it give wrong readings? Is it so much better than the cheaper one?

4

Are you sure the problem is with your HC-SR04 sensor? Most of the posted code I've seen contains errors.

The only oddity I've noticed with the HC-SR04 is that sometimes the echo line stays high when no echo is detected. It really ought to go low after a timeout period (which the specs say it should).

I tried a series of experiments documented at https://www.raspberrypi.org/forums/viewtopic.php?p=563957#p563957

I tend to use code similar to the following to read the sensor.

#!/usr/bin/env python

# HC_SR04.py
# 2015-08-06
# Public Domain

import time

import pigpio # http://abyz.me.uk/rpi/pigpio/python.html

class sensor:

   def __init__(self, pi, trigger, echo):

      self._pi    = pi
      self._trig = trigger
      self._echo = echo

      self._tick = None
      self._distance = 0.0
      self._new = False

      pi.set_mode(self._trig, pigpio.OUTPUT)
      pi.set_mode(self._echo, pigpio.INPUT)

      self._cb = pi.callback(self._echo, pigpio.EITHER_EDGE, self._cbf)

   def _cbf(self, gpio, level, tick):

      if level == 1:
         self._tick = tick
      else:
         if self._tick is not None:
            ping = pigpio.tickDiff(self._tick, tick)
            self._distance = ping * 17015.0 / 1000000.0
            self._new = True

   def trigger(self):

      self._tick = None
      self._pi.gpio_trigger(self._trig, 10)

   def get_centimetres(self):

      new = self._new
      self._new = False
      return self._distance, new

   def cancel(self):

      self._cb.cancel()

if __name__ == "__main__":

   import time
   import pigpio
   import HC_SR04

   pi = pigpio.pi()


   sonar = HC_SR04.sensor(pi, trigger=20, echo=21)

   end = time.time() + 1000.0

   r = 1
   while time.time() < end:

      sonar.trigger()
      time.sleep(0.1)
      cms, new = sonar.get_centimetres()
      print("{} {:.1f} {}".format(r, cms, new))
      r += 1

   sonar.cancel()

   pi.stop()
  • I'm not sure but since one sensor is extremely cheap and the other is extremely expensive, I took a guess, since you get what you pay for. – Lynob Aug 13 '15 at 14:05
  • thanks for your code, I'll try it tomorrow! really grateful – Lynob Aug 13 '15 at 14:05
  • 1
    @Lynob The sensors look pretty much the same to me. The RB URF02 has a range of 5 metres rather than 4 which might explain the difference in price. I don't believe paying more is any guarantee of quality or correctness. I have countless counter examples from my own experience. – joan Aug 13 '15 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.