https://github.com/qantrex/syt-radar
Radar Scanner with Esp32
https://github.com/qantrex/syt-radar
Last synced: 2 months ago
JSON representation
Radar Scanner with Esp32
- Host: GitHub
- URL: https://github.com/qantrex/syt-radar
- Owner: Qantrex
- License: mit
- Created: 2025-01-14T09:44:13.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2025-01-14T10:10:42.000Z (4 months ago)
- Last Synced: 2025-01-14T11:30:39.097Z (4 months ago)
- Language: Python
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ESP32 Radar System with Ultrasonic Sensor and Servo Motor
## **Overview**
This project implements a radar-like system using an **ESP32 microcontroller**, an ultrasonic sensor, a servo motor, and a speaker. The servo motor sweeps the ultrasonic sensor across a range of angles, measuring distances and displaying them on the serial monitor. A speaker provides auditory feedback for each measurement.
---
## **Components Used**
1. **Ultrasonic Sensor (HC-SR04)**
- Emits ultrasonic waves to measure distances based on the echo return time.2. **Servo Motor**
- Rotates the ultrasonic sensor, enabling a sweeping motion (0° to 180°).3. **Speaker (Buzzer)**
- Emits a beep for each distance measurement.4. **ESP32 Board**
- Controls the components and processes the logic.---
## **Pin Connections**
| Component | ESP32 Pin |
|--------------------|---------------|
| Ultrasonic Trig | GPIO 9 |
| Ultrasonic Echo | GPIO 8 (via Voltage Divider) |
| Servo Signal | GPIO 10 |
| Speaker Positive | GPIO 3 |> **Note:** Use a voltage divider with 10kΩ and 20kΩ resistors to step down the ultrasonic sensor’s Echo pin output from 5V to 3.3V to protect the ESP32.
---
## 📐 **Circuit Diagram**
Below is the circuit diagram for connecting the components:

> **Tip:** Use an external 5V power supply for the servo motor to avoid overloading the ESP32’s power regulator.
---
## **Arduino Code Overview**
The Arduino code controls the radar system by:
- Initializing the servo motor, ultrasonic sensor, and speaker.
- Moving the servo from 0° to 180° and back in 2° increments.
- Measuring the distance to nearby objects using the ultrasonic sensor at each angle.
- Logging the measured distance and angle to the serial monitor.
- Providing auditory feedback through the speaker for each measurement.---
## **Python Visualization Script**
A Python script is included to visualize the radar data using a graphical radar display. The script connects to the ESP32 via a serial port and creates a 180-degree radar visualization using **Pygame**.
### Key Features:
1. **Serial Data Reading**:
- Reads angle and distance data from the ESP32 via the specified serial port.
- Filters out-of-range data for a cleaner display.2. **Graphical Radar Display**:
- Displays a sweeping radar with a half-circle grid.
- Plots detected objects as red dots based on their angle and distance.
- Includes a dynamic sweeping line to simulate radar motion.3. **Concurrency**:
- Uses threading to read data and update the display simultaneously.### Python Script Highlights:
- **Dependencies**: Ensure `pygame` and `pyserial` are installed using:
```bash
pip install pygame pyserial
```- **Execution**: Update the serial port in the script (e.g., `COM5`) and run:
```bash
python radar_display.py
```- **Code Example**:
```python
for angle, distance in read_serial_data(port):
if 0 <= distance <= max_distance:
radar_data.append((angle, distance))
```---
## **How It Works**
1. **Initialization**:
- The radar system initializes the servo motor, ultrasonic sensor, and speaker.2. **Sweeping Motion**:
- The servo motor rotates the ultrasonic sensor between 0° and 180°, scanning for objects.3. **Distance Measurement**:
- At each angle, the ultrasonic sensor measures the distance to nearby objects and logs it to the serial monitor.4. **Visualization**:
- The Python script visualizes the radar data in real time on a Pygame display.---
## 🖥**Serial Output Example**
```
Radar System Initialized
Angle: 0, Distance: 50.23
Angle: 2, Distance: 48.00
Angle: 4, Distance: Out of Range
...
```---
## **Repository Content**
- **`radar.ino`**: Arduino sketch for the radar system.
- **`radar.py`**: Python script for visualizing radar data.
- **`README.md`**: Project documentation.---
## **Demo**
Will look similar to this Demo done by [Coders Cafe](https://www.youtube.com/@CodersCafeTech/shorts).
The Demo: !
---
## **License**
This project is licensed under the MIT License. See `LICENSE` for details.
---
## **Contact**
For questions or suggestions, reach out at [[email protected]](mailto:[email protected]).