Maker.io main logo

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

39

2025-07-17 | By Ron Cutts

License: GNU Lesser General Public License LED / Display Drivers LED Strips Ultrasonic Arduino

 

The LED will:

  1. Glow green when the distance is safe

  2. Turns 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

  1. HC‑SR04 (RUS‑04) ultrasonic distance measuring sensor

  2. Arduino board (or any other board

  3. Jumper wires

  4. Visuino program: Download Visuino

Step 2: The Circuit

The Circuit

  1. Connect RUS‑04 pin [VCC] to the [5V] pin on the Arduino

  2. Connect RUS‑04 pin [GND] to the [GND] pin on the Arduino

  3. Connect RUS‑04 pin [I/O] to the [D3] digital pin on the Arduino

  4. Connect 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 in 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

  1. 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"

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

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

  1. Add "Digital To Color" component and in the properties window set "False Value" to ClGreen and "True Value" to ClRed

  2. Add "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

imageimage

  1. Connect "CompareRange1" pin [Out] to "DigitalToColor1" pin [In]

  2. Connect "DigitalToColor1" pin [Out] to "MultiSource1" pin [In]

  3. Connect "MultiSource1" pin [0] to "UltrasonicRanger1" Left [0]

  4. Connect "MultiSource1" pin [1] to "UltrasonicRanger1" Left [1]

  5. Connect "MultiSource1" pin [2] to "UltrasonicRanger1" Left [2]

  6. Connect "MultiSource1" pin [3] to "UltrasonicRanger1" Right [0]

  7. Connect "MultiSource1" pin [4] to "UltrasonicRanger1" Right [1]

  8. Connect "MultiSource1" pin [5] to "UltrasonicRanger1" Right [2]

  9. Connect "UltrasonicRanger1" pin [Out] to "CompareRange1" pin [In]

  10. Connect "UltrasonicRanger1" LED pin [Out] to Arduino digital pin [2]

  11. 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 project. You can download it and open it in Visuino: https://www.visuino.com

Download Visuino file: Ultrasonic-rus04-rgb.visuino

Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.