I am facing some issues trying to connect two sensors which make use of the SDA GPIO.

  • Ultra sound sensor HC-SR04
  • Gyroscope & Accelerometer MPU-6050

Separately, they work just fine, however when I share the SDA GPIO they don't. Check the i2cdetect results:

i2c results

Here you can see the connections (Yellow is the SDA connected to the GPIO 2 (Pin 3):

Bread board with the connections

Do you guys have any idea what I might be doing wrong?

1 Answer 1


The HC-SR04 sonar ranger is not an I2C device. You should not connect it to an I2C bus.

It needs to be connected to two spare gpios. An output gpio for a trigger pulse and an input gpio for the echo signal.

To take a reading you set the trigger gpio high for >10 µs and then set it low. The echo line will read high thereafter until the sonar echo is received when the echo line will be set low. The high time indicates the round trip echo time.

If the round trip time is measured in µs the round trip cms can be calculated from

round trip cms = round trip time / 1000000.0 * 34030

If you power the sonar ranger from 5V (as you should if you want reliable readings) you will need to use a voltage divider to drop the 5V echo output to a Pi gpio safe 3V3.

An old example for a similar ranger is given at http://abyz.me.uk/rpi/pigpio/ex_sonar_ranger.html

  • Thanks Joan. I had this assumption in mind that the HC-SR04 was a I2C... :( Thanks!
    – user22948
    Nov 30, 2014 at 11:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.