0% found this document useful (0 votes)
27 views

Module 3 Actuators

Uploaded by

tipkou3007
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Module 3 Actuators

Uploaded by

tipkou3007
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Robotics and Sensory Technology - Actuators

 Actuator is a device which is used to actuate a process.

 Actuate is to operate the process.

• Switching devices
 mechanical switches, eg. relay
 solid state switches, eg diodes, thyristors and transistors
 app – switch on or off electrical devices
• Solenoids – type of devices used to actuate valves of hydraulic and pneumatic
systems. (flow control)

• Drive systems – DC motor, AC motor and stepper motor.

Types of Electrical Actuators

 Motor
o DC motor
o Geared
o Servo
o Stepper Motor
• Unipolar
• Bipolar
 Solenoid

DC MOTOR
 A motor using either generated or rectified D.C. power.
 A DC motor is usually used when variable speed operation is required.
 DC motor speed generally depends on a combination of the voltage and current flowing
in the motor coils and the motor load or braking torque.
 The speed of the motor is proportional to the voltage, and the torque is proportional to
the current.
 The speed is typically controlled by altering the voltage or current flow by using taps
in the motor windings or by having a variable voltage supply.
 Reversing the polarity of the power supply will reverse the direction of rotation.
1
Page
Robotics and Sensory Technology - Actuators

DC Motor Driver Using SPDT Relay

L293D Dual Reversible Motor Driver

Specifications

Truth Table
2
Page
Robotics and Sensory Technology - Actuators

Motor Speed Variation

Example No.1
/*
Input 1  Pin 5
Input 2  Pin 6
Enable  Pin 9
*/
#define Input1 5
#define Input2 6
#define Enable 9
#define sw1 digitalRead(2)
#define sw2 digitalRead(3)
void setup() {
pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(Input1, OUTPUT);
pinMode(Input2, OUTPUT);
pinMode(Enable, OUTPUT);
}
void loop() {
if ((sw1 == LOW) && (sw2 == LOW)){
// FAST MOTOR STOP
digitalWrite(Input1, LOW);
digitalWrite(Input2, LOW);
digitalWrite(Enable, HIGH);
}
else if ((sw1 == LOW) && (sw2 == HIGH)){
// FORWARD
digitalWrite(Input1, LOW);
digitalWrite(Input2, HIGH);
3

digitalWrite(Enable, HIGH);
Page

} else if ((sw1 == HIGH) && (sw2 == LOW)){


Robotics and Sensory Technology - Actuators

// REVERSE
digitalWrite(Input1, HIGH);
digitalWrite(Input2, LOW);
digitalWrite(Enable, HIGH);
} else {
// FREE RUNNING MOTOR STOP
// digitalWrite(Input1, LOW);
// digitalWrite(Input2, LOW);
digitalWrite(Enable, LOW);
}
}

Example 2
/*
Input 1  Pin 5
Input 2  Pin 6
Enable  Pin 9 PWM
*/

#define Input1 5
#define Input2 6
#define Enable 9
#define sw1 digitalRead(2)
#define sw2 digitalRead(3)
void setup() {
pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(Input1, OUTPUT);
pinMode(Input2, OUTPUT);
pinMode(Enable, OUTPUT);
}
void loop() {
if ((sw1 == LOW) && (sw2 == LOW)){
// FAST MOTOR STOP
digitalWrite(Input1, LOW);
digitalWrite(Input2, LOW);
analogWrite(Enable, 255);//High
}
else if ((sw1 == LOW) && (sw2 == HIGH)){
// FORWARD
digitalWrite(Input1, LOW);
digitalWrite(Input2, HIGH);
4

analogWrite(Enable, 128);// 50% Duty Cycle


Page

} else if ((sw1 == HIGH) && (sw2 == LOW)){


Robotics and Sensory Technology - Actuators

// REVERSE
digitalWrite(Input1, HIGH);
digitalWrite(Input2, LOW);
analogWrite(Enable,255*0.75);// 75% Duty Cycle
} else {
// FREE RUNNING MOTOR STOP
digitalWrite(Input1, LOW);
digitalWrite(Input2, LOW);
analogWrite(Enable, 0);//Low
}
}

