Ultrasonic Sensor Hc-sr04 & Led Indicator Module & Visuino

About the project

In this tutorial we will learn how to use LED Indicator Module & HC-SR04Ultrasonic sensor with Arduino and Visuino. Watch the video!

Project info

Difficulty: Easy

Platforms: ArduinoVisuino

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
Arduino UNO Wifi Rev.2 Arduino UNO Wifi Rev.2 x 1
LED Indicator Module (with a common ground) LED Indicator Module (with a common ground) x 1
Ultrasonic Sensor - HC-SR04 (Generic) Ultrasonic Sensor - HC-SR04 (Generic) x 1

Software apps and online services

Arduino IDE Arduino IDE
Visuino Visuino

Story

The closer the obstacles are to the sensor the more LEDs will glow.

Step 1: What You Will Need

1 / 5

  • LED Indicator Module (with a common ground)Link or here

Here we are using a module with 6 LEDs, if you will use a module with more LEDs you might need to connect it to other digital pins or use a breadboard

  • HC-SR04 Ultrasonic sensor
  • Arduino UNO or Arduino Mega (or any other board)
  • Visuino program: Download Visuino
  • Jumper wires

Step 2: The Circuit

For module with 6 LEDs: Put the module on the Arduino board digital pins [8, 9, 10, 11, 12, 13, GND]

  • D6 > digital pin [8]
  • D5 > digital pin [9]
  • D4 > digital pin [10]
  • D3 > digital pin [11]
  • D2 > digital pin [12]
  • D1 > digital pin [13]
  • GND > pin [GND]

If you are using a module with more LEDs you might need to use other digital pins or connect it to the breadboard.

  • 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 Board Type

1 / 2

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

1 / 4

  • Add "LED Bar Display" component and in the properties window set "Bars Output Pins" to 6 <<Number of LEDs on the module
  • Add "Ultrasonic Ranger" component
  • Add "Analog To Integer" component
  • Add "Map Range Analog" component

"Map Range Analog" component will transform our distance from the ultrasonic sensor to the number of LEDs

  • Select "MapRange1" and in the properties window set "Input Range" > "Max" to 20 <<this means that we will monitor the distance from 0 cm to 20 cm
  • and "Output Range" > "Max" to 5 <<this is the number of LEDs (0-5), if you are using 8 LEDs module then set it to 7

To change the LED direction select "LEDBarDisplay1" and in the properties window set "Inverted Bars" to True

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] "MapRange1" pin [In]
  • Connect "MapRange1" pin [Out] "AnalogToInteger1" pin [In]
  • Connect "AnalogToInteger1" pin [Out] to "LEDBarDisplay1" pin [In]
  • Connect "LEDBarDisplay1" pin [0] to Arduino digital pin [8]
  • Connect "LEDBarDisplay1" pin [1] to Arduino digital pin [9]
  • Connect "LEDBarDisplay1" pin [2] to Arduino digital pin [10]
  • Connect "LEDBarDisplay1" pin [3] to Arduino digital pin [11]
  • Connect "LEDBarDisplay1" pin [4] to Arduino digital pin [12]
  • Connect "LEDBarDisplay1" pin [5] to Arduino digital pin [13]

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 indicator module 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...