Ultrasonic sensor review: Parallax Ping, SainSmart HC-SR04, RadioShack Ultrasonic Range Sensor

August 24, 2014

Ultrasonic sensors are great for providing distance sensing to robots so they can navigate around obstacles and hopefully prevent them from crashing at high speed and damaging themselves. Probably like many people new to robotics, I have been using the Parallax Ping sensor as well as the Radioshack Ultrasonic Sensor, which are both great products, but at $30 each it starts to get expensive once you have three or five of them on a robot, and I really don't want to be limited to having a single operational robot at at time.

I recently found out about a much cheaper alternative named the HC-SR04 which cost a fraction of the price or the Parallax Ping. These can be purchased from as low as $1.40 on Amazon if you buy a pack of 10. This is clearly a game changer... if they actually work! I wanted to find out, so I purchased a SainSmart HC-SR04 Sensor for $5.25 (including shipping) and set up a test to compare this alongside the Parallax Ping and the Radio Shack Ultrasonic Range Finder products.

As you can see, this is a simple breadboard setup connected to an Arduino Uno. In the test I take one measurement from each sensor in quick succession and output them to the serial monitor. I do this once per second and note the results. I used the exact same code for each sensor, which sets the trigger pin HIGH for 10 microseconds and then reads a digital pulse from the echo pin. The length of the echo pulse indicates how long it took the sound to reach the target object and be echoed back.

In the case of the HC-SR04, the trigger pin and echo pin are separate pins (which could be a limitation for some applications), whereas the Parallax and Radio Shack versions use a single pin for both purposes.

int get_distance(int triggerPin, int echoPin) {

  // trigger the sensor to emit an ultrasonic signal
  pinMode(triggerPin, OUTPUT);
  digitalWrite(triggerPin, LOW);
  digitalWrite(triggerPin, HIGH);
  digitalWrite(triggerPin, LOW);

  // read the echo pulse 
  pinMode(echoPin, INPUT);
  long duration = pulseIn(echoPin, HIGH);

  long cm = duration / 29 / 2;

  return cm;

NOTE: Since posting this I found that there was a fatal flaw in my testing approach, so I have removed the original results and conclusions. See my Ultrasonic sensor comparison Part 2 post for more information.