Stepper Library
This library allows you to control unipolar or bipolar stepper motors. To use it you will need a
stepper motor, and the appropriate hardware to control it.
Circuits for Unipolar Stepper Motors
Two Pins Four Pins

5
Page
Robotics and Sensory Technology - Actuators

Circuit for Bipolar Stepper Motor


Two Pins

Four Pins

6
Page
Robotics and Sensory Technology - Actuators

Stepper(steps, pin1, pin2)


Stepper(steps, pin1, pin2, pin3, pin4)

Description
This function creates a new instance of the Stepper class that represents a particular stepper
motor attached to your Arduino board. Use it at the top of your sketch, above setup() and loop().
The number of parameters depends on how you've wired your motor - either using two or four
pins of the Arduino board.

Parameters
steps: the number of steps in one revolution of your motor. If your motor gives the number of
degrees per step, divide that number into 360 to get the number of steps (e.g. 360 / 3.6 gives 100
steps). (int)
pin1, pin2: two pins that are attached to the motor (int)
pin3, pin4: optional the last two pins attached to the motor, if it's connected to four pins (int)
Returns
A new instance of the Stepper motor class.
Example
Stepper myStepper = Stepper(100, 5, 6);

Stepper: setSpeed(rpms)

Description
Sets the motor speed in rotations per minute (RPMs). This function doesn't make the motor turn,
just sets the speed at which it will when you call step().
Parameters
rpms: the speed at which the motor should turn in rotations per minute - a positive number (long)

Stepper: step(steps)

Description
Turns the motor a specific number of steps, at a speed determined by the most recent call to
setSpeed(). This function is blocking; that is, it will wait until the motor has finished moving to
pass control to the next line in your sketch. For example, if you set the speed to, say, 1 RPM and
called step(100) on a 100-step motor, this function would take a full minute to run. For better
control, keep the speed high and only go a few steps with each call to step().
Parameters
steps: the number of steps to turn the motor - positive to turn one direction, negative to turn the
other (int)
7
Page
Robotics and Sensory Technology - Actuators

Example No.1:
#include <Stepper.h>

const int stepsPerRevolution = 200; /* change this to fit the


number of steps per revolution for your motor*/

// initialize the stepper library on pins 8 through 11:


Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

void setup() {
myStepper.setSpeed(60); // set the speed at 60 rpm:
Serial.begin(9600); // initialize the serial port:
}

void loop() {
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
delay(500);

Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution);
delay(500);
}

Example No.2:
#include <Stepper.h>

#define STEPS 100 // 360deg/3.6deg/step = 100 steps


Stepper stepper(STEPS, 8, 9, 10, 11);

int previous = 0; // the previous reading from the analog input

void setup() {
stepper.setSpeed(30); //set the speed of the motor to 30 RPMs
}
void loop() {
int val = analogRead(A0); // get the sensor value
stepper.step(val - previous);
previous = val;
8

}
Page
Robotics and Sensory Technology - Actuators

Servo library
This library allows an Arduino board to control servo motors. Servos have integrated gears and
a shaft that can be precisely controlled. Standard servos allow the shaft to be positioned at
various angles, usually between 0 and 180 degrees. Continuous rotation servos allow the rotation
of the shaft to be set to various speeds.

attach()

Description
Attach the Servo variable to a pin.
Syntax
servo.attach(pin)
servo.attach(pin, min, max)

Parameters
servo: a variable of type Servo
pin: the number of the pin that the servo is attached to
min (optional): the pulse width, in microseconds, corresponding to the minimum (0-degree)
angle on the servo (defaults to 544)
max (optional): the pulse width, in microseconds, corresponding to the maximum (180-degree)
angle on the servo (defaults to 2400)
Example
#include <Servo.h>
Servo myservo;
void setup()
{
myservo.attach(9);
}
void loop() {}

write()

Description
Writes a value to the servo, controlling the shaft accordingly. On a standard servo, this will set
the angle of the shaft (in degrees), moving the shaft to that orientation. On a continuous
rotation servo, this will set the speed of the servo (with 0 being full-speed in one direction, 180
being full speed in the other, and a value near 90 being no movement).
9

Syntax
Page

