Espressif ESP32-WROOM-32
ESP32 Ultrasonic Distance Meter
개요
An offline, breadboard-friendly ESP32 distance meter featuring an HC-SR04 ultrasonic sensor, an I2C 16x2 LCD, and a unit-switching push button powered via USB.
시스템 아키텍처
- POWER_USB → MCU_ESP32USBPowers the ESP32 module and provides programming/serial debugging interface.
- POWER_USB → SENSOR_ULTRASONICPowerSupplies 5V power rail directly to the HC-SR04 VCC pin.
- POWER_USB → DISPLAY_I2CPowerSupplies 5V power rail to the I2C LCD backpack.
- MCU_ESP32 → SENSOR_ULTRASONICGPIOSends 10us trigger pulse to start ultrasonic measurement.
- SENSOR_ULTRASONIC → LEVEL_SHIFTERGPIOSends 5V echo pulse out of sensor into resistor divider.
- LEVEL_SHIFTER → MCU_ESP32GPIODelivers safe 3.3V scaled echo pulse to ESP32 digital input.
- MCU_ESP32 → DISPLAY_I2CI2CI2C communication bus for driving the 16x2 LCD.
- MCU_ESP32 → USER_INPUTGPIODigital input with internal pull-up resistor sensing button presses.
자재 명세서(BOM)
| 부품 번호 | 유형 | 부품 | 제조사 | 패키지 | 수량 | 데이터시트 | 매칭 |
|---|---|---|---|---|---|---|---|
| TYPE-C-31-M-12 | POWER | USB-C Power Input Provides 5V input power from USB source and distributes to VIN/5V rail. | 韩国韩荣 | — | 1 | 매칭됨 | |
| ESP32-WROOM-32 | MCU | Espressif ESP32-WROOM-32 Main dual-core microcontroller handling distance calculation, display updating, and button polling. | Espressif Systems | Reel | 1 | 매칭됨 | |
검토된 대체품 2개 보기projects.detail.aiVerified | |||||||
| HC-SR04 | SENSOR | HC-SR04 Ultrasonic Sensor Measures distance by emitting a 40 kHz ultrasonic burst and measuring echo return time. | OSEPP Electronics LTD | Retail Package | 1 | 매칭됨 | |
| RC0603FR-071KL | MISC | Resistor Voltage Divider (1k / 2k) Steps down the 5V HC-SR04 Echo signal to a safe 3.3V logic level for the ESP32 input. | Yageo | 0603 (1608 Metric) | 1 | 매칭됨 | |
| I2C | DISPLAY | HD44780 16x2 LCD with PCF8574T I2C Backpack Displays measured distance values in centimeters or inches. | HGSEMI / Texas Instruments / NXP | — | 1 | 대기중 | |
검토된 대체품 3개 보기projects.detail.aiVerified | |||||||
| TS-1187A-B-A-B | ACTUATOR | Momentary Tactile Push Button Allows user to toggle display units between centimeters and inches. | XKB Connection | SMD | 1 | 매칭됨 | |
조립 가이드
Procurement & Preparation
- Gather all Bill of Materials components including the TYPE-C-31-M-12 USB-C port, ESP32-WROOM-32 module, HC-SR04 ultrasonic sensor, RC0603FR-071KL resistors for the voltage divider, I2C 16x2 LCD backpack, and TS-1187A-B-A-B momentary push button.
- Prepare the half-size breadboard, hookup jumper wires, and ensure a clean, well-lit workbench with a regulated 5V USB power source.
Hardware Assembly & Wiring
- Mount the ESP32-WROOM-32 module onto the center divider of the breadboard and connect the USB-C power input board (TYPE-C-31-M-12) to supply 5V and GND to the breadboard power rails.
- Wire the HC-SR04 ultrasonic sensor by connecting its VCC and GND to the 5V rail, linking GPIO12 to the TRIG pin, and routing the ECHO pin through the 1k/2k resistor voltage divider (RC0603FR-071KL) to safely step down the signal to 3.3V for ESP32 GPIO13.
- Connect the HD44780 16x2 LCD with PCF8574T I2C backpack by wiring VCC and GND to 5V/GND, SDA (GPIO21), and SCL (GPIO22).
- Install the TS-1187A-B-A-B momentary tactile push button on the breadboard with one side connected to GPIO4 and the other side tied to GND, utilizing the ESP32 internal pull-up resistor.
Firmware Setup
- Install the Arduino IDE, add the ESP32 board support package, and install required libraries including 'LiquidCrystal_I2C' for the display backpack.
- Write and upload the firmware script that initializes GPIO12 as TRIG output, GPIO13 as ECHO input, configures I2C on GPIO21/22 for the LCD, and polls GPIO4 with internal pull-up enabled for unit switching (Centimeters vs Inches).
Testing & Calibration
- Power the assembled device via the USB-C cable and verify that the I2C LCD lights up and displays the default distance measurement screen.
- Test distance calculation accuracy by placing objects at known distances (e.g., 10cm, 50cm, 100cm) in front of the HC-SR04 sensor and comparing readings against a tape measure.
- Press the TS-1187A-B-A-B push button to verify reliable toggling of measurement units between centimeters and inches on the 16x2 LCD interface.
문서
ESP32 Ultrasonic Distance Meter
An offline, breadboard-friendly ESP32 distance meter featuring an HC-SR04 ultrasonic sensor, an I2C 16x2 LCD, and a unit-switching push button powered via USB.
Design Overview
| Item | Details |
|---|---|
| Product Type | ESP32 Distance Meter |
| Key Functions | Measure distance using an ultrasonic sensor (HC-SR04), Display distance measurements on a 16x2 I2C LCD, Switch between centimetres and inches via push button |
| Power Source | USB-C 5V |
| Connectivity | |
| Size | Modular setup on a breadboard or perfboard |
| Environment | indoor |
| Difficulty | Beginner |
| Est. Time | 3-5 hours |
System Architecture
Power Topology: USB-C 5V supplies the main VIN rail, powering the HC-SR04 and I2C LCD directly at 5V, while the internal voltage regulator of the ESP32 module drops 5V to 3.3V for internal logic, GPIOs, and the push button circuit.
Module List
| Module ID | Type | Name | Function | Voltage |
|---|---|---|---|---|
| POWER_USB | POWER | USB-C Power Input | Provides 5V input power from USB source and distributes to VIN/5V rail. | 5V |
| MCU_ESP32 | MCU | Espressif ESP32-WROOM-32 | Main dual-core microcontroller handling distance calculation, display updating, and button polling. | 3.3V |
| SENSOR_ULTRASONIC | SENSOR | HC-SR04 Ultrasonic Sensor | Measures distance by emitting a 40 kHz ultrasonic burst and measuring echo return time. | 5V |
| LEVEL_SHIFTER | MISC | Resistor Voltage Divider (1k / 2k) | Steps down the 5V HC-SR04 Echo signal to a safe 3.3V logic level for the ESP32 input. | 3.3V |
| DISPLAY_I2C | DISPLAY | HD44780 16x2 LCD with PCF8574T I2C Backpack | Displays measured distance values in centimeters or inches. | 5V |
| USER_INPUT | ACTUATOR | Momentary Tactile Push Button | Allows user to toggle display units between centimeters and inches. | 3.3V |
Design Schemes
Standard ESP32 with Level Shifter Scheme ★
Utilizes a classic ESP32 development module powered directly by USB-C 5V, stepping down to 3.3V for logic. HC-SR04 operates on 5V VCC with a resistive divider on the Echo pin to protect the 3.3V ESP32 GPIO. A 16x2 I2C LCD and a tactile push button connect to the 3.3V rail.
Trade-offs: Balanced cost and reliability; requires discrete level shifting components for the 5V ultrasonic sensor.
Key IC selection
Main dual-core microcontroller handling Wi-Fi/BLE capability, GPIO polling, timing for ultrasonic echo, and I2C display updates.
- Need: Provide dual-core processing, precise hardware timers for ultrasonic pulse width measurement, and I2C/GPIO interfaces.
- Class: Wi-Fi + BLE Microcontroller Module
- Shortlist: Espressif ESP32-WROOM-32, Espressif ESP32-C3-MINI-1
- Pick: Select ESP32-WROOM-32 for robust community support, ample 38 GPIOs, and integrated flash.
Non-contact distance measurement using 40kHz acoustic waves.
- Need: Measure distances from 2cm to 400cm with low cost and reliable TTL trigger/echo interface.
- Class: Ultrasonic Ranging Module
- Shortlist: HC-SR04, JSN-SR04T
- Pick: Select HC-SR04 standard module for low cost and direct 5V compatibility matching the USB rail.
Visual feedback interface for distance values and unit status.
- Need: Display 2 rows of 16 characters using minimal microcontroller pins.
- Class: Character LCD with I2C I/O Expander Backpack
- Shortlist: 16x2 LCD + PCF8574T module, 16x2 LCD + MCP23017 module
- Pick: Select standard 1602 LCD fitted with PCF8574T I2C backpack for 2-wire SDA/SCL interfacing.
Risk register
| ID | Area | Severity | Detail | Mitigation |
|---|---|---|---|---|
| r1 | firmware | high | The HC-SR04 Echo pin outputs a 5V logic high signal proportional to distance. Connecting it directly to the 3.3V tolerant ESP32 GPIO via a simple resistor divider can experience ringing or overshoot that damages the pin during transients. | Verify resistor values (1k/2k) properly clamp the voltage below 3.3V under load, and consider adding a fast 3.3V Zener diode clamp on the ESP32 input pin for extra transient protection. |
| r2 | power | med | HC-SR04 requires a strict 5V supply to operate reliably and transmit adequate ultrasonic acoustic power, but the ESP32 operates at 3.3V and does not feature an on-board 5V boost/step-down converter from a single supply unless driven directly by USB VBUS. | Ensure POWER_USB feeds 5V directly to the HC-SR04 and a suitable LDO (like AMS1117-3.3 or RT9013) steps down the 5V rail to power the ESP32 module safely. |
| r3 | firmware | med | Blocking pulseIn() calls used for measuring HC-SR04 echo duration can interfere with FreeRTOS task scheduling or WiFi/BLE background stacks if running concurrently on the ESP32. | Implement non-blocking distance measurement using ESP32 hardware pulse counters (PCNT) or GPIO Interrupts with microsecond timestamps. |
Key Components
5/6 modules matched to real parts. See the BOM tab for the full component table.
USB-C Power Input (TYPE-C-31-M-12)
The candidate matches the primary MPN TYPE-C-31-M-12 exactly.
Espressif ESP32-WROOM-32 (ESP32-WROOM-32)
Candidate 1 (ESP32-WROOM-32) is an exact match for the primary MPN and preferred manufacturer Espressif Systems.
HD44780 16x2 LCD with PCF8574T I2C Backpack (I2C)
Rejected weak/wrong-class catalog hits; using web recommendation: I2C
Build Summary
- Difficulty: Beginner
- Estimated time: 3-5 hours
- Tools required: Anti-static mat, Breadboard, Jumper wires, Wire strippers, Multimeter, Computer
See the Build tab for the full step-by-step assembly guide.
Generated by YuanQi AI Design System · Query: ESP32 distance meter with an ultrasonic sensor (e.g. HC-SR04), a 16x2 LCD (I2C), and a push button to switch between centimetres and inches