EASY! Ultrasonic Sensor HC-SR04 With Arduino UNO R4

by RonFrtek in Circuits > Arduino

138 Views, 0 Favorites, 0 Comments

EASY! Ultrasonic Sensor HC-SR04 With Arduino UNO R4

EASY! Ultrasonic Sensor HC-SR04 with Arduino UNO R4

In this tutorial we will learn how to use Ultrasonic Sensor HC-SR04 to display the obstacle distance on the Arduino UNO R4 display using Visuino.

Watch the video!

What You Will Need

ArduinoR4.png
sku_416860_1.jpg
VisuinoAdvrtisemenArduinoUno_R4_4-small.png
jumper-wires.jpg
  • Ultrasonic Sensor HC-SR04
  • Arduino UNO R4
  • Jumper wires
  • Visuino program: Download Visuino


The Circuit

2024-04-21_13-26-04.jpg
  • Connect Ultrasonic module pin (VCC) to Arduino pin [+5V]
  • Connect Ultrasonic module pin (GND) to Arduino pin [GND]
  • Connect Ultrasonic module pin (ECHO) to Arduino pin digital (2)
  • Connect Ultrasonic module pin (TRIG) to Arduino pin digital (3)


Start Visuino, and Select the Arduino UNO R4 WiFi Board Type

select-board-uno.jpg
Visuino-Select-Board-UNO-R4.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 R4 WiFi" as shown on Picture 2

In Visuino Add & Set Components

F1YINGPLSRIPD6E.jpg
2024-04-21_14-20-55.jpg
2024-04-21_14-21-37.jpg
2024-04-21_14-23-03.jpg
2024-04-21_14-24-05.jpg
2024-04-21_14-26-02.jpg
2024-04-21_14-26-35.jpg
  • Add "Ultrasonic Ranger(Ping)" component
  • Add "Analog To Integer" component
  • Add "Integer Multi Source" component


  • Select "MultiSource1" and in the properties window set "Output Pins" to 3
  • Select Arduino UNO R4 WiFi board and in the properties window expand Modules>Display and select Elements and click on the 3 dots button, in the Elements window drag "Fill Screen" to the left side and drag "Draw Text" to the left side and in the properties window select "Text" and click on the pin icon and select "String SinkPin"
  • Close the Elements window

In Visuino Connect Components

2024-04-21_14-32-50.jpg
uno-ultrasonic.png
  • Connect "UltrasonicRanger1" pin [Echo] to Arduino digital pin [2]
  • Connect "UltrasonicRanger1" pin [Ping-Trigger] to Arduino digital pin [3]
  • Connect "UltrasonicRanger1" pin [Out] "AnalogToInteger1" pin [In]
  • Connect "AnalogToInteger1" pin [Out] to "MultiSource1" pin [In]
  • Connect "MultiSource1" pin [0] to Arduino UNO R4 WiFi > Display > "Fill Screen1" pin [clock]
  • Connect "MultiSource1" pin [1] to Arduino UNO R4 WiFi > Display > "Draw Text1" pin [Text]
  • Connect "MultiSource1" pin [1] to Arduino UNO R4 WiFi > Display > "Draw Text1" pin [clock]

Generate, Compile, and Upload the Arduino Code

Visuino-Compile-UNOR4.jpg

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 module the LEDs on the Arduino Display will start to indicate the distance of the obstacle detected by ultrasonic sensor.

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