Top Banner
ME 120: Speed control of small DC motors Arduino Application: Speed control of small DC Motors ME 120 Mechanical and Materials Engineering Portland State University http://web.cecs.pdx.edu/~me120
28

arduino application dc motors Hbridge

Nov 25, 2021

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: arduino application dc motors Hbridge

ME 120: Speed control of small DC motors

Arduino Application:Speed control of small DC Motors

ME 120Mechanical and Materials Engineering

Portland State Universityhttp://web.cecs.pdx.edu/~me120

Page 2: arduino application dc motors Hbridge

ME 120: Speed control of small DC motors

Learning Objectives

• Be able to describe the use of PWM for motor speed control• Be able to explain the role of a snubber diode• Be able to implement PWM speed control of a DC motor• Be able to use the H-Bridge with the Sparkfun Tinker Kit

to control a small DC Motor

• Additional references:❖ Experiment 9 in the Sparkfun Tinker Kit experiment guide❖ ME 120 course notes on PWM❖ http://learn.adafruit.com/adafruit-arduino-lesson-13-dc-

motors/overview

2

Page 3: arduino application dc motors Hbridge

ME 120: Speed control of small DC motors

Using a transistor as a high speed switch

3

Page 4: arduino application dc motors Hbridge

ME 120: Speed control of small DC motors

Transistor as a switching device

• Each Arduino output channel has a 40 mA limit❖ Only current to power a very small DC motor❖ Arduino is not designed as a power supply• Maximum current draw for an Arduino is 200 mA• Use the Arduino as the brain• Let another switching element be the brawn

4

Page 5: arduino application dc motors Hbridge

ME 120: Speed control of small DC motors

Use an NPN Transistor as a switch

5

NPN General Pupose AmplifierThis device is designed for use as a medium power amplifier and

switch requiring collector currents up to 500 mA.

MMBT44012N4401

Absolute Maximum Ratings* TA = 25°C unless otherwise noted

*These ratings are limiting values above which the serviceability of any semiconductor device may be impaired.

NOTES:

1) These ratings are based on a maximum junction temperature of 150 degrees C.

2) These are steady state limits. The factory should be consulted on applications involving pulsed or low duty cycle operations.

Symbol Parameter Value UnitsVCEO Collector-Emitter Voltage 40 V

VCBO Collector-Base Voltage 60 V

VEBO Emitter-Base Voltage 6.0 V

IC Collector Current - Continuous 600 mATJ, Tstg Operating and Storage Junction Temperature Range -55 to +150 °C

Thermal Characteristics TA = 25°C unless otherwise noted

Symbol Characteristic Max Units2N4401 *MMBT4401

PD Total Device Dissipation

Derate above 25°C625

5.0

350

2.8

mW

mW/°CRqJC Thermal Resistance, Junction to Case 83.3 °C/W

RqJA Thermal Resistance, Junction to Ambient 200 357 °C/W

CB E

TO-92

C

B

E

SOT-23Mark: 2X

*Device mounted on FR-4 PCB 1.6" X 1.6" X 0.06."

ã 2001 Fairchild Semiconductor Corporation

2N4401 / M

MB

T4401

2N4401/MMBT4401, Rev A

This device is designed for use as a medium power amplifier and switch requiring collector currents up to 500 mA

Page 6: arduino application dc motors Hbridge

ME 120: Speed control of small DC motors

Use Digital I/O pin to switch LED on/off

Digitaloutput

Digital I/O pin → LED

Page 7: arduino application dc motors Hbridge

ME 120: Speed control of small DC motors

Code to control brightness of an LEDint LED_pin = 11; // PWM pin LED or motor control

void setup() { pinMode( LED_pin, OUTPUT );

}

void loop() {int duty, pot_pin=0, reading;

reading = analogRead(pot_pin); // read potentiometerduty = map(reading,0,1023,0,255); // rescale to 8-bitduty = constrain(duty,0,255); // be safeanalogWrite(LED_pin,duty); // set duty cycle

}

In the following examples, the Arduino code does not need to change when the electrical circuit is changed. The Arduino code only needs to used a single digital output pin, which in this code is LED_pin.

Page 8: arduino application dc motors Hbridge

ME 120: Speed control of small DC motors

Use a Transistor to switch LED on/off

Digital I/O pin → Transistor → LED

Digitaloutput

5V

Page 9: arduino application dc motors Hbridge

ME 120: Speed control of small DC motors

NPN Transistors as Switches

NPNC

B

E

C is the collectorB is the baseE is the emitter

Transistors can be used as switches: By applying relatively small voltage to the base, electrical current will flow from the collector to the emitter.

Page 10: arduino application dc motors Hbridge

ME 120: Speed control of small DC motors

NPNC

B

EIBE ICE

NPN Transistors as Switches

C is the collectorB is the baseE is the emitter

When used as a switch, ICE, the current from the collector to the emitter is large compare to IBE, the current from the base to the emitter.

Page 11: arduino application dc motors Hbridge

ME 120: Speed control of small DC motors

What is a snubber diode, and why should I care?

11

Page 12: arduino application dc motors Hbridge

ME 120: Speed control of small DC motors

Simplest DC Motor Circuit

Connect the motor to a DC power supply

12

+5V +5V

I

Switch closed

