Professional Documents
Culture Documents
Documentat
ion in I.
Computer OBJECTIVES
Programmin 1.
g Project
Avoidance
Car (DARK
KNIGHT)
module.
5. Gain some experiences about building and creating designs to this kind of
project.
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
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
V.
FLOWCHART
QUEZON CITY UNIVERSITY
673 QUIRINO HIGHWAY, SAN BARTOLOME, NOVALICHES, QUEZON CITY
BACHELOR OF SCIENCE IN ELECTRONICS ENGINEERING
VI.
#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
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
grateful to those who have been my teachers in all subjects who are
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
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