Winter Bootcamp in ML and IoT in Jaipur
 Course content (For Bootcamp & Winter Training):- Machine Learning (ML) || Internet of Things (IoT) || Register for winter bootcamp
0 like 0 dislike
in Tutorial & Interview questions by (3.1k points)

1 Answer

0 like 0 dislike
by (3.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


Winter 10 Days bootcamp classes(7 HRS Daily) will start from 5 & 20 December 2019 in:
1) Internet of things(IoT) Using RASPBERRY-PI
2) Machine Learning (ML)

70% OFF| Fee-INR 3,000/-

Limited seats!! Hurry up!!

[[ CALL - 07976731765 ]]

Some Study Resources are compiled from original Stack Overflow Documentation, the content is developed by the different experts at Stack Overflow. Study resources are released under Creative Commons BY-SA. Images may be copyright of their respective owners. This website is for self-learning and not affiliated with Stack Overflow. All trademarks and registered trademarks are the property of their respective company owners. Please send feedback and corrections to chandwaglobal@gmail.com.

...