You are on page 1of 10

QUEZON CITY UNIVERSITY

673 QUIRINO HIGHWAY, SAN BARTOLOME, NOVALICHES, QUEZON CITY


BACHELOR OF SCIENCE IN ELECTRONICS ENGINEERING

Documentat
ion in I.
Computer OBJECTIVES

Programmin 1.

g Project
Avoidance
Car (DARK
KNIGHT)

I Submitted by: Earl Alistair Junio


Year&Section: SBECE1A
Submitted to: Joselito A. Trinidad, MTE

want to aim that I can pass the finals in this project.

2. Have experience in developing this type of technology.


QUEZON CITY UNIVERSITY
673 QUIRINO HIGHWAY, SAN BARTOLOME, NOVALICHES, QUEZON CITY
BACHELOR OF SCIENCE IN ELECTRONICS ENGINEERING

3. I can play it to my younger brother, I also plan to install it a bluetooth

module.

4. To be able to program basic C-language.

5. Gain some experiences about building and creating designs to this kind of

project.

6. Learn about how the ultrasonic senser and sensor works.

7. Learn to DIY so the costing of the project will be cheap but the creativity is

there.

II. DESCRIPTION
I named this Avoidance Robot the Dark Knight because I often do it every

night. And in its mala Dark color, also the Knight symbolize that it's my soldier

and I'm the Lord because in the Middle Ages Knights is a man who served his

sovereign or lord as a mounted soldier in armor.

Dark Knight has a length of 29 cm, a width of 17cm and a height of 12 cm. It

contains 4 gear motor with wheels in the outside and the controller I chose to

run the motor was l293d motor shield for Arduino Uno, contains one servo

motor and ultrasonic sensor that indicates the hindrance in its way so that the

robot can easily avoid things that can cause danger. Also, this robot was run

by a 4 pcs of AA Battery that formed into parallel connection to have a durable

but short lasting use, and 1 9v Battery for Arduino Uno.


QUEZON CITY UNIVERSITY
673 QUIRINO HIGHWAY, SAN BARTOLOME, NOVALICHES, QUEZON CITY
BACHELOR OF SCIENCE IN ELECTRONICS ENGINEERING

III. MATERIALS & COSTING


Materials Cost
Servo Motor 86
Motor Drive 85
Male to Male 20pcs 17
Female to Female 20pcs 17
Male to Female 20pcs 17
Sensor Bracket 32
DC Motor w/ Wheels 4pcs 268
4x AA Battery Holder 42
Spray Paint (Black) Free
Card Board 20
Glue 15
Glue Stick 10 pcs 30
Printed Layout 20
4x AA Battery Free
9v Battery Free
Switch 12
TOTAL 661

IV. PICTURES WHILE DOING THE PROJECT


QUEZON CITY UNIVERSITY
673 QUIRINO HIGHWAY, SAN BARTOLOME, NOVALICHES, QUEZON CITY
BACHELOR OF SCIENCE IN ELECTRONICS ENGINEERING

V.

FLOWCHART
QUEZON CITY UNIVERSITY
673 QUIRINO HIGHWAY, SAN BARTOLOME, NOVALICHES, QUEZON CITY
BACHELOR OF SCIENCE IN ELECTRONICS ENGINEERING

VI.

COMPLETE CODE (C/C++)

#include <AFMotor.h>
#include <NewPing.h>
#include <Servo.h>

#define TRIG_PIN A0
#define ECHO_PIN A1
QUEZON CITY UNIVERSITY
673 QUIRINO HIGHWAY, SAN BARTOLOME, NOVALICHES, QUEZON CITY
BACHELOR OF SCIENCE IN ELECTRONICS ENGINEERING
#define MAX_DISTANCE 200
#define MAX_SPEED 190 // sets speed of DC motors
#define MAX_SPEED_OFFSET 20

NewPing sonar(TRIG_PIN, ECHO_PIN, MAX_DISTANCE);

AF_DCMotor motor1(1, MOTOR12_1KHZ);


AF_DCMotor motor2(2, MOTOR12_1KHZ);
AF_DCMotor motor3(3, MOTOR34_1KHZ);
AF_DCMotor motor4(4, MOTOR34_1KHZ);
Servo myservo;

boolean goesForward=false;
int distance = 100;
int speedSet = 0;

