Mechatronics RVKL Y1 S7 MotorControl Sensor Arduino
Mechatronics RVKL Y1 S7 MotorControl Sensor Arduino
1
Prior Knowledge
Mechatronics Y1 S1, to S6
Mechanics of Machines
Workshop Practice
2
Contents
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
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)
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.
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.
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.
10
V
8
V
4
V
2
V
0
Pulse width 0%, 20%, 40%, 80%, 100% V
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.
25
Ultrasonic Sensor
(Distance Sensor)
26
Ultrasonic or Distance Sensor HC-SR04
Ultrasonic sensors measure distance by using ultrasonic waves.
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.
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)
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