HC-SR04 Ultrasonic Sensor Pinout in detail

The HC - SR04 ultrasonic sensor has four pins. Here is a detailed description of each pin:

  1. VCC Pin
    • Function: This pin is the power supply pin of the sensor and is used to provide the operating voltage for the sensor.
    • Voltage Requirement: It usually needs to be connected to a + 5V DC power supply to ensure the normal operation of the sensor.
  2. Trig Pin
    • Function: The Trig pin is the trigger pin and is an input pin. By sending a high - level pulse signal with a duration of at least 10µS to this pin, the sensor can be triggered to emit an ultrasonic pulse.
    • Working Principle: When this pin receives a high - level signal, the internal circuit of the sensor is activated, which drives the ultrasonic transmitter to emit 8 cycles of 40KHz ultrasonic pulses.
  3. Echo Pin
    • Function: The Echo pin is the echo pin and is an output pin. When the ultrasonic waves emitted by the sensor encounter an obstacle and are reflected back, this pin will output a high - level pulse. The width of the pulse is proportional to the time it takes for the ultrasonic wave to travel from emission to reception. By measuring the width of this pulse, the distance between the sensor and the obstacle can be calculated.
    • Working Principle: At the same time when the sensor emits ultrasonic waves, the Echo pin goes high and starts timing. When the reflected ultrasonic signal is received, the Echo pin remains high until the signal reception is completed, and then the pin goes low. At this time, the duration of the high - level is the round - trip time of the ultrasonic wave. According to the distance formula  (where  is the propagation speed of ultrasonic waves in the air, approximately  in normal air conditions), the distance between the sensor and the obstacle can be calculated.
  4. GND Pin
    • Function: The GND (Ground) pin provides a reference ground for the sensor's electrical circuit. It is essential for the proper operation of the sensor as it allows the electrical current to flow in a complete circuit. All the electrical signals and operations within the sensor are relative to this ground reference. It helps in maintaining the correct voltage levels and signal integrity across the other pins such as VCC, Trig, and Echo.