Module 3 Actuators
Module 3 Actuators
• 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)
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
Specifications
Truth Table
2
Page
Robotics and Sensory Technology - Actuators
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
// 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
// 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
Four Pins
6
Page
Robotics and Sensory Technology - Actuators
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>
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>
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
• 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
{
/* Setting INPUT1 HIGH and setting input2 LOW, making the motor turn in a
Page
clockwise direction */
Robotics and Sensory Technology - Actuators
/* 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
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
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
//enable standby
digitalWrite(STBY, LOW);
}
Page
Robotics and Sensory Technology - Actuators
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>
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
Example:
motor4.run(FORWARD);
Page
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.
Parameters:
• steps - the number of steps to turn
• direction - the direction of rotation (FORWARD or BACKWARD)
• style - the style of stepping:
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
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:
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
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);
DC Motor Program
#include <AFMotor.h>
delay(1000);
Page
Serial.print("tock");
Robotics and Sensory Technology - Actuators
Serial.print("tack");
motor.run(RELEASE); // stopped
delay(1000);
}
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
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);
}
Page
Robotics and Sensory Technology - Actuators
Activity 2