Finance[US] Career Guide Free Tutorials Go to Your University Placement Preparation 
0 like 0 dislike
1.3k views
in Tutorial & Interview questions by Goeduhub's Expert (9.3k points)

Speed control of DC motor by PWM (Pulse Width Modulation), Python Program.

1 Answer

0 like 0 dislike
by Goeduhub's Expert (9.3k points)
selected by
 
Best answer

L293D motor driver IC is used to control the DC Motor and that allows the motor to rotate in both the direction. 2 DC Motors can be controlled with a single L293D motor driver IC as describe in DC Motor Control With Raspberry Pi and L293D. Here we are using single motor to understand the concept of PWM.

PWM (Pulse Width Modulation) concept is used to control the speed of Motor.

Python Program


import RPi.GPIO as GPIO

import time

GPIO.setmode(GPIO.BOARD)

GPIO.setup(5,GPIO.OUT) #Motor input A for clockwise direction

GPIO.setup(7,GPIO.OUT) #Motor input B for anticlockwise direction

GPIO.setup(40,GPIO.OUT)  # for enable the Motor

GPIO.setwarnings(False)

i=0

pwm=GPIO.PWM(40,100) #Apply PWM to enable PIN (PIN no. 40 here)

pwm.start(0) #Start PWM with 0 Duty Cycle.

while i<1:

        for x in range(0,100,10):

                pwm.ChangeDutyCycle(x) # increase duty cycle or motor speed from 0 to 100 by  the interval of 10

                print("Duty_Cycle or motor speed is:",x)

                print("Rotating motor in clockwise direction with increase in speed by the interval  of 10")

                GPIO.output(5,0)

                GPIO.output(7,1)

                time.sleep(5)     #Five second delay

        for x in range(100,0,-10):

                pwm.ChangeDutyCycle(x) # decrease duty cycle or motor speed from 100 to 0 by the interval of 10

                print("Rotating Motor in anticlockwise direction with decrease in speed by the interval of 10")

                GPIO.output(5,0)

                GPIO.output(7,1)

                time.sleep(5)     #Five second delay

         i=i+1

Learn & Improve In-Demand Data Skills Online in this Summer With  These High Quality Courses[Recommended by GOEDUHUB]:-

Best Data Science Online Courses[Lists] on:-

Claim your 10 Days FREE Trial for Pluralsight.

Best Data Science Courses on Datacamp
Best Data Science Courses on Coursera
Best Data Science Courses on Udemy
Best Data Science Courses on Pluralsight
Best Data Science Courses & Microdegrees on Udacity
Best Artificial Intelligence[AI] Courses on Coursera
Best Machine Learning[ML] Courses on Coursera
Best Python Programming Courses on Coursera
Best Artificial Intelligence[AI] Courses on Udemy
Best Python Programming Courses on Udemy

Related questions

0 like 0 dislike
1 answer 1.4k views
0 like 0 dislike
1 answer 1.3k views
0 like 0 dislike
1 answer 2.5k views

 Important Lists:

Important Lists, Exams & Cutoffs Exams after Graduation PSUs

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy ||  Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 

 

Free Online Directory

...