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
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 module with Ultrasonic Sensor HC-SR04
- Arduino UNO (or any other board)
- Jumper wires
- Visuino program: Download Visuino
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]
Start Visuino, and Select the Arduino UNO Board Type
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
- 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
Using Instruments Window to See the Distance Values
- 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
- 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
Generate, Compile, and Upload the Arduino Code
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