EXP#3
DC motor speed control using PWM technique
Aim of experiment:
Teaching the student how to control on the speed of the DC motor by
controlling of the applied voltages by the property of PWM, and learn
how can to reverse the direction of rotation.
Theory:
PWM stands for "pulse width modulation", and it is important because
your Arduino controller cannot actually output analog voltages. It can
output only digital voltages, either 0 or 5 volts. To output analog
voltages, the computer uses averaged voltages, flipping between 0 and 5
volts at an appropriate interval to simulate the desired output voltage, as
in Figure (3.1). The supply signal consists of a train of voltages pulses
such that the width of individual pulses controls the elective voltage level
to the load. In these notes, we will describe the use of PWM on an
Arduino for controlling LED(s) and DC motors.
The Arduino Uno has 14 digital I/O pin(s) 6 provide PWM output. The
PWM give an analog output signal in rage [0,255] where each
255samples means 5V digital so, to determine the required analog output
voltage use the relation:
Veff :Is the required output level such (2, 2.5, 3, 3.5…etc.).
13
Figure (3.1) Pulse width modulation
Important instructions:
analogWrite(pin,value):This instruct use to give analog output
voltage from specific pin where, value are from 0 to 255 sample.
Arduino motor driver:
The Arduino Motor driver is based on the L298, which is a dual full-
bridge driver, designed to drive inductive loads such as relays, solenoids,
DC and stepping motors. It lets you drive two DC motors with your
Arduino board, controlling the speed and direction of each one
independently. The L298D driver has two output ports so can to connect
two motor or just one motor, the pin configuration of driver shown in
figure (3.2) below:
14
Figure (3.2) L298D pin configuration
Apparatus:
1-Arduino UNO
2-Motor driver L298D
3-Breadboard
4-Male to female jumper wires
5-Male to Male jumper wires
6-Small DC motor
7-push button x2
15
Part One
Driving DC motor via transistor 2N2222:
Procedure:
1-Connect the circuit shown in figure (3.3) shown below.
2- Write an Arduino program to make the motor are connected through
2N2222 run with high speed when pressed on push(1) and run with low
speed when the pressed on push(2).The pins of push(1),push(2) and
motor as shown in circuit diagram in figure (3.3).
3- Verify the Arduino sketch.
4-Download the Arduino sketch to the Arduino UNO board.
5-Test the circuit and write down the Arduino code on result paper.
Figure (3.3) practical circuit diagram
16
Part Two
Driving Dc motor via L298N
Procedure:
1-Connect the circuit shown in figure (3.4) shown below.
2- Write an Arduino program to make the motor connected on L298N
turn on with low speed and after 500 millisecond the speed increase
gradually until reaches to full speed.
3- Verify the Arduino sketch.
4-Download the Arduino sketch to the Arduino UNO board.
5-Test the circuit and write down the Arduino code on result paper.
Figure (3.4) practical circuit diagram
17
Discussion:
1- A small DC motor is connected on digital pin (7) of an Arduino Uno.
What are the Arduino commands to set the effective output voltage to 2V,
3V, and 4.5V? Only write the analogWrite( ) command.?
2-write an Arduino program to drive a DC motor connected on L293N
motor driver with three level of speed by 3, 4, 5 volts. Choose any pin's to
make your necessary connection.
3-What the benefits of using motor driver?
18