You are on page 1of 37

7

1
Prior Knowledge
 Mechatronics Y1 S1, to S6
 Mechanics of Machines
 Workshop Practice

2
Contents

 Connecting a DC Motor with a battery


 DC Motor Controls
 Control Requirements
 Direction Control using SPST & DPDT switches
 DC Motor Speed Control using MOSFET & POT
 Speed Control using PWM
 DC Motor Drive Electronics – L298N
 Ultrasonic Distance sensor
 Arduino UNO microcontroller pinouts and interfacing
 L298 pinouts and interfacing with Arduino UNO
3
DC Motor Controls

4
Connecting DC Motor to Battery
 A battery or a DC source has two terminals, +ve and –ve
 A DC motor has two terminals or leads, +ve and -ve
 Before connecting a motor with battery, observe the following:
Circuit diagram

 Match the voltage rating of the motor with that of


battery. M

 For example, if the motor is rated for 9 volt,


connect with a 9 volt battery. More volt may Wiring diagram

damage the motor. Less voltage may reduce the 9v DC motor

speed of the motor.


 Reversing the terminals of the motor with battery
terminals will change the direction of rotation
motor.
SPST switch
 Can use SPST switch for a ON/OFF control
9v battery 5
DC Motor Control Requirement
 There are two control requirements for DC motor:

 1. A DC motor requires to change the direction of rotation clockwise to


anticlockwise or vis-versa, called direction control

 2. A DC motor also requires to run at variable speed, called speed


control.
 Example: A drone requires to run the propeller with various speed and
direction control to operate correctly.
Drone

6
Direction Control of a DC Motor
 By the above method it is not easy to change the polarity of battery (or
motor) in order to change the direction of rotation of the motor.
 You have to re-wire the entire system which is not practical always.
Circuit diagram
 Therefore this way of speed reversal cannot be preferred in
practical systems.
M
 There are several ways to achieve this. Three of which are
as follows:
Wiring diagram
1. Use a DPDT switch instead of SPST and switch the
9v DC motor
direction manually.
2. Use DPDT switch to form a H-bridge circuit and
operate manually, not an automatic switching
3. Use H-bridge IC with a programable controller to
switch automatically – most preferred way.
SPST switch

9v battery 7
Reversing Rotation of a DC Motor using DPDT
 Wire the motor, battery and DPDT switch as follows:
 Use DPDT toggle switch with center position OFF
Circuit diagram 1 Circuit diagram 2

ON OFF ON M ON OFF ON M

DPDT center OFF Toggle switch DPDT center OFF Toggle switch
Wiring diagram

9v battery

9v DC motor
DPDT switch

8
Reversing Rotation of a DC Motor using H-
bridge
A Dual H-bridge Circuit:
Circuit diagram
 An H-Bridge circuit contains four switches.
 Motor is connected at the center of the circuit
forming an H-like arrangement.
 Closing or opening two opposite switches at the
same time reverses the polarity of the voltage
applied to the motor.
 This causes change in direction of rotation of the
motor
 Closing two switches simultaneously either from left
or right arm of the bridge causes a short circuit of
the battery. This is dangerous.
 The switching logic must take care to avoid such
battery short circuit.
9
Dual H-bridge Integrated Circuit (IC)

A Dual H-bridge Integrated Circuit (IC):


 H-bride circuit is available as Integrated Circuit
 L293D is such a 16 pin IC. It consists of two (dual) H-bridge circuits and the
relation logic circuits
 Direction of two motors can be controlled clockwise or anti-clockwise using
this IC.
 It uses external 5 Volts for its internal circuits and an external supply up to
36 volts, 600 mA to control the motors.

