Sunteți pe pagina 1din 3

ELC151.

2 Laboratory Activity 1: Mobot Open and


Close Loop System
Post-laboratory Report; Submitted: 2 September 2016

Verannie Q. Alcantara

Aija Nette R. Cruz

Electronics, Computer, and Communications Engineering


Ateneo de Manila University
Philippines
verannie.alcantara@obf.ateneo.edu

Electronics, Computer, and Communications Engineering


Ateneo de Manila University
Philippines
aija.cruz@obf.ateneo.edu

Abstract This paper explains how to create a shot clock with the
use of an Arduino, an open-source prototyping platform with both
hardware and software, and a 7-segment display shield, a ----. The
researchers used the Arduino software (IDE) to create a program
that counts down from 24 seconds and stops when it reaches 00.
Not only that, another goal was to integrate the two switches from
the 7-segment shield in the shot clock in a way that when switch 1
is pressed, it will stop/start the clock and when switch 2 is pressed,
it will reset the clock back to 24 seconds.

cmd1(250,1,150,1); //turn right


delay(200);
cmd1(255,1,255,1); //forward
delay(2000);
cmd1(200,1,150,1); //turn right
delay(200);
cmd1(255,1,255,1); //forward
delay(1000);
cmd1(250,1,150,1); //turn right
delay(200);
cmd1(255,1,255,1); //forward
delay(1000);
cmd1(150,1,250,1); //turn left
delay(400);
cmd1(255,1,255,1); //forward
delay(1500);
cmd1(150,1,250,1); //turn left
delay(200);

I. PROGRAM LISTING
Open Loop System
int i;
int run1 = 9; // 0 to 255, 255 = max, 0 = stop
int run2 = 10;
int dir1 = 8;
int dir2 = 11;
int LS1, LS2, LS3, col1, col2, col3;
void setup() {
//Serial.begin(9600);
for(i=2; i <=7;i=i+1)
pinMode(i, INPUT); //sensors
for(i=8; i <=11;i=i+1) {
pinMode(i, OUTPUT); //motor control
}
delay(10);
//stop motors
for(i=8; i <=11;i=i+1)
digitalWrite(i,LOW);
}
void loop() { //main routine here
//cmd1(int speed1, int mydir1, int speed2, int mydir2 )
cmd1(255,1,255,1); //forward
delay(1000);

}
void cmd1(int speed1, int mydir1, int speed2, int mydir2 ) {
// motor1
digitalWrite(dir1,mydir1); //direction control of motor1, 1
= forward
analogWrite(run1,speed1); //speed control of motor1, 0
=stop, 255 =fastest
// motor2
digitalWrite(dir2,mydir2); //direction control of motor2, 1
= forward
analogWrite(run2,speed2); //speed control of motor2, 0
=stop, 255 =fastest
}
Close Loop System

int i;
int run1 = 9; // 0 to 255, 255 = max, 0 = stop
int run2 = 10; // 0 to 255, 255 = max, 0 = stop
int dir1 = 8;
int dir2 = 11;
int LS1, LS2, LS3;
void setup() {
//Serial.begin(9600);
for(i=2; i <=7;i=i+1)
pinMode(i, INPUT); //sensors
for(i=8; i <=11;i=i+1) {
pinMode(i, OUTPUT); //motor control
}
delay(10);
//stop motors
for(i=8; i <=11;i=i+1)
digitalWrite(i,LOW);
}
void loop() { //main routine here
//cmd1(int speed1, int mydir1, int speed2, int mydir2 )
readsensor();
if(LS3==HIGH&&LS1==HIGH&&LS2==LOW)
{
cmd1(150,1,150,1); //forward
}
else
if((LS3==HIGH&&LS2==LOW&&LS1==LOW)||
(LS3==HIGH&&LS2==HIGH&&LS1==LOW))
{
cmd1(200,0,200,1);//right
}
else
if((LS1==HIGH&&LS3==LOW&&LS2==LOW)||
(LS1==HIGH&&LS2==HIGH&&LS3==LOW))
{
cmd1(200,1,200,0);//left
}
else
if(LS1==HIGH&&LS2==HIGH&&LS3==HIGH)
{
cmd1(150,1,150,1);//forward
}
}
else
{

cmd1(0,0,0,0); //stop
}
}

