Introduction: Dim a LED With Raspberry Pi 3 and Python

Hi ! I am going to show you how to dim a LED with Raspberry Pi.

Difficulty : EASY/BEGINNER.

Stay tuned for the next instructables!

Step 1: What Do We Need?

Hi ! I am going to show you how to dim a LED with Raspberry Pi.

Difficulty : EASY/BEGINNER.

First. You will need :

  • Raspberry Pi
  • 2 pcs Male/Female Connectors
  • 1 pcs of a minimum of 100 OmH resistor.
  • 1 pcs LED
  • 1 pcs breadboard.

Step 2: Connect All Parts Together and Let's Have FUN.

Step 3: Write the Python Code.

To connect the LED with the Raspberry PI and to make it dim we need to write the software code.For this I used Python language.

import RPi.GPIO as GPIO

import time

GPIO.setwarnings(False)

GPIO.setmode(GPIO.BOARD)

GPIO.setup(7,GPIO.OUT)

def dim()

	red_led = GPIO.PWM(7,100)

	red_led.start(0)

	pause_time = 0.010

	for i in range(0,100+1):

		red_led.ChangeDutyCycle(i)

		time.sleep(pause_time)

	for i in range(100,-1,-1):

		red_led.ChangeDutyCycle(i)

		time.sleep(pause_time)

	GPIO.cleanup()

dim()<br>

Step 4: Here Is the RESULT!