Page 13: arduino application dc motors Hbridge

ME 120: Speed control of small DC motors

Current continues after the switch is opened

Opening the switch does not immediately stop current from flowing in the motor windings

13

+5V

I+

– Inductive behavior of themotor causes current tocontinue to flow when theswitch is opened suddenly.Charge builds up on whatwas the negative terminalof the motor.

Page 14: arduino application dc motors Hbridge

ME 120: Speed control of small DC motors

Reverse current

Charge build-up can cause damage

14

+5V

I+

Arc acrossthe switch

Current surge throughthe voltage supply

Page 15: arduino application dc motors Hbridge

ME 120: Speed control of small DC motors

Motor Model

• Simple model of a DC motor:❖ Windings have inductance and resistance❖ Electrical energy is stored in the windings – the inductance

effect❖ We need a way to safely dissipate electrical energy when

the switch is opened after the motor has been running

15

+5V

I

+5V

Page 16: arduino application dc motors Hbridge

ME 120: Speed control of small DC motors

Flyback diode or snubber diode

Adding a diode in parallel with the motor provides a path for the dissipation of stored energy when the switch is opened

16

+5V The flyback diode allowscharge to dissipatewithout arcing acrossthe switch, or withoutflowing back to groundthrough the +5V voltagesupply.

+

Page 17: arduino application dc motors Hbridge

ME 120: Speed control of small DC motors

DC motor speed control circuit

The circuit for DC motor speed control uses the idea from the LED brightness control circuit. Replace the LED circuit with the DC motor and snubber diode

17

+5V

motorPin

330Ω

Page 18: arduino application dc motors Hbridge

ME 120: Speed control of small DC motors

Motor control with an H-Bridge

18

Page 19: arduino application dc motors Hbridge

ME 120: Speed control of small DC motors

H-Bridges simplifies motor control and enable

features not possible with a single transistor

An H-bridge

❖ Uses logic-level signals to switch higher current power to

the motor – just like a transistor

❖ Allows polarity of motor power, and hence direction of

rotation, to be reversed,

❖ Includes fly-back diodes (snubbers)

❖ Is available in a single IC package

19

Image of L293DNE quadruple half-H

motor driver from Sparkfun.com

Page 20: arduino application dc motors Hbridge

ME 120: Speed control of small DC motors

Low-current digital I/O signals from an Arduino control the behavior of the H-bridge

20

PowerSupply

MotorController

Arduino(or equivalent)

DCMotor

High current

Low

cur

rent

GN

DLo

gic

pow

erPW

MLo

gic

line

1Lo

gic

line

2Lo

gic

line

...

GND

+V + or –

+ or –

H-bridge motorcontroller chip

Page 21: arduino application dc motors Hbridge

ME 120: Speed control of small DC motors

Basic H-Bridge has four switches

Motor

+

S1 S3

S2 S4

21

Note that there are many ways to implement this concept. For example, 24 differentdesigns are shown at http://www.talkingelectronics.com/projects/H-Bridge/H-Bridge-1.html

Page 22: arduino application dc motors Hbridge

ME 120: Speed control of small DC motors

Closing two switches supplies power that causes motor to turn one way

22

Motor

+ +

S1 S3

S2 S4

– –

Page 23: arduino application dc motors Hbridge

ME 120: Speed control of small DC motors

Closing two other switches supplies power that causes motor to turn the opposite way

23

Motor

+ +

S1 S3

S2 S4

– –

Page 24: arduino application dc motors Hbridge

ME 120: Speed control of small DC motors

Using the H-bridge from the Tinker kit

24

Motor +

Motor –

Page 25: arduino application dc motors Hbridge

ME 120: Speed control of small DC motors

Using the H-bridge from the Tinker kit

25

Page 26: arduino application dc motors Hbridge

ME 120: Speed control of small DC motors

Using the H-bridge from the Tinker kit

26

//define the two direction logic pins and the speed / PWM pinconst int DIR_A = 5;const int DIR_B = 4;const int PWM_pin = 6;

void setup(){// -- set all motor control pins as outputpinMode(DIR_A, OUTPUT);pinMode(DIR_B, OUTPUT);pinMode(PWM_pin, OUTPUT);

Serial.begin(9600); // Used to display motor speed values}

// Code continued on next slide

Page 27: arduino application dc motors Hbridge

ME 120: Speed control of small DC motors

Using the H-bridge from the Tinker kit

27

// Code continued from previous slide

void loop(){

int motorSpeed, potpin=3, potval;

// -- Set control lines to drive forwarddigitalWrite(DIR_A, HIGH);digitalWrite(DIR_B, LOW);

// -- Read potentiometer to set PWM for motor speedpotval = analogRead(potpin);motorSpeed = map( potval, 0, 1023, 0, 255);motorSpeed = constrain( motorSpeed, 0, 255);analogWrite(PWM_pin, motorSpeed);

Serial.print(potval);Serial.print(" ");Serial.println(motorSpeed);

}

Page 28: arduino application dc motors Hbridge

ME 120: Speed control of small DC motors

Next Steps

After getting the basic code to work❖ Find the minimum PWM setting that will make the motor

spin

❖ Use the minimum PWM setting in the constrain() command❖ Make a servo sweep back and forth while the DC motor is

running❖ Add a button to change direction of the motor

28