ESP32 Tutorial 32/55 - Car Reverse Range Waring with LCD and buzzer | SunFounder's IoT Learning kit
In this tutorial, we will create a reversing aid system using the ESP32 microcontroller, an ultrasonic distance sensor, an LCD display, and a buzzer. This project will alert you to the distance from obstacles while reversing, with the buzzer's beeping frequency changing based on how close the obstacle is. You will learn how to wire the components, write the code, and expect the functionality of the system to work effectively for your vehicle.
As we implement this project, the ESP32 will handle the sensor readings and control the buzzer and LCD display. The ultrasonic sensor will measure the distance to any obstacles, while the buzzer will provide audio feedback based on that distance. The LCD will display the measured distance, allowing you to see the readings in real-time. For a clearer understanding of the setup, be sure to watch the video (in video at 00:00).
Hardware Explained
The key components in this project include the ESP32 microcontroller, an ultrasonic distance sensor, an LCD display, and a buzzer. The ESP32 is a powerful microcontroller with built-in Wi-Fi and Bluetooth capabilities, making it ideal for IoT projects. The ultrasonic sensor measures distances by emitting sound waves and calculating the time taken for the echo to return. The LCD will display the distance measured, while the buzzer provides audible alerts based on proximity.
Each component plays a crucial role in ensuring that the reversing aid functions correctly. Understanding how these parts work together will help you troubleshoot any issues that may arise during the build process. The project leverages the ESP32's processing power to manage sensor data and control outputs effectively.
Datasheet Details
| Manufacturer | Espressif Systems |
|---|---|
| Part number | ESP32 |
| Logic/IO voltage | 3.3 V |
| Supply voltage | 5 V (max) |
| Output current (per channel) | 40 mA |
| Peak current (per channel) | 160 mA |
| PWM frequency guidance | 1 kHz - 40 kHz |
| Input logic thresholds | 0.3 VCC (low), 0.7 VCC (high) |
| Voltage drop / RDS(on) / saturation | 0.2 V (typ.) |
| Thermal limits | Operating temperature: -40°C to 85°C |
| Package | QFN48 |
| Notes / variants | Various ESP32 modules available |
- Ensure proper power supply to avoid damage.
- Use a resistor with the buzzer to limit current.
- Keep signal wires short to reduce interference.
- Use pull-up resistors if necessary for digital inputs.
- Be cautious of the ultrasonic sensor's maximum range.
Wiring Instructions

To wire the components for the project, start by connecting the ultrasonic sensor. Connect the VCC pin of the sensor to the 5V power line and the GND pin to the ground. The Trig pin should be connected to pin 26 on the ESP32, and the Echo pin should be connected to pin 25.
Next, wire the buzzer by connecting its positive lead to pin 14 on the ESP32 and the negative lead to ground. For the LCD, connect the VCC pin to the 5V line and the GND pin to ground. The SDA and SCL pins of the LCD should be connected to pins 21 and 22, respectively. Ensure that all connections are secure to avoid any disconnections during operation.
Code Examples & Walkthrough
In the code, you will find key identifiers like distance, which stores the measured distance from the ultrasonic sensor. This variable is updated continuously in the loop to reflect the current distance. The buzzer's pin is defined as buzzerPin, allowing easy control of its state.
const int triggerPin = 26; // Trigger pin for ultrasonic sensor
const int echoPin = 25; // Echo pin for ultrasonic sensor
const int buzzerPin = 14; // Buzzer pin
These constants are defined at the beginning of the code for clarity and ease of adjustment. The trigger and echo pins are used to communicate with the ultrasonic sensor, while the buzzer pin controls the sound output.
void setup() {
pinMode(triggerPin, OUTPUT); // Set trigger pin as output
pinMode(echoPin, INPUT); // Set echo pin as input
pinMode(buzzerPin, OUTPUT); // Set buzzer pin as output
}
In the setup() function, we configure the pin modes for the ultrasonic sensor and the buzzer. This ensures that the ESP32 can correctly interact with the hardware components during operation.
void loop() {
distance = readDistance(); // Call function to read distance
if (distance <= 10) {
beep(100); // Fast beep for close distance
} else if (distance <= 20) {
beep(500); // Medium beep for moderate distance
} else {
beep(2000); // Slow beep for safe distance
}
}
The loop() function continuously reads the distance and adjusts the buzzer's beeping frequency based on the value. The beep() function is called with different intervals depending on how close the obstacle is.
Demonstration / What to Expect
Once everything is connected and the code is uploaded, you can expect the system to beep at different intervals based on the distance to an obstacle. When the distance is less than 10 cm, the buzzer will beep rapidly, while distances greater than 50 cm will result in a slow beep. Make sure to test the system by placing your hand in front of the ultrasonic sensor to see the changes in distance readings and corresponding beeping rates (in video at 12:30).
Video Timestamps
- 00:00 Start
- 2:08 Introduction and docs
- 4:12 Wiring Explained
- 13:17 Arduino Code
- 21:01 Selecting ESP32 Board and COM port in Arduino IDE
- 22:48 Demo in the lab
- 24:54 Demo on the car
Common Course Links
Common Course Files
|||您可能需要的东西
-
亚马逊Purchase LCD1602-I2C from Amazonamzn.to
-
易趣Purchase LCD1602-I2C from eBayebay.us
-
全球速卖通Purchase 10pcs LCD1602-I2C from AliExpresss.click.aliexpress.com
-
全球速卖通Purchase LCD1602-I2C from AliExpresss.click.aliexpress.com
资源与参考
-
文档ESP32 Tutorial 32/55- SunFounder doc page for reversing aiddocs.sunfounder.com
文件📁
Fritzing 文件
-
LCD2004-I2C
LCD2004-I2C.fzpz0.02 MB