servo.write(angle)
Robotics and Sensory Technology - Actuators

Parameters
servo: a variable of type Servo
angle: the value to write to the servo, from 0 to 180
Example
#include <Servo.h>
Servo myservo;
void setup()
{
myservo.attach(9);
myservo.write(90); // set servo to mid-point
}
void loop() {}

writeMicroseconds()

Description
Writes a value in microseconds (uS) to the servo, controlling the shaft accordingly. On a standard
servo, this will set the angle of the shaft. On standard servos a parameter value of 1000 is fully
counter-clockwise, 2000 is fully clockwise, and 1500 is in the middle.
Note that some manufactures do not follow this standard very closely so that servos often
respond to values between 700 and 2300. Feel free to increase these endpoints until the servo no
longer continues to increase its range. Note however that attempting to drive a servo past its
endpoints (often indicated by a growling sound) is a high-current state, and should be avoided.
Continuous-rotation servos will respond to the writeMicrosecond function in an analogous
manner to the write function.
Syntax
servo.writeMicroseconds(1500)
Parameters
servo: a variable of type Servo
uS: the value of the parameter in microseconds (int)
Example
#include <Servo.h>
Servo myservo;
void setup()
{
10

myservo.attach(9);
myservo.writeMicroseconds(1500); // set servo to mid-point
Page

}
Robotics and Sensory Technology - Actuators

read()

Description
Read the current angle of the servo (the value passed to the last call to write()).
Syntax
servo.read()

Parameters
servo: a variable of type Servo
Returns
The angle of the servo, from 0 to 180 degrees.

attached()

Description
Check whether the Servo variable is attached to a pin.
Syntax
servo.attached()

Parameters
servo: a variable of type Servo
Returns
true if the servo is attached to pin; false otherwise.

detach()

Description
Detach the Servo variable from its pin. If all Servo variables are detached, then pins 9 and 10
can be used for PWM output with analogWrite().
Syntax
servo.detach()

Parameters
servo: a variable of type Servo
11
Page
Robotics and Sensory Technology - Actuators

ACEduino Motor/Sensor Shield v1.1

The ACEduino Motor/Sensor Shield is an Arduino-compatible shield that:

• Can control
 up to two (2) stepper motors or
 up to four (4) DC motors using two Dual Full Bridge Driver ICs L298D
 up to eight (8) servo motors using only two pins (digital pins 6 and 7 by
default)
 one 8-bit timer (Timer 2) or two 16/8 bit timers in high accuracy mode.
• Has pins that are selectable by removing the 2-pin jumpers and wiring out to the desired
pin (E).
• Has 2 ports (Ground-VCC- I/O Signal) for Digital Sensors (D2,D3)
• Has 4 ports (VCC-Ground-I/O Signal) for Analog Sensors at section (D) that make it
very convenient for interfacing sensors to the Arduino
• Has voltage supply for the motors (G) that can be selected between Arduino VIN and
external power supply through a terminal block labelled External VCC (F).
Note:
Overlay for terminal blocks of L298 (B) output located at the lower right part of the shield
should be: from 4A, 4B, 3A, 3B to 4B, 4A, 3B, 3A
Current: Correct:
12
Page
Robotics and Sensory Technology - Actuators

Pinout
ACEduino 328/ACEduino MEGA 2560

L298 Full Bridge Driver (A)


IN1 D I/O 5
IN2 D I/O 9
IN3 D I/O 10
IN4 D I/O 11
OUT1 TB 1A
OUT2 TB 1B
OUT3 TB 2A
OUT4 TB 2B
L298 Full Bridge Driver (B)
IN1 D I/O 4
IN2 D I/O 8
IN3 D I/O 12
IN4 D I/O 13
OUT1 TB 3A
OUT2 TB 3B
OUT3 TB 4A
OUT4 TB 4B
CD4017 Decade Counter (C) – Servo Control
CLK D I/O 6
RST D I/O 7
Digital Sensor Inputs (D)
D2 (INT0) D I/O 2
D3 (INT1) D I/O 3
Analog Sensor Inputs (D)
A2 A2
A3 A3
A4 A4
A5 A5
Pushbuttons (H)
S1 A0 or 14
S2 A1 or 15
RESET Resets ACEduino board
DC Motor Control
/* Sample code for ACEduino Motor Shield that will help understand the
operation of full bridge driver IC L298 */

