How to Use RGB LED HC‑SR04 (RUS‑04) Ultrasonic Sensor With Arduino & Visual Programming

In this tutorial, you’ll learn how to use the HC‑SR04 (RUS‑04) ultrasonic distance measuring sensor with a built-in RGB LED and Arduino. Using Visual Programming tool Visuino, we’ll create a simple yet effective setup to detect nearby objects and provide color feedback using the onboard LED.

The LED will:

Glow green when the distance is safeTurn red when an object is closer than 5 cm

This setup is perfect for beginners and makes a great first step toward building robot car obstacle avoidance systems or proximity alert devices—no manual coding required!

Watch the video to see how easy it is with Arduino and visual programming!

STEP 1
What You Will Need

What You Will Need

What You Will Need

What You Will Need

What You Will Need

HC‑SR04 (RUS‑04) ultrasonic distance measuring sensorArduino board (or any other boardJumper wiresVisuino program: Download Visuino


Ā 

STEP 2
The Circuit

The Circuit

Connect RUS‑04 pin [VCC] to the [5V] pin on the ArduinoConnect RUS‑04 pin [GND] to the [GND] pin on the ArduinoConnect RUS‑04 pin [I/O] to the [D3] digital pin on the ArduinoConnect RUS‑04 pin [RGB] to the [D2] digital pin on the Arduino
STEP 3
Start Visuino, and Select the Arduino Board Type

Start Visuino, and Select the Arduino Board Type

Start Visuino, and Select the Arduino 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

STEP 4
In Visuino Add & Set Components

In Visuino Add & Set Components

In Visuino Add & Set Components

In Visuino Add & Set Components

In Visuino Add & Set Components

In Visuino Add & Set Components

In Visuino Add & Set Components

In Visuino Add & Set Components

Add "6 RGB LEDs Ultrasonic Ranger RUS-04(Ping)(One Pin)" component

Note: there are several different variants of this sensor, mine has pins (RGB) and {I/O}, so choose the right component in Visuino according to your sensor. You can see available sensors by typing in the search box "RUS-04" or "Ultrasonic"

Add "Compare Analog Range" component, and in the properties window set "Range" > "Max" to 5, this means that the red LED will turn ON if the distance will be below 5cm. Feel free to experiment with the settings.

Alternatively you could just use "Compare Analog value" component.

Add "Digital To Color" component and in the properties window set "False Value" to ClGreen and "True Value" to ClRedAdd "Color Multi Source" component, this is optional, you could connect the pins directly, I have added this component so that the project is more organized, in the properties window set "Output pins" to 6
STEP 5
In Visuino Connect Components
Connect "CompareRange1" pin [Out] to "DigitalToColor1" pin [In]Connect "DigitalToColor1" pin [Out] to "MultiSource1" pin [In]Connect "MultiSource1" pin [0] to "UltrasonicRanger1" Left [0]Connect "MultiSource1" pin [1] to "UltrasonicRanger1" Left [1]Connect "MultiSource1" pin [2] to "UltrasonicRanger1" Left [2]Connect "MultiSource1" pin [3] to "UltrasonicRanger1" Right [0]Connect "MultiSource1" pin [4] to "UltrasonicRanger1" Right [1]Connect "MultiSource1" pin [5] to "UltrasonicRanger1" Right [2]Connect "UltrasonicRanger1" pin [Out] to "CompareRange1" pin [In]Connect "UltrasonicRanger1" LED pin [Out] to Arduino digital pin [2]Connect "UltrasonicRanger1" pin [Ping (Trigger) Echo] to Arduino digital pin [3]
STEP 6
Generate, Compile, and Upload the Arduino Code

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

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

icon Ultrasonic-rus04-rgb.zip 1KB Download(0)
License
All Rights
Reserved
licensBg
0