arduino motor control - philadelphia.edu.jo
TRANSCRIPT
Arduino Motor Control
Dr. Tarek A. Tutunji
Philadelphia University
Outline• DC Motor
• Servo Motor
• Stepper Motor
DC Motor
DC Motor Control using PWM
Example: DC Motor Speed Control
reference: www.circuitstoday.com
Example: DC Motor Controlusing analogWrite
const int pwmPin = 10;
Const int Pot = A0;
void setup() {
pinMode(pwmPin, OUTPUT;
}
void loop() {
analogWrite(pwmPin, 99 );
}
Note:
Duty Cycle is 387/1000 = 0.387
Then, 0.387 x 255 = 98.685
Servo Motor
Servo Motors• Servo motors have built-in shaft encoder
• Data sheets provide the required pulses for specific speed and/or position
Motor EncoderMain
ControllerElectronics
Servo Motor• An actuator with built-in feedback mechanism that responds to a
control signal by moving to and holding a position, or by moving at continuous speed.
Servo motors
Reference: living with the lab
Servo Motor
Servo Motor
Servo Motor
• File Examples Servo Knob
/* Controlling a servo position using a potentiometer (variable resistor) */
#include <Servo.h>
Servo myservo; // create servo object
int potpin = 0; // analog pin connect the potentiometer
int val; // variable to read the value from analog pin
void setup()
{ myservo.attach(9); // attaches the servo on pin 9 }
void loop()
{
val = analogRead(potpin); // reads potentiometer
val = map(val, 0, 1023, 0, 180); // scale the value
myservo.write(val); // sets the servo position
delay(15); // waits for the servo to get there
}
Stepper Motor
Stepper Motor
Stepper Motor
Stepper MotorFile Examples Stepper stepper_oneRevolution
/* This program drives a unipolar or bipolar stepper motor. The motor is attached to digital pins 8 - 11 of the Arduino. The motor should revolve one revolution in one direction */
#include <Stepper.h>
const int stepsPerRevolution = 200;
// number of steps per revolution for your motor
// initialize 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
void loop() {
// step one revolution in one direction:
myStepper.step(stepsPerRevolution);
delay(500);
}