void setup () // set L298D (A) output pins


{
pinMode (5, OUTPUT);
pinMode (9, OUTPUT);
}
void loop ()
13

{
/* Setting INPUT1 HIGH and setting input2 LOW, making the motor turn in a
Page

clockwise direction */
Robotics and Sensory Technology - Actuators

digitalWrite (5, HIGH); // clockwise direction


digitalWrite (9, LOW);
delay (1000); // wait 1 second

/* Setting INPUT1 HIGH and setting input2 HIGH, stops the motor */
digitalWrite (5, HIGH); // motor stop
digitalWrite (9, HIGH);
delay (1000); // wait 1 second

/* Setting INPUT1 LOW and setting input2 HIGH, making the motor turn in a
counter-clockwise direction */
digitalWrite (5, LOW); // counterclockwise direction
digitalWrite (9, HIGH);
delay (1000); // wait 1 second

/* Setting INPUT1 LOW and setting input2 LOW, stops the motor */
digitalWrite (5, LOW); // motor stop
digitalWrite (9, LOW);
delay (1000); // wait 1 second
}

Servo Control
#include <ServoControl.h>
ServoShield servos; //Create an object to control up to 8 servos

void setup(){
for (int servo = 0; servo < 8; servo++){ //Initialize all 8 servos

servos.setbounds(servo, 1000, 2000); //Set the minimum and maximum


//pulse duration of the servo
servos.setposition(servo, 1500); //Set the initial position of the
//servo
}
servos.start(); //Start the servo control
}

void loop(){
for(int pos = 1000; pos < 2000; pos++){ //Move the servos from 0°to 180°
for (int i = 0; i < 8; i++) //for all 8 servos
servos.setposition(i, pos); //Tell servo to go to position in variable 'pos'
delay(1); //waits 15ms for the servos to reach the position
}
for(int pos = 2000; pos >= 1000; pos--){ // Move the servos from 180°to 0°
for (int i = 0; i < 8; i++) //for all 8 servos
servos.setposition(i, pos); //Tell servo to go to position in variable 'pos'
delay(1); //waits 15ms for the servos to reach the position
}
14

}
Page
Robotics and Sensory Technology - Actuators

SparkFun Motor Driver - Dual TB6612FNG (1A)

The TB6612FNG motor driver can control


 up to two DC motors at a constant current of 1.2A (3.2A peak).
• Two input signals (IN1 and IN2) can be used to control the motor in one of four function
modes - CW, CCW, short-brake, and stop.
• The two motor outputs (A and B) can be separately controlled, the speed of each motor is
controlled via a PWM input signal with a frequency up to 100 KHz.
• The STBY pin should be pulled high to take the motor out of standby mode.
• Logic supply voltage (VCC) can be in the range of 2.7-5.5VDC, while the motor supply (VM)
is limited to a maximum voltage of 15VDC.
• The output current is rated up to 1.2A per channel (or up to 3.2A for a short, single pulse).
Features:
• Power supply voltage: VM = 15V max, VCC = 2.7-5.5V
• Output current: Iout = 1.2A(average) / 3.2A (peak)
• Standby control to save power
• CW/CCW/short brake/stop motor control modes
• Built-in thermal shutdown circuit and low voltage detecting circuit
• All pins of the TB6612FNG broken out to 0.1" spaced pins
• Filtering capacitors on both supply lines
//motor A connected between A01 and A02
//motor B connected between B01 and B02
int STBY = 10; //standby
//Motor A
int PWMA = 3; //Speed control
int AIN1 = 9; //Direction
int AIN2 = 8; //Direction
//Motor B
15

int PWMB = 5; //Speed control


int BIN1 = 11; //Direction
Page

int BIN2 = 12; //Direction


Robotics and Sensory Technology - Actuators

