Arduino and ESP32-Based Ultrasonic Distance Measurement System
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary of the Circuit
This circuit integrates an Arduino UNO microcontroller board with an HC-SR04 Ultrasonic Sensor and an ESP32 Devkit V1 microcontroller. The Arduino UNO is used as the primary controller, interfacing with the ultrasonic sensor to measure distances. The ESP32 Devkit V1 is connected to the Arduino UNO for additional processing power or connectivity options. The power lines of the ESP32 and the Arduino are interconnected, and the ground lines are shared across all components to establish a common reference point. The HC-SR04 sensor is powered by the Arduino and sends trigger and echo signals to it. Serial communication is established between the ESP32 and the Arduino through the RX2 and TX2 pins of the ESP32 and the D0 and D1 pins of the Arduino, respectively.
Component List
Arduino UNO
- Microcontroller board based on the ATmega328P
- It has 14 digital input/output pins, 6 analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header, and a reset button.
HC-SR04 Ultrasonic Sensor
- An ultrasonic distance sensor capable of measuring distances from 2cm to 400cm with an accuracy of 3mm.
- It has four pins: VCC, TRIG, ECHO, and GND.
ESP32 Devkit V1
- A powerful microcontroller with Wi-Fi and Bluetooth capabilities.
- It has a wide variety of pins including digital I/O, analog inputs, UART, SPI, I2C, and more.
Wiring Details
Arduino UNO
- 3.3V connected to ESP32 Devkit V1 (3V3)
- 5V connected to HC-SR04 Ultrasonic Sensor (VCC)
- GND connected to ESP32 Devkit V1 (GND) and HC-SR04 Ultrasonic Sensor (GND)
- D9 connected to HC-SR04 Ultrasonic Sensor (TRIG)
- D8 connected to HC-SR04 Ultrasonic Sensor (ECHO)
- D1 connected to ESP32 Devkit V1 (RX2)
- D0 connected to ESP32 Devkit V1 (TX2)
HC-SR04 Ultrasonic Sensor
- VCC connected to Arduino UNO (5V)
- TRIG connected to Arduino UNO (D9)
- ECHO connected to Arduino UNO (D8)
- GND connected to Arduino UNO (GND)
ESP32 Devkit V1
- 3V3 connected to Arduino UNO (3.3V)
- GND connected to Arduino UNO (GND)
- RX2 connected to Arduino UNO (D1)
- TX2 connected to Arduino UNO (D0)
Documented Code
Arduino UNO Code (sketch.ino)
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
Note: The code provided for the Arduino UNO is a template and does not contain any functional code for interacting with the HC-SR04 Ultrasonic Sensor or the ESP32 Devkit V1. To make this circuit operational, the user must implement the setup and loop functions with the necessary initialization and logic.
ESP32 Devkit V1 Code
No code was provided for the ESP32 Devkit V1.
Note: To fully utilize the ESP32 Devkit V1, code must be written and uploaded to the microcontroller. This code would typically initialize the device, set up communication protocols, and define the logic for any tasks the ESP32 is intended to perform in conjunction with the Arduino UNO.