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)

Control Brightness of LED Using PWM of Raspberry PI. How does PWM control LED brightness? Can Raspberry Pi do PWM? What is Gpio in Raspberry Pi?

1 Answer

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

Hardware requirement and connections:

Hardware requirement and connections are same as explained in 

 What is Gpio in Raspberry Pi? 

Turning on and off LED with your Raspberry Pi's GPIO Pins

LED to Raspberry-PI_IOT-Training-in-Jaipur

Python program

import RPi.GPIO as GPIO # Importing RPi library to use the GPIO pins

from time import sleep # Importing sleep from time library

led_pin = 21 # Initializing the GPIO pin 21 for LED

GPIO.setmode(GPIO.BCM) # We are using the BCM pin numbering

GPIO.setup(led_pin, GPIO.OUT) # Declaring pin 21 as output pin

pwm = GPIO.PWM(led_pin, 100) # Created a PWM object

pwm.start(0) # Started PWM with 0% duty cycle

while 1: # Loop will run forever

          for x in range(100): # This Loop will run 100 times

                    pwm.ChangeDutyCycle(x) # Change duty cycle

                    sleep(0.01) # Delay of 10mS

          for x in range(100,0,-1): # Loop will run 100 times; 100 to 0

                    pwm.ChangeDutyCycle(x)

                    sleep(0.01)

pwm.stop() # Stop the PWM

GPIO.cleanup() # Make all the output pins LOW

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.3k views
0 like 0 dislike
1 answer 2.5k views
0 like 0 dislike
1 answer 1.4k 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

...