void setup(){
pinMode(STBY, OUTPUT);
pinMode(PWMA, OUTPUT);
pinMode(AIN1, OUTPUT);
pinMode(AIN2, OUTPUT);
pinMode(PWMB, OUTPUT);
pinMode(BIN1, OUTPUT);
pinMode(BIN2, OUTPUT);
}
void loop(){
move(1, 255, 1); //motor 1, full speed, left
move(2, 255, 1); //motor 2, full speed, left
delay(1000); //go for 1 second
stop(); //stop
delay(250); //hold for 250ms until move again

move(1, 128, 0); //motor 1, half speed, right


move(2, 128, 0); //motor 2, half speed, right
delay(1000);
stop();
delay(250);
}
void move(int motor, int speed, int direction){
//Move specific motor at speed and direction
//motor: 2 for B 1 for A
//speed: 0 is off, and 255 is full speed
//direction: 0 clockwise, 1 counter-clockwise
digitalWrite(STBY, HIGH); //disable standby
boolean inPin1 = LOW;
boolean inPin2 = HIGH;
if(direction == 1){
inPin1 = HIGH;
inPin2 = LOW;
}
if(motor == 1){
digitalWrite(AIN1, inPin1);
digitalWrite(AIN2, inPin2);
analogWrite(PWMA, speed);
}else{
digitalWrite(BIN1, inPin1);
digitalWrite(BIN2, inPin2);
analogWrite(PWMB, speed);
}
}
void stop(){
16

//enable standby
digitalWrite(STBY, LOW);
}
Page
Robotics and Sensory Technology - Actuators

Adafruit Motor Shield

Features:
• 2 connections for 5V 'hobby' servos connected to the Arduino's high-resolution
dedicated timer - no jitter!
• Up to 4 bi-directional DC motors with individual 8-bit speed selection (so, about
0.5% resolution)
• Up to 2 stepper motors (unipolar or bipolar) with single coil, double coil,
interleaved or micro-stepping.
• 4 H-Bridges: L293D chipset provides 0.6A per bridge (1.2A peak) with thermal
shutdown protection, 4.5V to 25V
• Pull down resistors keep motors disabled during power-up
• 2-pin terminal block to connect external power, for separate logic/motor supplies
• Tested compatible with Mega, Diecimila, & Duemilanov

AF_DCMotor class
The AF_DCMotor class provides speed and direction control for up to four DC motors
when used with the Adafruit Motor Shield. To use this in a sketch you must first add the
following line at the beginning of your sketch:
#include <AFMotor.h>

AF_DCMotor motorname(portnum, freq)


This is the constructor for a DC motor. Call this constructor once for each motor in your
sketch. Each motor instance must have a different name as in the example below.
Parameters:
• port num - selects which channel (1-4) of the motor controller the motor will be
connected to
17

• freq - selects the PWM frequency. If no frequency is specified, 1 KHz is used by


default.
Page
Robotics and Sensory Technology - Actuators

Frequencies for channel 1 & 2 are:


• MOTOR12_64KHZ
• MOTOR12_8KHZ
• MOTOR12_2KHZ
• MOTOR12_1KHZ
Frequencies for channel 3 & 4 are:
• MOTOR34_64KHZ
• MOTOR34_8KHZ
• MOTOR34_1KHZ

Example:
AF_DCMotor motor4(4); // define motor on channel 4 with 1KHz default PWM
AF_DCMotor left_motor(1, MOTOR12_64KHZ); // define motor on
channel 1 with 64KHz PWM
Note: Higher frequencies will produce less audible hum in operation, but may result in
lower torque with some motors.

setSpeed(speed)
Sets the speed of the motor.
Parameters:
speed- Valid values for 'speed' are between 0 and 255 with 0 being off and 255 as
full throttle.
Note: DC Motor response is not typically linear, and so the actual RPM will not necessarily
be proportional to the programmed speed.

run(cmd)
Sets the run-mode of the motor.
Parameters:
• cmd - the desired run mode for the motor

Valid values for cmd are:


• FORWARD - run forward (actual direction of rotation will depend on motor
wiring)
• BACKWARD - run backwards (rotation will be in the opposite direction from
FORWARD)
• RELEASE - Stop the motor. This removes power from the motor and is
equivalent to setSpeed(0). The motor shield does not implement dynamic
breaking, so the motor may take some time to spin down
18

Example:
motor4.run(FORWARD);
Page