void setup() {

myservo.attach(10);
myservo.write(115);
delay(2000);
distance = readPing();
delay(100);
distance = readPing();
delay(100);
distance = readPing();
delay(100);
distance = readPing();
delay(100);
}

void loop() {
int distanceR = 0;
int distanceL = 0;
delay(40);

if(distance<=25)
{
QUEZON CITY UNIVERSITY
673 QUIRINO HIGHWAY, SAN BARTOLOME, NOVALICHES, QUEZON CITY
BACHELOR OF SCIENCE IN ELECTRONICS ENGINEERING
moveStop();
delay(100);
moveBackward();
delay(500);
moveStop();
delay(200);
distanceR = lookRight();
delay(200);
distanceL = lookLeft();
delay(200);

if(distanceR=distanceL)
{
turnRight();
moveStop();
}else
{
turnLeft();
moveStop();
}
}else
{
moveForward();
}
distance = readPing();
}

int lookRight()
{
myservo.write(50);
delay(500);
int distance = readPing();
delay(100);
myservo.write(115);
return distance;
}

int lookLeft()

{
myservo.write(170);
delay(500);
int distance = readPing();
QUEZON CITY UNIVERSITY
673 QUIRINO HIGHWAY, SAN BARTOLOME, NOVALICHES, QUEZON CITY
BACHELOR OF SCIENCE IN ELECTRONICS ENGINEERING
delay(100);
myservo.write(115);
return distance;
delay(100);
}

int readPing() {
delay(70);
int cm = sonar.ping_cm();
if(cm==0)
{
cm = 250;
}
return cm;
}

void moveStop() {
motor1.run(RELEASE);
motor2.run(RELEASE);
motor3.run(RELEASE);
motor4.run(RELEASE);
}

void moveForward() {

if(!goesForward)
{
goesForward=true;
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
for (speedSet = 0; speedSet < MAX_SPEED; speedSet +=2) // slowly bring
the speed up to avoid loading down the batteries too quickly
{
motor1.setSpeed(speedSet);
motor2.setSpeed(speedSet);
motor3.setSpeed(speedSet);
motor4.setSpeed(speedSet);
delay(5);
}
}
}

void moveBackward() {
goesForward=false;
motor1.run(BACKWARD);
motor2.run(BACKWARD);
motor3.run(BACKWARD);
motor4.run(BACKWARD);
QUEZON CITY UNIVERSITY
673 QUIRINO HIGHWAY, SAN BARTOLOME, NOVALICHES, QUEZON CITY
BACHELOR OF SCIENCE IN ELECTRONICS ENGINEERING
for (speedSet = 0; speedSet < MAX_SPEED; speedSet +=2) // slowly bring
the speed up to avoid loading down the batteries too quickly
{
motor1.setSpeed(speedSet);
motor2.setSpeed(speedSet);
motor3.setSpeed(speedSet);
motor4.setSpeed(speedSet);
delay(5);
}
}

void turnRight() {
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(BACKWARD);
motor4.run(BACKWARD);
delay(1500);
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
}

void turnLeft() {
motor1.run(BACKWARD);
motor2.run(BACKWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
delay(1500);
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
}

VII. REFLECTION

While I was doing this project, I experienced a lot, especially the bad ones,

because I ran out of battery several times and damaged other equipment.
QUEZON CITY UNIVERSITY
673 QUIRINO HIGHWAY, SAN BARTOLOME, NOVALICHES, QUEZON CITY
BACHELOR OF SCIENCE IN ELECTRONICS ENGINEERING

Especially the housing construction of this project. But I also learned a lot as I

built it, that nothing is really easy in building something especially when

technology is already involved in it. When the 2nd sem started, I immediately

learned a lot in this subject. Starting with the lighting of led like traffic lights

and rainbow colors in RGB. Counting of Seven Segments with LED. Different

Sensors, until this last project that sir will have us to do. So I am very thankful

again this semester because I have learned so much from my Professor. I am

grateful to those who have been my teachers in all subjects who are

unwavering, tireless and eternally patient for my classmates including QCU

scholars. It can never match anything we received in the first year of study

here at QCU. And as a student I will work hard to fulfill my dreams in life and I

want my former teachers to see me as successful in life. Even in this way, I

can make my teachers smile for the next generation of my life. All the

suffering was for my parents and to all teachers who taught me in my college

life. Thank you very much. I hope that I can pass this sem and I will overcome

all the struggle in the next tasks.

You might also like