https://github.com/bocaletto-luca/obstacle-avoiding-robot
Obstacle-Avoiding-Robot - A two-wheel differential drive rover that roams autonomously, uses an HC-SR04 ultrasonic sensor to detect obstacles ahead, and an MPU-6050 IMU to monitor tilt (prevent tipping). On obstacle detection it stops, reverses, turns randomly left or right, then resumes. If it tilts beyond a safety angle, it immediately halts.
https://github.com/bocaletto-luca/obstacle-avoiding-robot
arduino bocaletto-luca cpp obstacle obstacle-robot openhardware opensource robot standalone
Last synced: about 2 months ago
JSON representation
Obstacle-Avoiding-Robot - A two-wheel differential drive rover that roams autonomously, uses an HC-SR04 ultrasonic sensor to detect obstacles ahead, and an MPU-6050 IMU to monitor tilt (prevent tipping). On obstacle detection it stops, reverses, turns randomly left or right, then resumes. If it tilts beyond a safety angle, it immediately halts.
- Host: GitHub
- URL: https://github.com/bocaletto-luca/obstacle-avoiding-robot
- Owner: bocaletto-luca
- License: gpl-3.0
- Created: 2025-06-12T23:30:53.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-12T23:31:52.000Z (about 1 year ago)
- Last Synced: 2025-06-13T00:33:23.469Z (about 1 year ago)
- Topics: arduino, bocaletto-luca, cpp, obstacle, obstacle-robot, openhardware, opensource, robot, standalone
- Language: C++
- Homepage: https://bocaletto-luca.github.io/
- Size: 18.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Obstacle-Avoiding Robot
**Files**
- `README.md`
- `ObstacleAvoidingRobot.ino`
## 1. Concept
A two-wheel differential drive rover that roams autonomously, uses an HC-SR04 ultrasonic sensor to detect obstacles ahead, and an MPU-6050 IMU to monitor tilt (prevent tipping). On obstacle detection it stops, reverses, turns randomly left or right, then resumes. If it tilts beyond a safety angle, it immediately halts.
**Key Behaviors**
1. **Forward Patrol** at constant speed.
2. **Obstacle Avoidance**:
- If distance < 20 cm ➔ Stop ➔ Reverse ➔ Turn (random) ➔ Resume.
3. **Tilt Safety**:
- If roll or pitch > 30° ➔ Emergency stop.
## 2. Bill of Materials
- 1 × Arduino Uno (or Nano)
- 1 × L298N dual H-bridge motor driver
- 2 × DC gear motors + wheels
- 1 × HC-SR04 ultrasonic distance sensor
- 1 × MPU-6050 6-axis IMU
- Chassis, caster wheel, battery pack (7.4 V Li-ion or 6×AA)
- Jumper wires, solderless breadboard (optional)
## 3. Wiring Diagram
Arduino Uno L298N Motor Driver Motor A
┌──────────────┐ ┌────────────────┐ ┌─────┐
│ D2 ─────► IN1 │──► │ IN1 │──► │ M+ │
│ D3 ─────► IN2 │──► │ IN2 │──► │ M- │
│ D5 (PWM)► ENA │──► │ ENA │
└──────────────┘ └────────────────┘ └─────┘
Arduino Uno L298N Motor Driver Motor B
┌──────────────┐ ┌────────────────┐ ┌─────┐
│ D4 ─────► IN3 │──► │ IN3 │──► │ M+ │
│ D7 ─────► IN4 │──► │ IN4 │──► │ M- │
│ D6 (PWM)► ENB │──► │ ENB │
└──────────────┘ └────────────────┘ └─────┘
HC-SR04:
┌──────────────┐
│ D8 ──► Trig │
│ D9 ──► Echo │
└──────────────┘
MPU-6050 (I²C):
┌──────────────┐
│ A4 ──► SDA │
│ A5 ──► SCL │
│ 5V ──► VCC │
│ GND─► GND │
└──────────────┘
> **Power:** Drive motors from battery pack; power Arduino and sensors from 5 V regulator.
## 4. Software Setup
1. In Arduino IDE install libraries:
- `NewPing` by Tim Eckel
- `I2Cdev` & `MPU6050` (Jeff Rowberg’s I2CdevLib)
2. Create project folder `ObstacleAvoidingRobot` and add both files.
3. Open `ObstacleAvoidingRobot.ino` in Arduino IDE.
4. Select **Arduino Uno** (or Nano) and correct COM port.
## 5. Operation
1. Power on. Robot begins forward at `MOTOR_SPEED`.
2. If obstacle < `DIST_THRESHOLD` cm:
- Stops ➔ reverses `REVERSE_TIME` ms ➔ random turn left/right for `TURN_TIME` ms ➔ resumes.
3. If tilt > `TILT_LIMIT` ° in any axis:
- Immediate full stop. Re-enable by power-cycle.
---
Say **continua** to move on to project #7!