Documente Academic
Documente Profesional
Documente Cultură
Verannie Q. Alcantara
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.
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
REFERENCES
[1]
[2]
[3]
[4]
[5]
[6] K.
[7] , 1989.