Lab 2 Control
Lab 2 Control
OBJECTIVES: -
To check the DC motor.
To check the motor driver and test its output.
Controlling direction and speed of motor using driver and Arduino.
APPARATUS: -
Arduino board
Laptop
DC Encoder Motor
Motor Driver L298N
DC ENCODER MOTOR: -
Figure Error! No text of specified style in document..1: Encoder Motor Pin Diagram
There are six wires in the figure shown above all are labeled and motor can be
connected to the power accordingly. The encoder outputs will give square output pulses, these
two have phase shift of about 180o typically. The phase shift is used to sense the direction of
rotation of motor and one of those pulses to find velocity or direction of rotation.
MOTOR DRIVER: -
As there is a rated amount of current and voltage for Arduino MCU. According
to the Arduino official rated voltage for Arduino is 7 to 12V and current rating is max 40mA
which is very less for a motor. So if we directly connect a 12V motor with Arduino it will
eject more current than its limit and Arduino will burn out. So, to handle this situation one
we can use drivers. Here we are going to control a motor so we can use a motor driver which
is L298N here.
This motor driver is basically a dual H-bridge which can be used to control
motor direction or rotation and speed using PWM pulses.
Here we have two outputs for two motors and two supplies can be connected to
the driver which is 5V or 12V (which can be 0 to 48V but 12V is normally used) the driver
consists of an IC which is named as LM298. There are 6 additional pins on the driver known
as logic pins three for each motor. Here is a brief discussion for these pins.
Figure Error! No text of specified style in document..3: Motor Driver Circuit (L298N)
EN (Enable Pin) is used to control the speed of motor using PWM signal. Here
duty cycle of PWM is changed at a certain frequency to obtain different rotational speed. By
changing the duty cycle average voltage at the FETs of h-bridge are changed so results in
variable motor speed. Following figure shows the relation of average voltage and duty cycle of
PWM.
Figure Error! No text of specified style in document..4: PWM and Average Voltage Relation
IN1 and IN2 pins are used to control the direction of the motor these are logic
level pins and a high or logic can be applied on these pins. Let say if IN1 is high and IN2 is
low motor will rotate clockwise and if IN1 is low and IN2 is high, motor will rotate
counterclockwise. This accordingly the direction of rotation can be controlled for each of two
motors.
CHECKING DC MOTOR: -
Set the power supply voltage to 5V/12V (see motor specs).
Connect DC motor with the supply without connecting the encoder and check whether
it rotates in a direction if yes note the direction.
Now invert the polarity of connection with supply and check the direction of rotation it
should be opposite to first case.
If these conditions satisfy, then motor is Ok.
CHECKING THE DRIVER: -
Connect Arduino with the PC through data cable.
Connect Arduino 5V output to the power input of encoder labeled 5V and ground of
Arduino to ground of driver.
Now apply logic high on IN1 and low at IN2 and 5V or 100 duty cycle on the EN pin
of any of the input among A and B.
Now check the output voltage at the specified output where we have to connect the
motor it should be close to 5V, some voltage may drop due to internal circuitry of driver.
Now invert the IN1 and IN2 logics and check the voltage again at output it should be
inverted also.
CONTROLLING DIRECTION OF ROTATION OF MOTOR USING DRIVER AND ARDUINO: -
Connect Arduino with the PC through data cable.
Connect 12V to the power input of encoder labeled 12V and ground of supply to ground
of driver.
Connect ground of Arduino with the ground of driver or supply also.
Connect the motor at the output of driver.
Now apply logic high on IN1 and low at IN2 and 5V or 100 duty cycle on the EN pin
of any of the input among A and B, using Arduino and MATLAB.
Check the direction of rotation whatever it is clockwise or anti-clockwise.
Now invert the IN1 and IN2 logics and check the direction again it should be opposite
to the previous case.
CONTROLLING SPEED OF ROTATION OF MOTOR USING DRIVER AND ARDUINO: -
Connect Arduino with the PC through data cable.
Connect 12V to the power input of encoder labeled 12V and ground of supply to ground
of driver.
Connect ground of Arduino with the ground of driver or supply also.
Connect the motor at the output of driver.
Connect Arduino with the encoder and note that EN pin must be connected to the
Arduino digital pin marked with ~ which means it can support PWM.
Now apply logic high on IN1 and low at IN2 pin of any of the input among A and B,
using Arduino and MATLAB.
Use writeAnalogVoltage or writePWMDutyCycle functions to apply a PWM wave of
required duty cycle or voltage at the EN pin of driver.
To change the speed of motor, change the duty cycle or voltage of the PWM.
Increased duty cycle means high speed and vice versa.
Tasks:-
a) write a code to change the direction of the DC motor and show its execution practically.
b) who is the pause function executing on hardware (DC motor, inertial element), draw
the timing diagram for motor activation and pause activation.
c) write a code to increase and then decrease the speed of the DC motor and show its
execution practically.
COMMENTS: -
In conclusion, DC encoder motors are widely used in various industries due to their high
precision and accuracy. To control and operate DC encoder motors, a motor driver is required
to provide enough power and to control the motor's speed and direction. Interfacing DC encoder
motors with Arduino using MATLAB provides a convenient and user-friendly method for
controlling and monitoring motor behavior. By using MATLAB commands, the user can
program the Arduino board to control the motor's speed, direction, and rotation angle. This
integration of DC encoder motors, motor drivers, Arduino, and MATLAB opens up a wide
range of applications in robotics, automation, and control systems.