10
Pin Outs of H-bridge IC – L293D
•Pin-1 (Enable 1-2):  When the enable pin is high, then the left part of the
IC will work otherwise it won’t work. This pin is also called as a master
control pin.
•Pin-2 (Input-1):  When the input pin is high, then the flow of current will
be through output 1
•Pin-3 (Output-1): This output-1 pin must be connected to one of the
terminals of the motor
•Pin4 &5: These pins are ground pins
•Pin-6 (Output-2):  This pin must be connected to one of the terminals of
the motor.
•Pin-7 (Input-2): When this pin is HIGH then the flow of current will be
though output 2
•Pin-8 (Vcc2): This is the voltage pin which is used to supply the voltage to the motor.
•Pin-16 (Vss): This pin is the power source to the integrated circuit.
•Pin-15 (Input-4): When this pin is high, then the flow of current will be through output-4.
•Pin-14 (Output-4): This pin must be connected to one of the terminals of the motor
•Pin-12 & 13: These pins are ground pins
•Pin-11 (Output-3): This pin must be connected to one of the terminals of the motor.
•Pin-10 (Input-3): When this pin is high, then the flow of current will through output-3
•Pin-9 (Enable3-4): When this pin is high, then the right part of the IC will work & when it is low the right part
of the IC won’t work. This pin is also called as a master control pin for the right part of the IC.
11
Connecting H-bridge IC – L293D
•The IC LM293D consists of 4-i/p pins where, pin2 and 7 on the left side of the IC
and Pin 10 and 15 on the right side of the IC.
•Left input pins on the IC will control the rotation of a motor connected to pin 3 &
6.
•Right input pins on the IC will control the rotation of a motor connected to pin 11
& 14.
•This motor rotates based on the i/ps we provided across the input pins as Logic 0
and Logic 1.

12
H-bridge- L293D – Left Motor Logic
•For E.g., when a motor is connected to the o/p pins 3 and 6 on the left side of
the IC. For rotate of the left motor in forward or reverse direction then the i/p
pins have to be provided with the following logical order of 0 and 1.

Input 1 (2) Input 2 (7) Motor Left (3 & 6)


1 0 Forward
0 1 Reverse
0 0 Idle (high impedance)
13
1 1 Idle
H-bridge- L293D – Right Motor Logic
•Similarly, when a motor is connected to the o/p pins 10 and 15 on the right
side of the IC. For rotate of the right motor in forward or reverse direction then
the i/p pins have to be provided with the following logical order of 0 and 1.

Input 3 (10) Input 4 (15) Motor Right (11 & 14)


1 0 Forward
0 1 Reverse
0 0 Idle (high impedance)
1 1 Idle 14
Speed Control of a DC Motor
 Principle:

 Out of the three methods 3rd one is the most popular and widely
15
used:
Speed Control by Pulse Width
Modulation (PWM)
 Principle: Instead of applying a varying DC voltage to a DC
motor, voltage is chopped into pulses, and the pulses are
applied to the motor.
 The width of the pluses are varied to get the required speed.
This technique is called PWM
 DC pulses are series of ON-OFF voltages/currents generated
using circuits called Pulse Width Modulation hardware
circuits or software.
50% ON
Motor gets 6
A 12 volt pulse
required for 12 6V volts as from
volt motor
50% OFF PWM controller
 By PWM speed of the motor can be varied smoothly from low to
16
high
About Pulse and Duty Cycle
 Pulse is having a time period, e.g. 20 millisecond
 A pulse time period is divided into two portions, ON and OFF
 When there is only OFF period for a pulse, in effect there is no presence
of pulse. Now the pulse is said to has 0% duty cycle (only OFF period but
no width).
 When there is only ON period for a pulse, in effect there is full presence
of pulse. Now the pulse is said to has 100% duty cycle (only ON period
and full width).
 When there is ON and OFF period for a pulse, in effect there is part
presence of pulse depending up on the % width or duty cycle of the pulse.
 This way by varying the width/duty cycle of the pluses the average output
voltage of the circuit can be varied.

 E.g., is a 12 volt pulse, ON and OFF widths 50% ON

Pulse ON
(periods) are equal. Now we say the duty cycle 6V
is 50%. And the output volt is 50% of 12 volt,
i.e. 6 volt. 50% OFF
Varying Duty Cycle
 Pulses of different duty cycle for example is shown below.

