HCSR04

What is HCSR04?

HCSR04 is a sensor that can measure distances using ultrasonic waves.

HCSR04 works as follows.

    1. When trig pin goes HIGH, ultrasonic waves are generated.

    2. When ultrasound is returned by hitting the obstacle, the echo pin becomes HIGH.

    3. You can determine the distance by measuring the time the ultrasonic waves have returned from the start. (Ultrasonic velocity: 340 m/s)

Precautions when using HCSR04

    • Objects that are too far away are difficult to measure. (It limits to 80cm in ARDUnity.)

    • If the ultrasonic reflection angle exceeds 45 degrees, it is not detected well.

    • If the object to be measured is too small or absorbs ultrasonic waves, it can not be measured.

Circuit for HCSR04

    • VCC: +5V

    • GND: Ground pin

    • Trig: 2 pin (Digital out)

    • Echo: 3 pin (Digital input)

Wiring in ARDUnity

In ARDUnity, HCSR04 can be found in "ARDUINO / Add Controller / Sensor / HCSR04".

Enter pin wiring information in Sketch Option of HCSR04.

The following connections in the Wire Editor are ready for testing.

The above information can be found in detail in the provided sample Scene.

(ARDUnity / Examples / HCSR04 / CircuitTest)

Run

If you have assemble the circuit as above, export Sketch by running the sample Unity Scene to find ArdunityApp.

(See how to export sketch from ArdunityApp)

The generated Sketch can be uploaded to the board by using Arduino IDE.

(See how to upload sketch)

If the circuit used in Unity Scene is the same circuit, you do not need to repeat the same Export Sketch & Upload.

If the connection is successful, you can check the distance measured in the Inspector of the HCSR04.