delay(1000); // run forward for 1 second


Robotics and Sensory Technology - Actuators

motor4.run(RELEASE);
delay(100); // 'coast' for 1/10 second
motor4.run(BACKWARD); // run in reverse

AF_Stepper Class
The AF_Stepper class provides single and multi-step control for up to 2 stepper motors
when used with the Adafruit Motor Shield.

AF_Stepper steppername(steps, portnumber)


The AF_Stepper constructor defines a stepper motor. Call this once for each stepper motor
in your sketch. Each stepper motor instance must have a unique name as in the example
below.
Parameters:
• steps - declare the number of steps per revolution for your motor.
• num - declare how the motor will be wired to the shield.
Valid values for 'num' are 1 (channels 1 & 2) and 2 (channels 3 & 4).
Example:
AF_Stepper Stepper1(48, 1); // A 48-step-per-revolution motor on channels 1 & 2
AF_Stepper Stepper2(200, 2); // A 200-step-per-revolution motor on channels 3 & 4

step(steps, direction, style)


Step the motor.

Parameters:
• steps - the number of steps to turn
• direction - the direction of rotation (FORWARD or BACKWARD)
• style - the style of stepping:

Valid values for 'style' are:


• SINGLE - One coil is energized at a time.
• DOUBLE - Two coils are energized at a time for more torque.
• INTERLEAVE - Alternate between single and double to create a half-step in
between. This can result in smoother operation, but because of the extra half-step,
the speed is reduced by half too.
• MICROSTEP - Adjacent coils are ramped up and down to create a number of
'micro-steps' between each full step. This results in finer resolution and smoother
rotation, but with a loss in torque.
Note: Step is a synchronous command and will not return until all steps have
19

completed. For concurrent motion of two motors, you must handle the step timing for both
motors and use the "onestep()" function below.
Page
Robotics and Sensory Technology - Actuators

Stepper1.step(100, FORWARD, DOUBLE);// 100 steps forward using


//double coil stepping
Stepper2.step(100, BACKWARD, MICROSTEP);// 100 steps backward
//using double microstepping
setSpeed(RPMspeed)
Set the speed of the motor

Parameters:
• Speed - the speed in RPM
Note: The resulting step speed is based on the 'steps' parameter in the constructor. If this
does not match the number of steps for your motor, you actual speed will be off as well.
Example:
Stepper1.setSpeed(10); // Set motor 1 speed to 10 rpm
Stepper2.setSpeed(30); // Set motor 2 speed to 30 rpm

onestep(direction, stepstyle)
Single step the motor.
Parameters:
• direction - the direction of rotation (FORWARD or BACKWARD)
• stepstyle - the style of stepping:

Valid values for 'style' are:


• SINGLE - One coil is energized at a time.
• DOUBLE - Two coils are energized at a time for more torque.
• INTERLEAVE - Alternate between single and double to create a half-step in
between. This can result in smoother operation, but because of the extra half-step,
the speed is reduced by half too.
• MICROSTEP - Adjacent coils are ramped up and down to create a number of
'micro-steps' between each full step. This results in finer resolution and smoother
rotation, but with a loss in torque.
Example:

Stepper1.onestep(FORWARD, DOUBLE); // take one step forward using double coil stepping

release()
Release the holding torque on the motor. This reduces heating and current demand, but
the motor will not actively resist rotation.
Example:
20

Stepper1.release(); // stop rotation and turn off holding


torque.
Page
Robotics and Sensory Technology - Actuators

Stepper Motor Program


#include <AFMotor.h>
AF_Stepper motor(48, 2);

void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Stepper test!");
motor.setSpeed(10); // 10 rpm
motor.step(100, FORWARD, SINGLE);
motor.release();
delay(1000);
}
void loop() {
motor.step(100, FORWARD, SINGLE);
motor.step(100, BACKWARD, SINGLE);

motor.step(100, FORWARD, DOUBLE);


motor.step(100, BACKWARD, DOUBLE);

motor.step(100, FORWARD, INTERLEAVE);


motor.step(100, BACKWARD, INTERLEAVE);

motor.step(100, FORWARD, MICROSTEP);


motor.step(100, BACKWARD, MICROSTEP);
}

