You are on page 1of 11

QUEZON CITY UNIVERSITY

673 Quirino Highway ,San Bartolome, Novaliches, Quezon City


Electronic Engineering

DOCUMENTATION
IN COMPUTER PROGRAMMING
(Avoidance Robot)

DAD BOT
Submitted By: Jade B. Bermas
SECTION: SBECE-1A
Submitted to: Prof. Joselito Trinidad MTE
QUEZON CITY UNIVERSITY
673 Quirino Highway ,San Bartolome, Novaliches, Quezon City
Electronic Engineering

I. Objectives:

1.Aims to gain knowledge about sensors


2.Builds a strong foundation about how the ultrasonic senser works.
3.Able to program basic C-language.
4.Aims to accomplish an autonomous robot that can drive itself.
5.Build knowledge about motors.
6.To have a better knowledge about Arduino and its capabilities.
7.To gain experiences about building and creating different designs of this
project.
8.Have a background about motor drivers and how it works.
9.To able to identify the differences of l293d motor shield to H-bridge motor
controller.
10.Learn to create ideas that will helps the project.
11.Learn the proper costing for the materials of the project.
12.Learn how to build a self-driving car that can drive using li-ion battery.

II. Description:
This avoidance robot has a concept of an insect called firefly In Filipino, as
you can see in the picture every time when we are starting this robot it has a color red
backlight, helps to easily identify this thing in dark places. This avoidance robot name
was DADBOT the reason behind this name was because since I am a father of one,
some of my friends calling me daddy that’s why I think I should start to put the word
DADDY into my projects because it’s easy to Identify that this thing is one of my
creations.
This avoidance robot has a length around 30 cm and a with around 15cm and a
height around 10 cm, it contains 2 gear motor and one cartwheel in the outside and the
controller that I choose to run the motor was l293d motor shield for Arduino Uno, and
also it 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 Li-ion that formed into parallel connection
to have a durable and long-lasting use, and I choose to use some step-up inverter so I
can increase the given voltages of this robot into the needed voltage to run this thing.
QUEZON CITY UNIVERSITY
673 Quirino Highway ,San Bartolome, Novaliches, Quezon City
Electronic Engineering
III. Flow Chart:

a c
b

start

Delay(100)
Delay(200)

If distance==25

Int Distance=Read If
distanc distanceR>=distanceL
e=0 ping
Delay(300)
Turn
Turn Left
RIght
Delay(100)
Int Move stop Move
speed Forward
set= 0
Distance= Read
Ping
Delay(200)
End

My
servo Delay(100)
=10
Distance
R= look
Right
Int
My servo
distanc
write=115
e R=0
Delay(200)

Delay(2000) Int
distanc
e L=0
Distance L=
look Left

Distance=read ping
Delay(40)

c
a b
QUEZON CITY UNIVERSITY
673 Quirino Highway ,San Bartolome, Novaliches, Quezon City
Electronic Engineering

IV. Code: (C/C++)

1. #include <AFMotor.h
2. #include <NewPing.h>
3. #include <Servo.h

4. #define TRIG_PIN A0
5. #define ECHO_PIN A1
6. #define MAX_DISTANCE 200
7. #define MAX_SPEED 150
8. #define MAX_SPEED_OFFSET 20

9. NewPing sonar(TRIG_PIN, ECHO_PIN, MAX_DISTANCE);

10. AF_DCMotor motor1(1, MOTOR12_);


11. AF_DCMotor motor2(2, MOTOR12_);
12. Servo myservo;

13. boolean goesForward=false;


14. int distance = 100;
15. int speedSet = 0;

16. void setup() {

17. myservo.attach(10);
18. myservo.write(115);
19. delay(2000);
20. distance = readPing();
21. delay(100);
22. distance = readPing();
23. delay(100);
24. distance = readPing();
25. delay(100);
26. distance = readPing();
27. delay(100);
28. }

