DC Motor Speed Control using PWM

Summary of DC Motor Speed Control using PWM


This project implements DC motor speed control using PWM via an L298 driver IC, enabling direction reversal and real-time speed visualization. It utilizes a microcontroller with three push buttons for operation: two to adjust speed up or down and one to toggle rotation direction. A bar graph LED display provides visual feedback on the current speed level. The system includes Bascom code for implementation and a Proteus simulation file for PC testing.

Parts used in the DC Motor Speed Control Project:

  • DC Motor
  • L298 Driver IC
  • Microcontroller (ATmega16)
  • Three Push Buttons
  • Bar Graph LED Display
  • Bascom Compiler Software
  • Proteus Simulation File

This project gives a speed control of DC motor through PWM method. The Dc motor is derived by the L298 driver IC.
You can also control the direction of the motor.
There are three buttons to control the motor. Also a bar graph Led display indicate the speed of the motor.
An proteus simulation file is also available at the download so that you can check the code on your PC.
Project from this Link
DC motor speed control

Bascom Code

$regfile = “m16def.dat”
$crystal = 1000000
‘============================================================================
Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Down , Prescale = 1024
Config Portb = Input
Config Portc = Output
Config Porta = Output
‘============================================================================
Dim A As Word , B As Bit
‘============================================================================
Declare Sub Progress(num As Word)
‘============================================================================
A = 100
Pwm1a = A
Portc.0 = 1
Portc.1 = 0
B = 0
‘============================================================================
Do
‘////////////////////////////////////////////////////////////////////////////
If Pinb.0 = 1 Then
A = A + 10
If A >= 250 Then A = 250
Pwm1a = A
Waitms 250
End If
‘////////////////////////////////////////////////////////////////////////////
If Pinb.1 = 1 Then
A = A – 10
If A <= 10 Then A = 10
Pwm1a = A
Waitms 250
End If
‘////////////////////////////////////////////////////////////////////////////
If Pinb.2 = 1 Then

If B = 0 Then
B = 1
Portc.0 = 0
Portc.1 = 1
Elseif B = 1 Then
B = 0
Portc.0 = 1
Portc.1 = 0
End If
Waitms 250
End If
‘////////////////////////////////////////////////////////////////////////////
Call Progress(a)
‘////////////////////////////////////////////////////////////////////////////
Loop
‘============================================================================
End
‘/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Sub Progress(num As Word)
If Num < 25 Then
Portc.7 = 1
Portc.6 = 0
Porta = 0
End If
If Num < 50 And Num >= 25 Then
Portc.6 = 1
Portc.7 = 1
Porta = 0
End If
If Num < 75 And Num >= 50 Then
Portc.6 = 1
Portc.7 = 1
Porta = &B00000001
End If
If Num < 100 And Num >= 75 Then
Portc.6 = 1
Portc.7 = 1
Porta = &B00000011
End If
If Num < 125 And Num >= 100 Then
Portc.6 = 1
Portc.7 = 1
Porta = &B00000111
End If
If Num < 150 And Num >= 125 Then
Portc.6 = 1
Portc.7 = 1
Porta = &B00001111
End If
If Num < 175 And Num >= 150 Then
Portc.6 = 1
Portc.7 = 1
Porta = &B00011111
End If
If Num < 200 And Num >= 175 Then
Portc.6 = 1
Portc.7 = 1
Porta = &B00111111
End If
If Num < 225 And Num >= 200 Then
Portc.6 = 1
Portc.7 = 1
Porta = &B01111111
End If
If Num < 255 And Num >= 225 Then
Portc.6 = 1
Portc.7 = 1
Porta = &B11111111
End If

End Sub
For more Detail: DC Motor Speed Control using PWM

Quick Solutions to Questions related to DC Motor Speed Control Project:

  • How is the DC motor speed controlled?
    The speed is controlled using the PWM method driven by the L298 driver IC.
  • Can the direction of the motor be changed?
    Yes, the direction can be controlled using one of the three available buttons.
  • What indicates the speed of the motor?
    A bar graph LED display is used to indicate the current speed of the motor.
  • How many buttons are used to control the motor?
    There are three buttons used to control the motor functions.
  • Is there a way to test the code on a PC?
    Yes, a Proteus simulation file is available for checking the code on your PC.
  • What software is used for the project code?
    The project uses Bascom code written for the ATmega16 microcontroller.
  • How does the speed adjustment work?
    Two buttons increase or decrease the PWM value in steps of 10 within a range of 10 to 250.
  • What happens when the direction button is pressed?
    Pressing the button toggles the state of Portc pins to reverse the motor direction.

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter
Scroll to Top