+21622886281
ESP32 HC-SR04

Control the HC-SR04 Ultrasonic sensor with ESP32

Purpose of this tutorial:

In this tutorial we will learn how to use an HC-SR04 reference ultrasonic distance sensor with the ESP32 board.

Necessary components

  • ESP32
  • HC-SR04 sensor
  • SSD1306 display
  • connecting wires

  • Test plate

Mounting

The assembly is disconcertingly simple:

For HC-SR04 sensor :

  • The 3.3V power supply from the ESP32 board goes to the VCC pin of the sensor.

  • The GND pin of the ESP32 board goes to the GND pin of the sensor.

  • Pin D5 of the ESP32 board goes to the TRIGGER pin of the sensor.

  • Pin D18 of the ESP32 board goes to the ECHO pin of the sensor.

For SSD1306 display:

  • the SCL pin to pin D22 of the ESP32 board

  • the VCC pin to the 3.3V pin of the ESP32 board

  • the GND pin to the GND pin of the ESP32 board

  • the SDA pin the D21 pin of the ESP32 card

Micropython program

Here is the program that displays the distance in cm that separates the ultrasonic sensor from an obstacle.

 

Note: the following two libraries must be imported: hcsr04 and ssd1306




0 commentaire


Leave a comment

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Scroll to Top