Connecting HC-SR04 (analog) to Pixhawk 2.4.8

My friends and I are working on a project for school that requires a distance sensor to hover a set distance above the ground (~2m). To keep costs relatively low, we decided to purchase the HC-SR04 (analog, not I2C) ultrasonic sensor (pictured below).


In researching, I found one forum that mentioned a link that seemed to show how to connect the sensor to the Pixhawk: .

I followed the connections and modifications in both QGroundControl and Mission Planner, but I have not been able to “communicate” (read distance) from the sensor.

The connections I am using for the sensor are through Aux Out:

  • Power: Row 2, Aux Out Pin 1
  • Ground: Row 1, Aux Out Pin 1
  • Trig: Row 3, Aux Out Pin 1 (Virtual Pin 50)
  • Echo: Row 3, Aux Out Pin 2 (Virtual Pin 51)

Since it is for altitude sensing, RNGFND_ORIENT=25 (downward facing).
RNGFND1_TYPE=30 (HC-SR04 in Mission Planner).
These values were changed to match that provided in the link for connecting the sensor that I pasted above.

Is there any way to get a reading from this sensor? I have seen other posts that say it’s not possible, but I would think that since the Aux Out pins are used as GPIO it should possible. Others have said that getting a different sensor would be a good idea in response to other people’s posts, so I am starting to think that I may have to but I wanted to see if I was overlooking anything that would actually make it work. Do you have any ideas as to why it isn’t working?

1 Like

In further testing, we tried to use a logic level shifter to pass the Trig and Echo signals so that they weren’t too high voltage for the microcontroller in the Pixhawk and did hear it trying to work. We then tried to connect it directly and ended up frying the GPIO pins… BEWARE if you are passing in things above 3.3 volts. We didn’t think about it enough! (Luckily we didn’t really need these pins for the project, but still…)

I’ve justed tested this on master Rover and it is working for me.

I don’t think this works on the stable firmwares ATM.

Good afternoon colleagues, I am involved in a rover project with pixhawk 6c, and I would like to have it if possible, how did you manage to make the HC-SR04 sensor work directly on the pixhawk ???

At the end you have a possible connection diagram of the sensor pins to the pixhawk board.

I have seen on the net that there is very little information about it. Thanks in advance and a smile

1 Like

You could go to the Wiki entry for it…

1 Like

Thanks for the information, my question is if I can connect directly to the pixhawk or do I have to make an intermediate mechanism with an arduino nano?

Connection to a Flight Controller is detailed in that link (GPIO pins)

did you sort it out at the end ?
if yes, how ?
because I want to connect the same now

why it will not work ??

did you connect directly ? pls share all relevant parameters in Pixhawk 2.4.8

In the end, we were using a different (I believe digital) sensor. This specific sensor we weren’t able to get working with the Pixhawk. The other sensor from what I recall was an I2C sensor something like this: I2CXL-MaxSonar-EZ Products – MaxBotix. It was kinda spotty when the drone was in the air, though.

1 Like

will find something else.