29. void loop() {


30. int distanceR = 0;
31. int distanceL = 0;
32. delay(40);

33. if(distance<=20)
34. {
35. moveStop();
36. delay(100);
37. moveBackward();
38. delay(300);
39. moveStop();
40. delay(200);
41. distanceR = lookRight();
42. delay(200);
43. distanceL = lookLeft();
44. delay(200);

45. if(distanceR>=distanceL)
46. {
47. turnRight();
48. moveStop();
49. }else
50. {
51. turnLeft();
52. moveStop();
53. }
54. }else
55. {
56. moveForward();
57. }
58. distance = readPing();
59. }

60. int lookRight()


61. {
62. myservo.write(50);
63. delay(500);
64. int distance = readPing();
65. delay(100);
66. myservo.write(115);
67. return distance;
68. }

69. int lookLeft()


70. {
71. myservo.write(170);
72. delay(500);
73. int distance = readPing();
74. delay(100);
75. myservo.write(115);
76. return distance;
77. delay(100);
78. }

79. int readPing() {


80. delay(70);
81. int cm = sonar.ping_cm();
82. if(cm==0)
83. {
84. cm = 250;
85. }
86. return cm;
87. }

88. void moveStop() {


89. motor1.run(RELEASE);
90. motor2.run(RELEASE);
91. }

92. void moveForward() {

93. if(!goesForward)
94. {
95. goesForward=true;
96. motor1.run(FORWARD);
97. motor2.run(FORWARD);
98. for (speedSet = 0; speedSet < MAX_SPEED; speedSet +=2)
99. {
100. motor1.setSpeed(speedSet);
101. motor2.setSpeed(speedSet);
102. delay(5);
103. }
104. }
105. }

106. void moveBackward() {


107. goesForward=false;
108. motor1.run(BACKWARD);
109. motor2.run(BACKWARD);
110. for (speedSet = 0; speedSet < MAX_SPEED; speedSet +=2)
111. {
112. motor1.setSpeed(speedSet);
113. motor2.setSpeed(speedSet);
114. delay(5);
115. }
116. }

117. void turnRight() {


118. motor1.run(FORWARD);
119. motor2.run(BACKWARD);
120. delay(450);
121. motor1.run(FORWARD);
122. motor2.run(FORWARD);
123. }

124. void turnLeft() {


125. motor1.run(BACKWARD);
126. motor2.run(FORWARD);
127. delay(450);
128. motor1.run(FORWARD);
129. motor2.run(FORWARD);

130. }
QUEZON CITY UNIVERSITY
673 Quirino Highway ,San Bartolome, Novaliches, Quezon City
Electronic Engineering

V. Schematic:
QUEZON CITY UNIVERSITY
673 Quirino Highway ,San Bartolome, Novaliches, Quezon City
Electronic Engineering

VI. Pictures:
Materials Quantity Cost = Peso
Gear motor 2 60.00

Arduino Motor Shield 1 80.00

Servo Motor 1 120.00

Ultrasonic Sensor 1 30.00

Jumper wires 1 set 60.00

LED 1 0.00

Battery (Li-ION) 4 20.00

TP56 1 35.00

Step-up voltage 1 35.00


inverter
Card Board 3 0.00

Glue 1 set 50.00

Popsicle Sticks 1 set 15.00

Foam Tape 1 roll 30.00

Switch 1 13.00

Spray Paint (Black) 1 0.00


Arduino UNO 1 0.00

TOTAL: 548.00
QUEZON CITY UNIVERSITY
673 Quirino Highway ,San Bartolome, Novaliches, Quezon City
Electronic Engineering

VII. Costing/Materials:
QUEZON CITY UNIVERSITY
673 Quirino Highway ,San Bartolome, Novaliches, Quezon City
Electronic Engineering

VIII. Reflection:

This project thought me many things first, whenever what happens always
challenge yourself to be better, second, imagination and creativity is the key to
accomplish all the problems that you will encounter during and after you finish to
innovate this project, lastly, we have different kinds of ideas and it can be same
program but it can be different on how we innovate and present it.
At start I always ask myself on how and where do I start, because how can I
make things at my own? And then I realized that I am not alone because I have friends
and a very good professor that will guide me at my journey to accomplished this
programmable robot, I am very glad that I experience this thing’s because I know to my
self that it can help me for the near future and I believed that as long I make mistake’s I
have chance to be a better student and programmer.

You might also like