//functions here
void readsensor() {
LS1 = digitalRead(5);
LS2 = digitalRead(6);
LS3 = digitalRead(7);
}
void cmd1(int speed1, int mydir1, int speed2, int
mydir2 ) {
// motor1
digitalWrite(dir1,mydir1); //direction control of
motor1, 1 = forward
analogWrite(run1,speed1); //speed control of motor1,
0 =stop, 255 =fastest
// motor2
digitalWrite(dir2,mydir2); //direction control of
motor2, 1 = forward
analogWrite(run2,speed2); //speed control of motor2,
0 =stop, 255 =fastest
}
void viewsensor() { //main routine here
readsensor();
Serial.print(LS1);
Serial.print(" ");
Serial.print(LS2);
Serial.print(" ");
Serial.println(LS3);
Serial.println();
delay(250);
}
II. DESIGN PROCESS AND DISCUSSION
In this laboratory activity, a mobot was utilized through the
use of Arduino and Arduino IDE. The goal was to run the
mobot in an open and close loop. For the open loop, the mobot
had to pass a certain length while moving forward in a straight
direction. As for the close loop, the mobot had to pass the same
length by tracing a black straight line through the use of the
light sensors.

For both programs, the first set of lines in the code provides
that declaration of the pin outputs of the motors. The integer dir
was for the direction while run was for the speed. Dir1 and
run1 corresponds to pins 8 and 9 respectively. These were
assigned to the left part of the motor control. On the other
hand, dir2 and run2 were assigned to pins 11 and 10
respectively. These were used for the right part of the motor
control. It was important to note that the maximum speed of
the mobot was 255. Consequently, a value of zero for the run
integer will make the mobot to stop.
As for the next set of codes, the setup just shows the pin
assignments for sensors and motors. Values of i between two
and seven were assigned to the sensors as inputs while values
of i from 8 to 11 were assigned to the motor control as outputs.
Open Loop
For this part of the activity, the goal was basically to
program the mobot to move forward in a straight direction.
One major challenge with this was the uncertainty of the
movement of the mobot. Hence, the researchers initially
programmed the mobot to move forward for a certain delay.
With that, the behavior of the robot was observed. Since after a
certain period of moving forward the mobot had the tendency
to move towards the left, a following ine of code was added
which prompted the mobot to move towards the right for a
short delay. This was done to realign the orientation of the
mobot. This was done for a couple of times. After a certain
delay, the mobot then moved towards to the right. Another line
of code was added to realign the mobot by changing the
movement towards the left. After a couple of tries, the
researchers were successful in programming the mobot to
move forward in a straight direction.
Close Loop
As for the close loop part, the goal was to create aa
program that would trace the black line detected by the light
sensors connected to the mobot. The most essential part of the
code is located in the loop segment. The code followed the
format cmd1(int speed1, int mydir1, int speed2, int mydir2 ).
The mobot consisted of three light sensors: LS1 located on the
left, LS2 on the middle and LS3 on the right. The first if
statement considers the situation when both LS3 and LS1 are
high, thus, implying that the mobot is parallel to the line. In
this case, the mobot was programmed to move forward with a
speed of 150. The second if statement implies that the mobot is
oriented towards the left for cases when both LS2 and LS3 or
just LS3 detects a black line. Hence, the mobot should align

itself by moving to the right with a speed of 200. On the other


hand, when both LS2 and LS1 or just LS1 detects a black line,
then it means that the mobot is tilted to the right. It then
follows that the mobot should move to the left with a speed of
200. As for the fourth if statement, when all of the sensors
detect the black line, then it must also move forward
considering that its orientation is correct. Lastly, if the given
conditions are not satisfied, then the mobot must stop moving.
The following segment of the code is for assigning the
values of the direction and the speed to their corresponding pin
assignments either in motor 1 or motor 2. The value in mydir1
is assigned to dir1 which relates to pin 8. The value of speed1
is assigned to run1 which corresponds to pin 9. The value of
mydir2 is assigned to dir2 which links to pin 11 while the value
of speed2 is assigned to run2 which was for pin 10. The last
segment of the code is just for the reading the values of the
light sensors.
With these, it was observed that the mobot programmed in
open loop was faster than that of close loop. One compelling
reason for this was the fact that in close loop, the mobot had to
interpret the input data from the light sensors whenever a black
line is detected before executing the code. In contrast to that,
the mobot in an open loop basically just executes the code.
III. CONCLUSION AND RECOMMENDATION
The researchers were successful in creating a mobot that
performs as a line tracer. Although it wasnt moving as
smoothly as the researchers wanted it to be, it managed to pass
even the 90 degree angle path that most people are having a
hard time with. Reiterating, the main logic of the code is to
create an action based on which sensors are detecting black
light and which are detecting white light. Aside from this, it
can be concluded that this laboratory activity helped the
researchers understand as to how wide the applications of
coding in Arduino really is.

REFERENCES
[1]
[2]
[3]
[4]
[5]

What Is Arduino In Arduino. n.d. Web. 16 Sep 2015.


Arduino Software (IDE) In Arduino. n.d. Web. 16 Sep 2015.
Arduino Uno In Arduino. n.d. Web. 16 Sep 2015.
Arduino Shields In SparkFun. n.d. Web. 16 Sep 2015.
Line Follower Robots Controlling, Working Principle and
Applications In ElProCus. n.d. Web. 11 Oct 2015.

[6] K.
[7] , 1989.

S-ar putea să vă placă și