University of Perpetual Help System Dalta
College of Engineering
           CpE Department
                        CONTROL SYSTEMS LABORATORY
                                 Machine Problem No.6
                                    Motor Controller
I.           OBJECTIVES
          1. To be able to control the direction and speed of a DC motor
          2. To be able to create a program that will control the direction of the dc
          motor based on an ultrasonic sensor.
         Arduino or Genuino Board
         Ultrasonic Sensor
         2 DC Motor
         9V Battery
         Motor Shield
II.          DISCUSSION
BASIC INFORMATION
The Arduino Motor Shield must be powered only by an external power supply.
Because the L298 IC mounted on the shield has two separate power connections,
one for the logic and one for the motor supply driver. The required motor current
often exceeds the maximum USB current rating.
External (non-USB) power can come either from an AC-to-DC adapter (wall-wart)
or battery. The adapter can be connected by plugging a 2.1mm center-positive
plug into the Arduino's board power jack on which the motor shield is mounted or
by connecting the wires that lead the power supply to the Vin and GND screw
terminals, taking care to respect the polarities.
To avoid possible damage to the Arduino board on which the shield is mounted,
we reccomend using an external power supply that provides a voltage between 7
and 12V. If your motor require more than 9V we recommend that you separate
the power lines of the shield and the Arduino board on which the shield is
mounted. This is possible by cutting the "Vin Connect" jumper placed on the back
side of the shield. The absolute limit for the Vin at the screw terminals is 18V.
The power pins are as follows:
Vin on the screw terminal block, is the input voltage to the motor connected to
the shield. An external power supply connected to this pin also provide power to
the Arduino board on which is mounted. By cutting the "Vin Connect" jumper you
make this a dedicated power line for the motor.
GND Ground on the screw terminal block.
Machine Problem No.6 Motor Shield                                                   1
                                                      ENGR. CYD LAURENCE B. SANTOS
        University of Perpetual Help System Dalta
        College of Engineering
        CpE Department
                        CONTROL SYSTEMS LABORATORY
The shield can supply 2 amperes per channel, for a total of 4 amperes maximum.
III.        ACTIVITY
1. Encode the given program. Assign filename sam1.ino
#include <AFMotor.h>
AF_DCMotor motor(1, MOTOR12_64KHZ); // create motor #2, 64KHz pwm
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Motor test!");
motor.setSpeed(200); // set the speed to 200/255
}
void loop() {
Serial.print("tick");
motor.run(FORWARD); // turn it on going forward
delay(1000);
Serial.print("tock");
Machine Problem No.6 Motor Shield                                          2
                                                   ENGR. CYD LAURENCE B. SANTOS
        University of Perpetual Help System Dalta
        College of Engineering
        CpE Department
                        CONTROL SYSTEMS LABORATORY
motor.run(BACKWARD); // the other way
delay(1000);
Serial.print("tack");
motor.run(RELEASE); // stopped
delay(1000);
}
2. Observe and gather the conclusion.
IV.        PICTURE OF THE OUTPUT
Machine Problem No.6 Motor Shield                                 3
                                          ENGR. CYD LAURENCE B. SANTOS
      University of Perpetual Help System Dalta
      College of Engineering
      CpE Department
                  CONTROL SYSTEMS LABORATORY
                       Fig 1. Arduino with DC Motors
V.      SOURCE CODE
Machine Problem No.6 Motor Shield                                    4
                                             ENGR. CYD LAURENCE B. SANTOS
        University of Perpetual Help System Dalta
        College of Engineering
        CpE Department
                     CONTROL SYSTEMS LABORATORY
#include <AFMotor.h>
AF_DCMotor motor1(1, MOTOR12_64KHZ), motor2(2, MOTOR12_64KHZ); // create
motor #2, 64KHz pwm
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Motor test!");
motor1.setSpeed(200); // set the speed to 200/255
motor2.setSpeed(200);
}
void loop() {
Serial.print("tick");
motor1.run(FORWARD); // turn it on going forward
delay(1000);
Serial.print("tock");
motor1.run(BACKWARD); // the other way
delay(1000);
Serial.print("tack");
motor1.run(RELEASE); // stopped
delay(1000);
Serial.print("tick");
motor2.run(FORWARD); // turn it on going forward
delay(1000);
Serial.print("tock");
motor2.run(BACKWARD); // the other way
delay(1000);
Serial.print("tack");
motor2.run(RELEASE); // stopped
delay(1000);
}
VI.        OBSERVATION
In this laboratory activity, we are tasked to use motor shield and DC
motors. First, since motor shield is an Arduino shield, we installed it
Machine Problem No.6 Motor Shield                                          5
                                                   ENGR. CYD LAURENCE B. SANTOS
       University of Perpetual Help System Dalta
       College of Engineering
       CpE Department
                   CONTROL SYSTEMS LABORATORY
into the Arduino, next is by using jumping wires we connected the
DC motor into the motor #1 and motor #2 in the motor shield.
Lastly, when it comes to the code the source code was already
given but it needs a tweak because we were using two DC motors,
we just simply declare that there are two dc motors in use
(motor1(1, MOTOR12_64KHZ), motor2(2, MOTOR12_64KHZ)).
VII.     CONCLUSION
In conclusion, the reason why we used motor shield is because it
has its own power input, it allows us to use higher amounts of
current and wider range of voltages since DC motors runs at 6V
to12V which is not provided by the Arduino. The other advantage is
Machine Problem No.6 Motor Shield                              6
                                       ENGR. CYD LAURENCE B. SANTOS
      University of Perpetual Help System Dalta
      College of Engineering
      CpE Department
                  CONTROL SYSTEMS LABORATORY
that it is has an easier interface, making the wiring simple and
eliminating the use of breadboard. When it comes to the output it is
also the same as the last laboratory activity but this time, we’re
using DC motors instead of servo motors.
Machine Problem No.6 Motor Shield                                7
                                        ENGR. CYD LAURENCE B. SANTOS