Measuring Distance With HC-SR04P & Ultrasonic Sensor HC-SR04 Using Visuino

by RonFrtek in Circuits > Arduino

83 Views, 2 Favorites, 0 Comments

Measuring Distance With HC-SR04P & Ultrasonic Sensor HC-SR04 Using Visuino

Measuring Distance With HC-SR04P & Ultrasonic Sensor HC-SR04 Using Visuino

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

Watch the Video!

What You Will Need

HC-SR04P.jpg
FNLOD2CKEY93G5N.jpg
WEATHER (12).png
jumper-wires.jpg
  • HC-SR04P module with Ultrasonic Sensor HC-SR04
  • Arduino UNO (or any other board)
  • Jumper wires
  • Visuino program: Download Visuino


The Circuit

2023-11-11_16-26-57.jpg
  • 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]

Start Visuino, and Select the Arduino UNO Board Type

select-board-uno.jpg
Visuino-Select-Board-UNO.jpg

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

Using Serial Window to See the Distance Values

2023-11-11_16-00-12.jpg
2023-11-11_16-01-51.jpg
  1. In Visuino connect Arduino board serial pin [Out] to Arduino board serial pin [In]
  2. Upload the Project (see the step "Generate, Compile, and Upload the Arduino Code")
  3. 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

Using Instruments Window to See the Distance Values

2023-11-11_16-06-12.jpg
2023-11-11_16-07-04.jpg
2023-11-11_16-08-16.jpg
2023-11-11_16-08-33.jpg
2023-11-11_16-11-11.jpg
2023-11-11_16-12-08.jpg
2023-11-11_16-13-17.jpg
2023-11-11_16-13-35.jpg
  • 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

In Visuino Connect Components

2023-11-11_16-16-11.jpg
ultrasonic.png
2023-11-11_16-22-19.jpg
  • 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]
  1. Upload the Project (see the step "Generate, Compile, and Upload the Arduino Code")
  2. 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

Generate, Compile, and Upload the Arduino Code

FBR42I2KXBU01YW.jpg
2023-11-11_16-27-27.jpg

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.

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

Downloads