Autonomous Vehicle Project2
Autonomous Vehicle Project2
Project Overview
The Autonomous Vehicle Project utilizes an Arduino-based
system to build a vehicle capable of detecting and avoiding
obstacles in its path using ultrasonic sensors. This project
demonstrates fundamental principles of robotics and
embedded systems, providing insights into autonomous
navigation.
Objectives
To develop a vehicle that can autonomously navigate and
avoid obstacles.
To implement ultrasonic sensing technology for distance
measurement.
To integrate motor control and servo mechanism for
directional adjustments.
Components Required
1. Arduino Uno
2. Motor Driver Module (e.g., L298N)
3. 2 x DC Motors
4. 2 x Wheels
5. 1 x Caster Wheel
6. Ultrasonic Sensor (HC-SR04)
7. Servo Motor (for direction checking)
8. Jumper Wires
9. Breadboard
10. Power Supply (Battery)
Wiring Configuration
Motor Driver and DC Motors
1. Connect the DC Motors to the Motor Driver Module.
2. Connect the Motor Driver to the Arduino:
o IN1 to Digital Pin 2
o IN2 to Digital Pin 3
o IN3 to Digital Pin 4
o IN4 to Digital Pin 5
o ENA to Digital Pin 6 (for speed control)
o ENB to Digital Pin 7 (for speed control)
Ultrasonic Sensor Connections
VCC to Arduino 5V
GND to Arduino GND
TRIG to Digital Pin 8
ECHO to Digital Pin 9
Servo Motor Connection
Signal pin to Digital Pin 10 (or any other available pin)
VCC and GND to the respective power supply
Wiring Diagram
(Include a visual diagram here showing the connections
between the components.)
Arduino Code
#include <Servo.h>
#define trigPin 8
#define echoPin 9
#define motorA1 2
#define motorA2 3
#define motorB1 4
#define motorB2 5
#define ENA 6
#define ENB 7
#define servoPin 10
Servo myServo; // Create a servo object
void setup() {
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(motorA1, OUTPUT);
pinMode(motorA2, OUTPUT);
pinMode(motorB1, OUTPUT);
pinMode(motorB2, OUTPUT);
pinMode(ENA, OUTPUT);
pinMode(ENB, OUTPUT);
void loop() {
long duration, distance;
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
delay(100); // Small delay for stability
}
void moveForward() {
digitalWrite(motorA1, HIGH);
digitalWrite(motorA2, LOW);
digitalWrite(motorB1, HIGH);
digitalWrite(motorB2, LOW);
analogWrite(ENA, 255); // Max speed
analogWrite(ENB, 255); // Max speed
}
void stop() {
digitalWrite(motorA1, LOW);
digitalWrite(motorA2, LOW);
digitalWrite(motorB1, LOW);
digitalWrite(motorB2, LOW);
}
void turnLeft() {
// Implement left turn
myServo.write(0); // Adjust servo position for left
delay(500); // Wait for the turn
moveForward(); // Move forward again after turning
}
void turnRight() {
// Implement right turn
myServo.write(180); // Adjust servo position for right
delay(500); // Wait for the turn
moveForward(); // Move forward again after turning
}
Final Notes
1. Ensure all components are properly connected before
powering the Arduino.
2. Adjust the distance threshold in the code according to
your sensor's range.
3. Test the vehicle in a safe environment to evaluate its
obstacle avoidance capabilities.
Conclusion
This project demonstrates the ability to create a simple yet
effective autonomous vehicle using readily available
components and basic programming skills. The integration of
ultrasonic sensors for distance measurement and motor control
allows for practical applications in robotics and autonomous
systems.