GOEDUHUB Online Courses || Last Batch Student's Projects || COVID-19 Projects(AI-ML) || Universities  ||  Placement Preparation  Subscribe our youtube channel
+91-7976731765 Free Online Tutorials || AI || ML || NLP ||  OpenCV || Python || DBMS || OOPs || DSA || Java || Linux/Unix ||  C Programming
0 like 0 dislike
162 views
in Tutorial & Interview questions by Goeduhub's Expert (8.1k points)

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

1 Answer

0 like 0 dislike
by Goeduhub's Expert (8.1k 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

Related questions

0 like 0 dislike
1 answer 230 views
0 like 0 dislike
1 answer 147 views
0 like 0 dislike
1 answer 437 views

 Goeduhub:

About Us | Contact Us  © goeduhub.com Social::   |  | 
 Placements:   List of companies | Logical Reasoning Questions | Quantitative Aptitude Questions | General English Questions | Technical-MCQ and Interview Questions
 Important Lists: List of NITsList of IITsList of Exams After Graduation | List of Engineering Entrance Examinations (UG/PG)College ReviewsCollege Fest, Events & WorkshopsKnowledge ShareTrainees/Interns After 15-04-2020
Exams & Cutoffs: JEE Main | JEE Advanced | GATE | IES | ISROList of PSUs || Cutoff-GATECutoff_IIT-JEECS-ScopeECE ScopeEE-Scope
 Download Previous Year Papers For:  GATE | IES | RAJASTHAN TECHNICAL UNIVERSITY (RTU-Kota)RPSC Technical Exams | ISRO
...