Summer training at Goeduhub Technologies-Jaipur

Online Instructor-Led Live Training Courses/Workshops details

0 like 0 dislike
26 views
in Tutorial & Interview questions by Goeduhub's Expert (7.3k points)

1 Answer

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


Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
 Know About Popular Colleges/Universities  List of IITsList of NITs | RTU-KOTA/BTU-Bikaner | Manipal University-Jaipur | JECRC University | Amity University Jaipur | BIT Mesra-Jaipur | MODY UNIVERSITY | LNMIIT-Jaipur | JK Lakshmipat | Banasthali Vidyapith | POORNIMA University
 Exams:   List of Exams After Graduation | List of Engineering Entrance Examinations (UG/PG) | JEE Main | JEE Advanced | GATE | IES | ISROList of PSUs
Placements:  List of companies | Logical Reasoning Questions | Quantitative Aptitude Questions | General English Questions | Technical-MCQ and Interview Questions
 Download Previous Year Papers For:  GATE | IES | RAJASTHAN TECHNICAL UNIVERSITY (RTU-Kota)RPSC Technical Exams | ISRO
 Online Free Training:  Artificial Intelligence(AI) & Machine Learning(ML)Python Programming | Internet of Things-IoT | OpenCV (Open Source Computer Vision Library) | LINUX | Big Data : Hadoop | 
 Goeduhub
About Us | Contact Us   Social::   |  | 
...