DC Motor Program
#include <AFMotor.h>

AF_DCMotor motor(2, MOTOR12_64KHZ); // create motor #2, 64KHz PWN


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
21

delay(1000);
Page

Serial.print("tock");
Robotics and Sensory Technology - Actuators

motor.run(BACKWARD); // the other way


delay(1000);

Serial.print("tack");
motor.run(RELEASE); // stopped
delay(1000);
}

L298P Motor Shield


L298P Shield DC motor driver use high-power motor driver dedicated chip L298P, can directly
drive 2 DC motors, the drive current up to 2A. The motor output interfaces use 8 high-speed
Schottky diodes as protect. It can be directly plugged into the Arduino. L298P Shield DC motor
driver with PWM speed control mode and the PLL mode, using jumper to switch.

Parameters:
Logical input voltage VD: 5V
Drive input voltage: VIN 6.5 - 12V, PWR IN 4.8 - 24V
Logical working current Iss: ≤ 36mA
Drive working current Io: ≤ 2A
Maximum power dissipation: 25W (T= 75°C)
Control signal input electric level:
High level: 2.3V≤ Vin ≤ 5V
Low level: -0.3 V ≤ Vin ≤ 15V
Operating temperature: -25°C ~ +130°C

Features:
22

1. There is L298P motor driver chip on the board so that you can use digit IO interface(D .D10.
D11. D12) without cumbersome wiring connection.
Page

2. Onboard buzzer (D4), you can set the astern alarm ringtone.
Robotics and Sensory Technology - Actuators

3. Convenient motor interface can be two routes motor output.


4. Two-way Bluetooth interface requires no wiring and you can plug directly.
5. It has seven digital interface that are not occupied (including D 2, D 3, D 5, D 6,
D 7, D 9, D).
6. It has six analog interfaces (A0, A1, A2, A3, A4, and A5).
7. It has indicator for forward and backward changing direction.

Code:
int E1 = 10;
int M1 = 12;
int E2 = 11;
int M2 = 13;
void setup()
{
pinMode(M1, OUTPUT);
pinMode(M2, OUTPUT);
}
void loop()
{
int value;
for(value = 0 ; value <= 255; value+=5)
{
digitalWrite(M1, HIGH);
digitalWrite(M2, HIGH);
analogWrite(E1, value);
analogWrite(E2, value);
delay(30);
}
delay(1000);

for(value = 0 ; value <= 255; value+=5)


{
digitalWrite(M1, LOW);
digitalWrite(M2, LOW);
analogWrite(E1, value);
analogWrite(E2, value);
delay(30);
}
delay(1000);}
23

}
Page
Robotics and Sensory Technology - Actuators

Activity 2

1. Write a program that will perform the following procedure:


When the Arduino receives an integer:
a. 1 – rotate stepper motor in clockwise direction by 50
steps (10 rpm)
b. 3 – rotate stepper motor in clockwise direction by 100
steps (20 rpm)
c. 5 – rotate stepper motor in counter clockwise direction by
80 steps (30 rpm)
d. 7 - rotate stepper motor in counter clockwise direction by
120 steps (40 rpm)

2. Write a program that will perform the following


procedure:(using pin 9)
a. When only sw1 (pin2) is closed, rotate the Servo with
1.25ms pulse width.
b. When only sw2 (pin3) is closed, rotate the Servo with
1.5ms pulse width.
c. When both sw1 and sw2 are closed, rotate the Servo with
1.75ms pulse width.

3. Make a program to implement the following events:


SW1 SW2 Stepper(7.2°/Step) Motor1 Motor2
pin2 pin3 Pin15 – Pin12 Pin11 Pin10 Pin6 Pin5
0 1 CLOCKWISE CLOCKWISE STOP
15 STEPS 1 0
30rpm 30%DC
1 0 C.CLOCKWISE STOP C.CLOCKWISE
25 STEPS 0 1
10 rpm 70%DC
0 0 STOP CLOCKWISE C.CLOCKWISE
1 0 0 1
40%DC 60%DC
1 1 STOP C.CLOCKWISE CLOCKWISE
0 1 1 0
100% 25%DC
24
Page

You might also like