Ece 416 - Microprocessor System With Programming Finals Obstacle Avoiding Car

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Republic of the Philippines

Batangas State University


College of Engineering, Architecture, and Fine Arts
Electrical and Computer Engineering Department

ECE 416 – MICROPROCESSOR SYSTEM WITH PROGRAMMING


FINALS
Obstacle Avoiding Car

Submitted by:
Canubas, Brendalyn P.
Dalisay, Derick John M.
Quizon, Christian Joebert E.
EE - 5101

Submitted to:
Engr. Mark John Fel T. Rayos

December 15, 2018


I. Objectives
This laboratory activity aims
 To familiarize the students about the uses and features of Arduino Uno, including
the functions of different codes and delays, to be encoded in the device through
the use of Arduino Software.
 To assemble a car kit with ultrasonic sensors and servo motor
 To encode codes that will make the car kit function and move as desired pattern
sequence and avoid any obstacles that may come its way.

II. Materials
Below are the materials used in making the activity.

Figure 1. Arduino Uno Figure 2. Car Kit (Chassis parts and


motors)

Figure 3. AA Batteries Figure 4. Connecting Wires


Figure 5. Ultrasonic Sensor Figure 6. Servo Motor

III. Procedures
Here are the logical step by step procedures in making the activity.
1. Assemble all the chassis parts and attach the motors to the wheels (if not already
assembled).
2. Connect the red wire from the battery enclosure to Vin on the motor shield.
3. Connect the black wire from the battery enclosure to GND on the motor shield.
4. Connect the red wire from motor A to motor A+ on the motor shield, and the black
wire from motor A to A- on the motor shield.
5. Connect the red wire from motor B to B+ on the motor shield, and the black wire from
motor B to B- on the motor shield.
6. Attach the motor shield to the top of the Arduino Uno board. Be careful not to bend or
damage any of the pins.
7. Connect the Arduino Uno board to the computer via the USB cable and upload the
codes using the Arduino IDE software.
8. Insert four AA batteries in the battery enclosure.
9. Attach the servo motor and the ultrasonic sensor in front of the car kit. Make codes that
will command the car kit to avoid any obstacle that may come its way. Upload the codes to the
Arduino Uno.
9. Test your robot. Check if the motor pins are in the right places and make sure that no
pins are loose.

IV. Circuit Diagram


V. Pattern Sequence

VI.Codes
#include <Servo.h> delay(100);
#include <NewPing.h> distance = readPing();
delay(100);
const int LeftMotorForward = 4; }
const int LeftMotorBackward = 5;
const int RightMotorForward = 6; void loop()
const int RightMotorBackward = 7; {
int distanceRight = 0;
#define TRIGGER_PIN A1 int distanceLeft = 0;
#define ECHO_PIN A2 delay(50);
#define MAX_DISTANCE 250
if (distance <= 20)
Servo servo_motor {
NewPing sonar(TRIGGER_PIN, moveStop();
ECHO_PIN, MAX_DISTANCE);
delay(300);
moveBackward();
boolean goesForward = false;
delay(400);
int distance = 100;
moveStop();
delay(300);
void setup()
distanceRight = lookRight();
{
delay(300);
pinMode(RightMotorForward, OUTPUT);
distanceLeft = lookLeft();
pinMode(LeftMotorForward, OUTPUT);
delay(300);
pinMode(LeftMotorBackward, OUTPUT);

if (distanceRight >= distanceLeft)


pinMode(RightMotorBackward,OUTPUT);
{
turnRight();
servo_motor.attach(10);
delay(300);
servo_motor.write(115);
moveStop();
delay(2000);
distance = readPing();
}
delay(100);
else
distance = readPing();
{
delay(100);
turnLeft();
distance = readPing();
delay(300);
moveStop(); int cm = sonar.ping_cm();
} if (cm==0)
{
} cm=250;
else }
{ return cm;
moveForward(); }
}
void moveStop()
distance = readPing(); {
} digitalWrite(RightMotorForward, LOW);
digitalWrite(RightMotorBackward, LOW);
int lookRight() digitalWrite(LeftMotorForward, LOW);
{ digitalWrite(LeftMotorBackward, LOW);
servo_motor.write(50); }
delay(500);
int distance = readPing(); void moveForward()
delay(100); {
servo_motor.write(115); digitalWrite(RightMotorForward, HIGH);
return distance; digitalWrite(RightMotorBackward,
LOW);
}
digitalWrite(LeftMotorForward, HIGH);
digitalWrite(LeftMotorBackward, LOW);
int lookLeft()
}
{
servo_motor.write(180);
void moveBackward()
delay(500);
{
int distance = readPing();
digitalWrite(RightMotorForward, LOW);
delay(100);
digitalWrite(RightMotorBackward,HIGH);
servo_motor.write(115);
digitalWrite(LeftMotorForward, LOW);
return distance;
digitalWrite(LeftMotorBackward, HIGH);
}
}

int readPing()
void turnRight()
{
{
delay(100);
digitalWrite(RightMotorForward, LOW); {
digitalWrite(RightMotorBackward,HIGH); digitalWrite(RightMotorForward, HIGH);
digitalWrite(LeftMotorForward, HIGH); digitalWrite(RightMotorBackward, LOW);
digitalWrite(LeftMotorBackward, LOW); digitalWrite(LeftMotorForward, LOW);
} digitalWrite(LeftMotorBackward, HIGH);
}
void turnLeft()

VII. Conclusion
In this laboratory, the aim is to create an obstacle avoiding car which detects the obstacle
in his path and navigate according to the actions we set for it. This obstacle avoiding car was
designed and implemented with Arduino Uno microcontroller. Experimental work has been
carried out carefully.
Ultrasonic sensors were also used in this project to detect the obstacle in the way. The
ultrasonic sensor is attached in front of the car and it help the car navigate smoothly through
obstacle. The operation of the obstacle avoiding car is set through by having the car moved
forward direction. When an electrical pulse of high voltage is applied to the ultrasonic
transducer, it vibrates across a spectrum of frequencies and generates a burst of sound waves.
Whenever any obstacle comes ahead of the sensor, the waves will reflect back in the form of
echo and generates an electric pulse. It will allow the car to detect the obstacle in its path.
The codes for the Arduino were set by the students and help them familiarize the use and
functions of different components. This activity help the students to do different task and
programming in the future.

VII. Actual Photos

Figure 7. Actual Robotic Car Kit


Figure 8 and 9. Robotic Car Kit Avoiding Obstacles

You might also like