Tech details:

  • Working Voltage DC 5 V
  • Working Current 15mA
  • Working Frequency 40Hz
  • Max Range 4m
  • Min Range 2cm
  • Measuring Angle 15 degree
  • Trigger Input Signal 10uS TTL pulse
  • Echo Output Signal Input TTL level signal and the range in proportion
  • Dimension 45*20*15mm


4 pin connector, pins as follows:

  • VCC: 5V Supply
  • TRIG: Trigger Pulse Input
  • ECHO: Echo Pulse Output (5v)
  • GND: 0V Ground

Echo Pulse Output requires Voltage to be stepped down to 3.3V to work with Raspberry and prevent damage.

What does it do?

Sonar HC-SR04 sensor issues an ultrasonic pulse to determine a distance from the board itself. Sensors placement limits the min range to 2cm, and it is possible to detect objects as far as 400cm away (4m). The output is generated to the GPIO21 using the code linked below and the command to check for the distance is issued on GPIO2.


How to use it?

You will need 2 GPIO pins on your board to send and receive signals to the sensor (blue), the board itself is powered by 5V from RPI (red) and last connections is for ground (black) 

Sample code:

You can test the Sonar HC-SR04 sensor using a python2 code from here:

Support NotEnoughTech
A lot of time and effort goes into keeping NotEnoughTech alive! If my work helped you out, consider buying me a coffee or check out exclusive rewards available to Patreon supporters.