0% found this document useful (0 votes)
5 views5 pages

LED Brightness Control Using PWM On Raspberry Pi

The document outlines a project to control LED brightness using Pulse Width Modulation (PWM) on a Raspberry Pi. It includes details on the components needed, circuit setup, Python code for implementation, and the expected output of the LED gradually increasing and decreasing in brightness. The experiment successfully demonstrates the application of PWM for simulating analog behavior with digital signals.

Uploaded by

engr.mithunrd
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

LED Brightness Control Using PWM On Raspberry Pi

The document outlines a project to control LED brightness using Pulse Width Modulation (PWM) on a Raspberry Pi. It includes details on the components needed, circuit setup, Python code for implementation, and the expected output of the LED gradually increasing and decreasing in brightness. The experiment successfully demonstrates the application of PWM for simulating analog behavior with digital signals.

Uploaded by

engr.mithunrd
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Title: LED Brightness Control Using PWM on Raspberry Pi

📌 Aim

To design a circuit using a Raspberry Pi to control the brightness of an LED using Pulse Width
Modulation (PWM), such that the LED gradually increases in brightness and then gradually
decreases.

📖 Introduction

Pulse Width Modulation (PWM) is a technique used to simulate analog output using digital
signals. By varying the duty cycle (the percentage of time the signal stays HIGH), we can
control the brightness of an LED.

In this experiment, a Raspberry Pi GPIO pin is used to generate PWM signals. By gradually
increasing and decreasing the duty cycle, the LED brightness smoothly fades in and out.

⚙️Components Required

 Raspberry Pi

 LED

 330Ω Resistor

 Breadboard

 Jumper wires

🔌 Circuit Description

 Connect the anode (+) of the LED to a GPIO pin (e.g., GPIO18) through a resistor

 Connect the cathode (-) of the LED to GND

🧠 Concept

 PWM signal controls brightness

 Duty cycle = % of ON time

 0% → LED OFF

 100% → LED fully ON


 Intermediate values → varying brightness

💻 Python Code

import [Link] as GPIO

import time

# Setup GPIO mode

[Link]([Link])

# Define LED pin

LED_PIN = 18

# Setup pin as output

[Link](LED_PIN, [Link])

# Create PWM instance (frequency = 100Hz)

pwm = [Link](LED_PIN, 100)

# Start PWM with 0% duty cycle

[Link](0)

try:

while True:

# Increase brightness

for duty in range(0, 101, 5):

[Link](duty)

[Link](0.05)
# Decrease brightness

for duty in range(100, -1, -5):

[Link](duty)

[Link](0.05)

except KeyboardInterrupt:

pass

# Cleanup

[Link]()

[Link]()

Circuit Diagram
🔄 Procedure

1. Connect LED and resistor to GPIO18

2. Open terminal in Raspberry Pi

3. Create file:

4. nano pwm_led.py

5. Paste the code

6. Run:

7. python3 pwm_led.py

8. Observe LED brightness changing smoothly

✅ Output

 LED brightness gradually increases from OFF to FULL

 Then gradually decreases back to OFF

 Entire cycle takes more than 1 second ✔️

🎯 Result

The LED brightness was successfully controlled using PWM. The LED smoothly faded in and
out, demonstrating effective use of duty cycle variation.

💡 Conclusion

This experiment demonstrates how PWM can be used to control analog-like behavior
(brightness) using digital outputs. It is widely used in applications like motor control, lighting
systems, and embedded systems.

You might also like