0% found this document useful (0 votes)
53 views5 pages

Autonomous Vehicle Project2

Uploaded by

charanreddy2908
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views5 pages

Autonomous Vehicle Project2

Uploaded by

charanreddy2908
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Autonomous Vehicle Project

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);

myServo.attach(servoPin); // Attach the servo to the defined pin


}

void loop() {
long duration, distance;

// Trigger the ultrasonic sensor


digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);


distance = duration * 0.034 / 2; // Distance in cm

// Check distance and adjust movement


if (distance < 10) { // If an obstacle is detected within 10 cm
stop(); // Stop the vehicle
turnLeft(); // Optionally, implement a turn
} else {
moveForward(); // Move forward
}

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.

You might also like