Measuring Distance With Hc-sr04p & Ultrasonic Sensor Hc-sr04

About the project

In this tutorial we are going to connect HC-SR04P module to Arduino using a serial connection & display the distance in Visuino.

Project info

Difficulty: Easy

Platforms: ArduinoVisuino

Estimated time: 1 hour

License: GNU General Public License, version 3 or later (GPL3+)

Items used in this project

Hardware components

Jumper wires (generic) Jumper wires (generic) x 1
Arduino UNO Arduino UNO x 1
Ultrasonic Sensor - HC-SR04 (Generic) Ultrasonic Sensor - HC-SR04 (Generic) x 1

Software apps and online services

Arduino IDE Arduino IDE
Visuino Visuino

Story

Display the distance in Visuino Terminal window or in Visuino Instruments window.

Watch the Video!

Step 1: What You Will Need

1 / 4

  • HC-SR04P module with Ultrasonic Sensor HC-SR04
  • Arduino UNO (or any other board)
  • Jumper wires
  • Visuino program: Download Visuino

Step 2: The Circuit

  • Connect HC-SR04P module pin [VCC] to Arduino board pin [5V]
  • Connect HC-SR04P module pin [GND] to Arduino board pin [GND]
  • Connect HC-SR04P module pin [TX] to Arduino board pin [RX]

Step 3: Start Visuino, and Select the Arduino UNO Board Type

1 / 2

Start Visuino as shown in the first picture Click on the "Tools" button on the Arduino component (Picture 1) in Visuino When the dialog appears, select "Arduino UNO" as shown on Picture 2

Step 4: Using Serial Window to See the Distance Values

1 / 2

  • In Visuino connect Arduino board serial pin [Out] to Arduino board serial pin [In]
  • Upload the Project (see the step "Generate, Compile, and Upload the Arduino Code")
  • In Visuino select "Serial > Terminal Tab", make sure that the correct port is selected & click "Connect" button

Note: When you upload the project disconnect pin [RX] on the Arduino board and after the upload connect it back

Step 5: Using Instruments Window to See the Distance Values

1 / 8

  • Add "Char To Text" component
  • Add "Replace Text" component and in the properties window set "From Value" to D:
  • Add another "Replace Text" component and in the properties window set "From Value" to cm

Note that there is a space in front of cm

  • Add "Text To Integer" component
  • Add "Packet" component
  • Double click on the "Packet1" component and in the "Elements" window drag "Integer" to the left side
  • Optional: you can select a different Instrument in the properties window or set the MAX or MIN scale

Step 6: In Visuino Connect Components

1 / 3

In Visuino connect Arduino board serial pin [Out] to "CharToText1" pin [In]

  • Connect "CharToText1" pin [Out] to "ReplaceText1" pin [In]
  • Connect "ReplaceText1" pin [Out] to "ReplaceText2" pin [In]
  • Connect "ReplaceText2" pin [Out] to "TextToInteger1" pin [In]
  • Connect "TextToInteger1" pin [Out] to "Packet1">"Integer1" pin [In]
  • Connect "Packet1" pin [Out] to Arduino board serial pin [In]
  • Upload the Project (see the step "Generate, Compile, and Upload the Arduino Code")
  • In Visuino select "Serial > Instruments Tab", make sure that the correct port is selected & click "Connect" button

Note: When you upload the project disconnect pin [RX] on the Arduino board and after the upload connect it back

Step 7: Generate, Compile, and Upload the Arduino Code

1 / 2

Note: Before uploading the project disconnect pin [RX] on the Arduino board and after the upload connect it back

In Visuino, at the bottom click on the "Build" Tab, make sure the correct port is selected, then click on the "Compile/Build and Upload" button.

Step 8: Play

If you power the Arduino UNO module, the HC-SR04P module will start to send the distance values in cm to Visuino using the serial connection.

Congratulations! You have completed your project with Visuino. Also attached is the Visuino project, that I created for this Instructable. You can download and open it in Visuino: https://www.visuino.eu

Schematics, diagrams and documents

Visuino File

Code

Visuino File

Credits

Photo of Ron

Ron

Arduino Developer

   

Leave your feedback...