INSTALL DEPENDENCY:
- Check any Python package installed in RPi
- Open terminal paste below code.
python
python3
- If python, python3 and GPIO library of python is Not installed copy the below code and paste in terminal.
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python
sudo apt-get install pyhton3
sudo apt-get install python-rpi.gpio python3-rpi.gpio
- Analog output basically PWM (Pulse Width Modulation) output.
- For more Details about PWM go through below calculation for how it produce variable voltage in GPIO pin of RPi using PWM method.


- led.GPIO.PWM(3,100) #Set PWM output wih 100Hz Frequency
- 100Hz means 100cycles per sec.

REQUIRED COMPONENTS
- Raspberry Pi (setup)- 1pic
- Micro USB cable
- Resistor 220E – 1pic
- LED (3.5mm) -1pic
- Breadboard- 1pic
- Jumper wire – as per requirement
CIRCUIT CONNECTION:

CODE:
# Tested code by Robogenesis
import RPi.GPIO as GPIO
import time
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD) #Board pin numbering
GPIO.setup(3, GPIO.OUT) #Led is connected to Pin 3
led = GPIO.PWM(3,100) # set PWM output with 100Hz frequency
try :
x=0
while True :
print ("increment")
for x in range (0,100,1) :
led.ChangeDutyCycle(x)
time.sleep(0.02)
print ("Decrement")
time.sleep(1)
for x in range (100,0,-1) :
led.ChangeDutyCycle(x)
time.sleep(0.02)
led.start(0)
except :
led.stop()
GPIO.cleanup()
OUTPUT:

Hava a Good Day!!