Using HC-SR04 ultrasonic sensor with Jetson Nano?

Hello there,

I try to use the HC-SR04 ultrasonic sensor with the 40-pin GPIO extension header on the Jetson Nano. I didn’t find any guides at the internet, so because I’m a complete beginner with pins and co., I would be glad about any kind of help!

So for those who don’t know: this is the HC-SR04 ultrasonic sensor, originally build for Arduino:

It has four pins: VCC (for power 5V), GND (Ground), Trig and Echo (for signals). So first: How do I connect it? I have female to female jumper cables, can I connect the sensor directly to the Jetson with them? And which pins do I have to connect it with? There are 2 pins for 5V, 8 for GND and lots of others, so I don’t know which ones to use.

I have to communicate with the sensor via Python, so I can simply use the Jetson.GPIO-library, right? Or do I have to setup some communication systems like I2C or UART first? And if I do, how?

I’m also wondering about how the commands in Jetson.GPIO work. Can somebody link a guide or something to it? So far I know, I have to send a HIGH signal on the Trig pin and wait for a HIGH from Echo to come back. Then from measuring the time difference, you can calculate the distance. How can I accomplish this?

Thanks in advance!

First thing the HC-SR04 is only 5V tolerant so needs 5v to 3.3 logic translators when connecting the GPIO pins to the Nano. There is an old article which gives am indication of what needs to be implemented on the software side you need port the kernel driver to the nano. There also an RPI kernel driver which you can use as a starting point.


Calling the ultrasonic sensor directly from the Jetson Nano may not be ideal as the Jetson Nano does not do real time processing. This causes your distance measurement to become unreliable.

You’re probably better off adding a small Arduino Nano or Adafruit Feather microcontroller (the latter fits nicely under the Adafruit motor controller) to measure the distance. You can then use I2C communication to instruct the microcontroller to make a measurement and return the result via I2C.

If you’re looking for more detailed installation instructions and / or sample code you can check out my blog on this subject at .


This link: AI on the Jetson Nano LESSON 56: Using the GPIO Pins on the Jetson Nano | Technology Tutorials will be helpful for using the GPIO pins on the Jetson Nano.