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

Motors: Bme Capstone Design Lab

This document provides instructions for a lab experiment on controlling motors using Arduino. It introduces how to control DC motors and stepper motors. It describes using an L298 driver chip to control two DC motors independently by changing the voltage applied to motor pins. It also explains three methods for driving stepper motors: wave drive, full step, and half step. Exercises are outlined to build systems for controlling a DC motor's speed and direction using a potentiometer and button, rotating a stepper motor in different modes, and adding an optical encoder to count cycles of a rotating DC motor.

Uploaded by

Huy G. Cu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views

Motors: Bme Capstone Design Lab

This document provides instructions for a lab experiment on controlling motors using Arduino. It introduces how to control DC motors and stepper motors. It describes using an L298 driver chip to control two DC motors independently by changing the voltage applied to motor pins. It also explains three methods for driving stepper motors: wave drive, full step, and half step. Exercises are outlined to build systems for controlling a DC motor's speed and direction using a potentiometer and button, rotating a stepper motor in different modes, and adding an optical encoder to count cycles of a rotating DC motor.

Uploaded by

Huy G. Cu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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.

You might also like