https://github.com/gitutk/obstacle-avoiding-robot
This Arduino code utilizes an ultrasonic sensor to measure distances. When an object is detected within a fix distance , the connected motors trigger a sequence: move backward, turn right, turn left, then move forward. Motor control is achieved using the AFMotor library, and the distance calculation is based on the sensor's pulse duration.
https://github.com/gitutk/obstacle-avoiding-robot
arduino l293d obstacle-avoidance obstacle-avoidance-robot obstacle-detection ultrasonic-sensor
Last synced: 3 months ago
JSON representation
This Arduino code utilizes an ultrasonic sensor to measure distances. When an object is detected within a fix distance , the connected motors trigger a sequence: move backward, turn right, turn left, then move forward. Motor control is achieved using the AFMotor library, and the distance calculation is based on the sensor's pulse duration.
- Host: GitHub
- URL: https://github.com/gitutk/obstacle-avoiding-robot
- Owner: GitUtk
- License: mit
- Created: 2023-11-07T11:56:16.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-04-12T13:23:55.000Z (about 1 year ago)
- Last Synced: 2025-07-01T16:13:12.302Z (11 months ago)
- Topics: arduino, l293d, obstacle-avoidance, obstacle-avoidance-robot, obstacle-detection, ultrasonic-sensor
- Language: C++
- Homepage:
- Size: 3.83 MB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Award Winning Obstacle Avoidance Robot

## Description
This Arduino code implements an object avoidance mechanism using an ultrasonic sensor and a four-wheeled robot with individual motors. When an object is detected within 15 cm, the robot performs a predefined sequence: it moves backward, turns right, turns left, and then moves forward. Motor control is facilitated through the AFMotor library, while the distance calculation relies on the pulse duration from the ultrasonic sensor.
## Components Used
- Ultrasonic Sensor
- AFMotor Library
- Motor Shield
- Four DC Motors (M1, M2, M3, M4)
- Arduino Board
## Circuit Setup


1. Connect the ultrasonic sensor's trigPin to A2 and echoPin to A3 on the Arduino.
2. Connect the four DC motors to the motor controller, assigning each to motorM1, motorM2, motorM3, and motorM4.
3. Ensure the AFMotor library is installed in your Arduino IDE.
## How It Works
The Arduino continuously measures the distance using the ultrasonic sensor. When an object is detected within 15 cm, it triggers a sequence of movements to avoid the obstacle: move backward, turn right, turn left, and then move forward. Motor speed and direction are controlled through the AFMotor library.
## Usage
1. Upload the provided code to your Arduino board.
2. Ensure the hardware setup is correct.
3. Power up the robot.
4. Observe the robot's behavior in response to obstacles within its detection range.
Note: Adjustments to motor speeds and delay times can be made in the code to optimize performance for your specific robot.
Feel free to contribute by forking the repository and submitting pull requests.
## License
This project is licensed under the [MIT License](LICENSE).