arduino motor control - philadelphia.edu.jo

17
Arduino Motor Control Dr. Tarek A. Tutunji Philadelphia University

Upload: others

Post on 24-Apr-2022

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Arduino Motor Control - philadelphia.edu.jo

Arduino Motor Control

Dr. Tarek A. Tutunji

Philadelphia University

Page 2: Arduino Motor Control - philadelphia.edu.jo

Outline• DC Motor

• Servo Motor

• Stepper Motor

Page 3: Arduino Motor Control - philadelphia.edu.jo

DC Motor

Page 4: Arduino Motor Control - philadelphia.edu.jo

DC Motor Control using PWM

Page 5: Arduino Motor Control - philadelphia.edu.jo

Example: DC Motor Speed Control

reference: www.circuitstoday.com

Page 6: Arduino Motor Control - philadelphia.edu.jo

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

Page 7: Arduino Motor Control - philadelphia.edu.jo

Servo Motor

Page 8: Arduino Motor Control - philadelphia.edu.jo

Servo Motors• Servo motors have built-in shaft encoder

• Data sheets provide the required pulses for specific speed and/or position

Motor EncoderMain

ControllerElectronics

Page 9: Arduino Motor Control - philadelphia.edu.jo

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.

Page 10: Arduino Motor Control - philadelphia.edu.jo

Servo motors

Reference: living with the lab

Page 11: Arduino Motor Control - philadelphia.edu.jo

Servo Motor

Page 12: Arduino Motor Control - philadelphia.edu.jo

Servo Motor

Page 13: Arduino Motor Control - philadelphia.edu.jo

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

}

Page 14: Arduino Motor Control - philadelphia.edu.jo

Stepper Motor

Page 15: Arduino Motor Control - philadelphia.edu.jo

Stepper Motor

Page 16: Arduino Motor Control - philadelphia.edu.jo

Stepper Motor

Page 17: Arduino Motor Control - philadelphia.edu.jo

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);

}