LAB 7 23102024 105957pm
LAB 7 23102024 105957pm
EXPERIMRENT # 7
Objectives: In this Lab Students are introduced about Pulse width modulation (PWM),
motor driver and interfacing of DC motor with Arduino Uno
Introduction:
Pulse width modulation (PWM):
Pulse width modulation (PWM) is an important feature in Arduino
Uno, it is used to control the brightness of LED or speed of a DC
motor by varying the duty cycle of PWM. Figure 7.1 shows PWM
signals with different duty cycles.
Arduino Uno has pin no 3, 5, 6 9,10 & 11 that can be used to generate a PWM
signal , these pins are labelled with (~) sign on Arduino Uno board. Arduino IDE
has a built in function analogWrite () that is used to generate PWM signal.
analogWrite(255) means a
16
Software Engineering Department
Bahria University (Karachi Campus)
Lab Manual Embedded System Design
DC Motor Driver:
DC motor can be interfaced to Arduino Uno through L298N motor driver. L298N
is a dual channel H-bridge IC capable of controlling two Dc motors. Simplified
circuit diagram of H-bridge is shown in figure 7.2:
When transistors Q1 & Q4 are on and Q2 & Q3 are off, motor runs in lock wise
direction, similarly when Q1 & Q4 are off and Q2 & Q3 are on, motor runs in anti-clock
wise direction. Diode across the transistors are to prevent back EMF from the motor.
Time Boxing
Activity Name Activity Time Total Time
Login Systems + Setting up Proteus & Arduino 3 mints + 5 mints 8 mints
Environment
Walk through Theory & Tasks 60 mints 60 mints
Implement Tasks 80 mints 80 mints
Evaluation Time 30 mints 30 mints
Total Duration 178 mints
Connections:
1121
ATMEGA328P-PU
DIGITAL (~PWM)
ANALOG IN
17
Software Engineering Department
Bahria University (Karachi Campus)
Lab Manual Embedded System Design
Code:
Connections:
Code:
18
Software Engineering Department
Bahria University (Karachi Campus)
Lab Manual Embedded System Design
Task 3: Write a program in Arduino Uno to control the speed of DC motor using PWM.
Code:
Conclusion:
19
Software Engineering Department
Bahria University (Karachi Campus)