18
PWM for Different Duty Cycle -Demo
• Most widely used speed control method is called (PWM) or Pulse Width
Modulation.

Motor Average Volt

10
V
8
V
4
V
2
V
0
Pulse width 0%, 20%, 40%, 80%, 100% V

• Instead of applying voltage directly, a series of DC pulses will be used. The


width of the pluses will be varied using a PWM circuit or logic. The motor
gets an average value of the pulse voltage that is proportional to the Duty
Cycle of the pulses. This is demonstrated above.
PWM Using Potentiometer and MOSFET
 Applied voltage V can be varied by a simple setup using a
variable resistor and N-MOSFET (Metal Oxide Field Effect
Transistor, IRF540 or IRF3205)
 Rotating the knob controls the
speed of the motor
 + ve is connected to the Drain
of the MOSFET.
 Supply voltage depend on
MOSFET and motor. E.g. If
motor is designed for 12V and
MOSFET is capable of 50V, the
supply voltage should be 12V.
 This method is efficient only for
low power motors.
20
Motor Drive Controller

21
Motor Drive Controller –L298N
 For automatic control of both Speed and Direction dedicated
drive electronics called Motor Drive controllers are available.
 L298N is such a motor drive controller widely used for
robotics. This can be easily interfaced with microcontrollers.
 Consists of a Dual DC motor or one bipolar stepper controller
of 2 amps rating.

 The H-bridge inside can be used


for motors between 5V and 35V
DC.
 If the supply is up to 12V, you
can also used onboard 5V supply.
22
L298N Module Pinouts
1. DC motor 1 "+" or stepper motor A+
2. DC motor 1 "-" or stepper motor A-
3. 12V jumper - remove this if using a supply voltage greater
than 12V DC. This enables power to the onboard 5V
regulator
4. Connect your motor supply voltage here, maximum of 35V
DC. Remove 12V jumper if >12V DC
5. GND
6. 5V output if 12V jumper in place, ideal for powering your
Arduino (etc)
7. DC motor 1 enable jumper. Leave this in place when using a
stepper motor. Connect to PWM output for DC motor speed
control.
8. IN1
9. IN2
10. IN3
11. IN4
23
12. DC motor 2 enable jumper. Leave this in place when using a
Activity 6
6.1 Use a breadboard, SPST toggle switch and battery to ON and
OFF a DC motor.
6.2 Use a breadboard, four SPST toggle switches and battery to
form a H-bridge to control a DC motor. Use 100 mA fuse to
protect the battery from short circuit
6.3 Use a breadboard, DPDT toggle switch and battery to change
the direction of a DC motor.
6.4 Use a breadboard, L293D IC, four SPST switches and battery
to change the direction of two DC motors.
6.5 Use a breadboard, one SPST switch, one SPDT relay, and
battery to control both directions of a DC motor.
24
Activity 6
6.6 Understand the problem of controlling the motors in above
mentioned ways and suggest a solution for it.
6.7 Use a breadboard, MOSFET, Potentiometer, rocker switch
and battery to control speed of a DC motor.

25
Ultrasonic Sensor
(Distance Sensor)

26
Ultrasonic or Distance Sensor HC-SR04
 Ultrasonic sensors measure distance by using ultrasonic waves.

 The HC-SR04 ultrasonic sensor uses


sonar to determine the distance to an
object just like bats and dolphins.
 Since they are used to determine
distance, ultrasonic sensors are
popularly known as distance sensors.
 Ultrasonic sensors offer excellent

c
Ec ig
ho
non-contact range detection from 2cm

d
Vc

Gn
Tr
to 400 cm or 1” to 13 feet.

27
HC-SR04 Working
 The sensor head emits an ultrasonic wave and receives the wave reflected
back from the target. Ultrasonic Sensors measure the distance to the target
by measuring the time between the emission and reception.

 The HC-SR04 receives from the

r
itte

er
microcontroller and it transmits this

sm

iv
ce
an
chirp (Trig). The receiver detects the

