Distance Sensor

You have received HC-SR04 ultrasonic distance sensors. This module, which measures distances using ultrasonic waves, consists of four pins:

../../_images/HC-SR04.png
  • VCC: sensor power supply (5V)

  • Trig: trigger pin

  • Echo: echo reception pin

  • GND: ground

Input and Output Voltages

  • Power supply voltage (VCC): 5V

  • Output voltage (Echo): 5V

Operation

  1. Triggering: To initiate a measurement, a 10-microsecond signal must be sent to the Trig pin. This triggers the emission of a burst of 8 ultrasonic pulses at 40 kHz.

  2. Reception: The sensor then waits to receive the echo of these pulses. When the echo is detected, the Echo pin goes high.

  3. Time Measurement: The duration for which the Echo pin remains high corresponds to the time taken by the ultrasonic wave to travel to the obstacle and back.

Reminder: The speed of sound in air is approximately 343 m/s.

Connection to the Raspberry Pi

Warning

Since the sensor’s output voltage is 5V, a voltage divider is required to lower this voltage to a level acceptable for the Raspberry Pi’s GPIO pins (3.3V).

Creating the voltage divider:

../../_images/Circuit.png

vertical resistor: 1K ohm, horizontal resistor: 2K ohm

  • Connect the sensor’s VCC pin to a 5V pin on the Raspberry Pi.

  • Connect the sensor’s GND pin to a GND pin on the Raspberry Pi.

  • Connect the sensor’s Trig pin to a GPIO pin on the Raspberry Pi (e.g., GPIO 10).

  • Connect the sensor’s Echo pin to another GPIO pin on the Raspberry Pi (e.g., GPIO 9).