Sunteți pe pagina 1din 6

BME CAPSTONE DESIGN LAB

Lab 4

Motors

Full name:

Student number:
.
Class:
....
Date:
.

I. Objectives
In this laboratory, you will be introduced:
How to control DC Motors and Stepper Motors using Arduino.
II. DC Motor & L298 Driver

//L293D
//Motor A
const int motorPin1
const int motorPin2
//Motor B
const int motorPin3
const int motorPin4

= 9; // Pin 14 of L293
= 10; // Pin 10 of L293
= 6; // Pin 7 of L293
= 5; // Pin 2 of L293

//This will run only one time.


void setup(){
//Set pins as outputs
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
//Motor Control - Motor A: motorPin1,motorpin2 & Motor B:
motorpin3,motorpin4
//This code will turn Motor A clockwise for 2 sec.
analogWrite(motorPin1, 180);

analogWrite(motorPin2, 0);
analogWrite(motorPin3, 180);
analogWrite(motorPin4, 0);
delay(5000);
//This code will turn Motor A counter-clockwise for 2 sec.
analogWrite(motorPin1, 0);
analogWrite(motorPin2, 180);
analogWrite(motorPin3, 0);
analogWrite(motorPin4, 180);
delay(5000);
//This code will turn Motor B clockwise for 2 sec.
analogWrite(motorPin1, 0);
analogWrite(motorPin2, 180);
analogWrite(motorPin3, 180);
analogWrite(motorPin4, 0);
delay(1000);
//This code will turn Motor B counter-clockwise for 2 sec.
analogWrite(motorPin1, 180);
analogWrite(motorPin2, 0);
analogWrite(motorPin3, 0);
analogWrite(motorPin4, 180);
delay(1000);
//And this code will stop motors
analogWrite(motorPin1, 0);
analogWrite(motorPin2, 0);
analogWrite(motorPin3, 0);
analogWrite(motorPin4, 0);
}
void loop(){
}

III.

Stepper Motors

3 ways to drive:
- Wave drive

- Full step

-Half step

int
int
int
int
int

motorPin1 = 8;
motorPin2 = 9;
motorPin3 = 10;
motorPin4 = 11;
delayTime = 500;

void setup() {
pinMode(motorPin1,
pinMode(motorPin2,
pinMode(motorPin3,
pinMode(motorPin4,
}

OUTPUT);
OUTPUT);
OUTPUT);
OUTPUT);

void loop() {
digitalWrite(motorPin1,
digitalWrite(motorPin2,
digitalWrite(motorPin3,
digitalWrite(motorPin4,
delay(delayTime);
digitalWrite(motorPin1,
digitalWrite(motorPin2,
digitalWrite(motorPin3,
digitalWrite(motorPin4,
delay(delayTime);
digitalWrite(motorPin1,
digitalWrite(motorPin2,
digitalWrite(motorPin3,
digitalWrite(motorPin4,
delay(delayTime);

HIGH);
LOW);
LOW);
LOW);
LOW);
HIGH);
LOW);
LOW);
LOW);
LOW);
HIGH);
LOW);

digitalWrite(motorPin1,
digitalWrite(motorPin2,
digitalWrite(motorPin3,
digitalWrite(motorPin4,
delay(delayTime);
}

LOW);
LOW);
LOW);
HIGH);

IV. Exercises

1. Build a DC motor controlling system that can control speed and


direction of motor using a 10K potentiometer (speed), a button
(direction), display on LCD
2. Build a stepper motor system rotating in 3 modes:
a. 30 degrees
b. Half cycle
c. 4 cycles
Using LCD to display (number of degree and cycle) and buttons to set mode,
initiate.
3. We prepare an optical encoder for you in the toolbox. Using Ex.
1 settings, adding the encoder to count the rotating cycles,
then display on LCD. Setting your motor to rotate at 10/30/100
rpm.

S-ar putea să vă placă și