Re
Tr
bounced back (echo) and sends the
duration in microseconds to the
microcontroller.
 The distance in cm = duration/29/2
 If you are writing the C program you
have to use the above formula for
calculating the distance of the object.

c
Ec i g
ho
d
Vc

Gn
Tr
28
Arduino Microcontroller

29
Arduino UNO R3 Platform
 Arduino is an open-source electronics platform based on easy-
to-use hardware and software.
 Arduino boards are able to read inputs - light on a sensor, a
finger on a button and turn it into an output - activating a
motor, turning on an LED.
 Arduino board actually is a specially designed circuit board
for programming and prototyping with Atmel
microcontrollers.

30
Arduino UNO R3 Parts
 Before you can start doing anything with the Arduino, you need to download
and install the Arduino IDE (integrated development environment)

 Arduino programs are called sketches

31
Arduino UNO R3 Pins

Transformer 32
Arduino UNO R3 Pins Explanation
 Input and Output: Each of the 14 digital pins on the Arduino Uno can be
used as an input or output, using pinMode(), digitalWrite(), and digitalRead()
functions. They operate at 5 volts. Each pin can provide or receive a
maximum of 40 mA and has an internal pull-up resistor (disconnected by
default) of 20-50 kOhms.
In addition, some pins have specialized functions:
Serial: pins 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL
serial data. These pins are connected to the corresponding pins of the
ATmega8U2 USB-to-TTL Serial chip.
 External Interrupts: pins 2 and 3. These pins can be configured to trigger an
interrupt on a low value, a rising or falling edge, or a change in value. See the
attachInterrupt() function for details.
 PWM: 3, 5, 6, 9, 10, and 11. Provide 8-bit PWM output with the
analogWrite() function.
 SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK). These pins support SPI
communication using the SPI library.
33
Arduino UNO R3 Pins Explanation ..
 LED: 13. There is a built-in LED connected to digital pin 13. When the pin is
HIGH value, the LED is on, when the pin is LOW, it’s off.
 The Uno has 6 analog inputs, labeled A0 through A5, each of which provide
10 bits of resolution (i.e. 1024 different values). By default they measure from
ground to 5 volts, though is it possible to change the upper end of their range
using the AREF pin and the analogReference() function. Additionally, some
pins have specialized functionality:
 TWI: A4 or SDA pin and A5 or SCL pin. Support TWI communication using
the Wire library.
 There are a couple of other pins on the board:
 AREF. Reference voltage for the analog inputs. Used with analogReference().
 Reset. Bring this line LOW to reset the microcontroller. Typically used to add
a reset button to shields which block the one on the board.

34
Arduino UNO R3 General Device connections

 Motor wiring:
 Pin 3 – connects to one of the two dc motors. Let us call this “A”
motor (or motor0). AIN1 stands for one of the leads (top) from “A”
motor.
 Pin 5 – connects to the second lead of “A” motor. AIN2 stands for
second lead (bottom)from the from “A” motor.
 Pin 6 – connects to the second dc motor. Let us call this “B” motor (or
motor1). BIN1 stands for one of the leads (top) from “B” motor.
 Pin 11– connects to the second lead of “B” motor. BIN2 stands for
second lead (bottom) from the from “B” motor.
 Ultrasonic sensor wiring:
 Pin 7 – connects to the Trigger pin of the ultrasonic sensor.
 Pin 8 – connects to the Echo pin of the ultrasonic sensor

35
Arduino UNO R3 General Device connections
..
 LED wiring:
 Pin 13 – connects to the anode of a bult-in
LED
 Buzzer:
 Pin 12- one of the leads of the buzzer
 Line sensor wiring:
 Pin D14 – Right light sensor.
 Pin D15 – Middle light sensor.
 Pin D16 – Left light sensor
 Servo motor:
 Pin 9 – One of the servo motors (servo0).
 Pin 10 – The second servo (servo1)
 IR Sensor:
 Pin 4

36
Any Questions?

Y1 – S7 Concludes
Thank You !

Vijaya Kumar

37

You might also like