Easy! Ultrasonic Sensor Hc-sr04 With Arduino Uno R4

About the project

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

Project info

Difficulty: Easy

Platforms: ArduinoSparkFunVisuino

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
SparkFun Ultrasonic Sensor - HC-SR04 SparkFun Ultrasonic Sensor - HC-SR04 x 1
Arduino UNO R4 WiFi Arduino UNO R4 WiFi x 1

Software apps and online services

Visuino Visuino

Story


Step 1: What You Will Need

  • Ultrasonic Sensor HC-SR04
  • Arduino UNO R4
  • Jumper wires
  • Visuino program: Download Visuino

Step 2: The Circuit

  • 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)

Step 3: Start Visuino, and Select the Arduino UNO R4 WiFi 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 R4 WiFi" as shown on Picture 2

Step 4: In Visuino Add & Set Components

3 More Images

  • 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 ArduinoUNO 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

Step 5: In Visuino Connect Components

1 / 2

  • 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 ArduinoUNO R4 WiFi > Display > "Fill Screen1" pin [clock]
  • Connect "MultiSource1" pin [1] to ArduinoUNO R4 WiFi > Display > "Draw Text1" pin [Text]
  • Connect "MultiSource1" pin [1] to ArduinoUNO R4 WiFi > Display > "Draw Text1" pin [clock]

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

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 7: 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

Schematics, diagrams and documents

Visuino File

Code

Visuino File

Credits

Photo of Ron

Ron

Arduino Developer

   

Leave your feedback...