Maker.io main logo

Ultrasonic Distance Sensor Using ATOM Matrix ESP32

2023-04-12 | By M5Stack

License: General Public License Wifi Arduino

* Thanks for the source code and project information provided by @ronfrtek

Things used in this project

Hardware components

M5Stack ATOM Matrix ESP32 Development Kit×1

SparkFun Ultrasonic Sensor - HC-SR04×1

Jumper wires (generic)×1

Software apps and online services

Arduino IDE

Visuino

Story

 

 

 
Step 1: What You Will Need
  • ATOM Matrix ESP32
  • HC-SR04 Ultrasonic Range Measurement Module
  • Jumper wires
  • Visuino program: Download Visuino

Step 2: The Circuit

2

 
  • Connect Ultrasonic sensor pin [VCC] to Atom Matrix pin [5V]
  • Connect Ultrasonic sensor pin [GND] to Atom Matrix pin [GND]
  • Connect Ultrasonic sensor pin [Trig] to Atom Matrix pin [G21]
  • Connect Ultrasonic sensor pin [ECHO] to Atom Matrix pin [G25]

Step 3: Start Visuino, and Select the Atom Matrix Board Type

1

1

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 "Atom Matrix" as shown on Picture 2

Step 4: In Visuino Add Components

1

2

3

4

 

  • Add "Ultrasonic Ranger" component
  • Add "Compare Analog Value" component
  • Add "Detect Edge" component
  • Add "Color Value" component

Step 5: In Visuino Set Components

1

2

3

4

5

6

7

8

  • Select "M5 Stack ATOM Matrix" board in the properties window expand "Modules">"RGB Matrix">"Elements" and click on the 3 dots button
  • In the "Elements" window drag "Fill Screen" to the left side and in the properties window select "Color" and click on the Pin Icon and select "Alpha Color SinkPin"
  • Close the "Elements" window
  • Select "CompareValue" and in the properties window select "Compare Type" to ctBigger and "Value" to 5 <<this is the distance to detect obstacle, you can adjust this number if you want
  • Select "DetectEdge1" and in the properties window set "Rising" to False
  • Double click on the "ColorValue1" and in the Elements window :
    • drag "Set Value" to the left side and in the properties window set "Color" to clGreen
    • drag another "Set Value" to the left side and in the properties window set "Color" to clRed
    • Close the Elements window

Step 6: In Visuino Connect Components

e

2

  • Connect "M5 Stack ATOM Matrix" pin [GPIO 25] to "UltrasonicRanger1" pin [Echo]
  • Connect "UltrasonicRanger1" pin[Ping] to "M5 Stack ATOM Matrix" pin [GPIO 21]
  • Connect "UltrasonicRanger1" pin[Out] to "CompareValue1" pin [In]
  • Connect "CompareValue1" pin [Out] to "DetectEdge1" pin [In]
  • Connect "CompareValue1" pin [Out] to "ColorValue1" > "Set Value1" pin [In]
  • Connect "DetectEdge1" pin [Out] to "ColorValue1" > "Set Value2" pin [In]
  • Connect "ColorValue1" pin [Out] to "M5 Stack ATOM Matrix" > "Fill Screen1" pin [Color]
  • Connect "ColorValue1" pin [Out] to "M5 Stack ATOM Matrix" > "Fill Screen1" pin [Clock]

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

 8

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

If you power the ATOM Matrix module The Display will start to show Green color and you can put an obstacle in front of the Ultrasonic module the display will show a Red color.

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.eu

 

制造商零件编号 C008-B
ATOM MATRIX ESP32 DEV KIT
M5Stack Technology Co., Ltd.
制造商零件编号 U098-B1
ULTRASONIC DISTANCE UNIT I2C
M5Stack Technology Co., Ltd.
制造商零件编号 SEN-15569
ULTRASONIC DISTANCE SENSOR - HC-
SparkFun Electronics
Add all DigiKey Parts to Cart
TechForum

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

Visit TechForum