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

Requirements:: Sudo Nano Led - Py

This document describes using LED patterns with a Raspberry Pi. It explains that an LED needs a resistor when connected to the Raspberry Pi. It then provides the code for 5 LED patterns - a blinking LED, a pattern that lights up each LED sequentially, a countdown pattern, a pattern that lights different combinations of LEDs, and the reverse of the previous pattern. The code uses Python and RPi.GPIO library functions to set the pin modes and output patterns to the LEDs connected to various GPIO pins.

Uploaded by

Nivedan Liye
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)
107 views5 pages

Requirements:: Sudo Nano Led - Py

This document describes using LED patterns with a Raspberry Pi. It explains that an LED needs a resistor when connected to the Raspberry Pi. It then provides the code for 5 LED patterns - a blinking LED, a pattern that lights up each LED sequentially, a countdown pattern, a pattern that lights different combinations of LEDs, and the reverse of the previous pattern. The code uses Python and RPi.GPIO library functions to set the pin modes and output patterns to the LEDs connected to various GPIO pins.

Uploaded by

Nivedan Liye
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
You are on page 1/ 5

Practical No2: Displaying different LED pattern with Raspberry Pi.

The LED:
A Red LED stands for Light Emitting Diode, and glows when electricity is passed through it. When
you pick up the LED, you will notice that one leg is longer than the other.
The longer leg is known as ‘anode;, is always connected to the positive supply of the circuit. The
shorter leg is known as ‘cathode’, and is always connected to the negative side of the power supply,
known as ground.

The Resistor:
You must always use resistors to connect LEDs up to the GPIO pins of the Raspberry Pi. You will be
using 330 Ohm Resistor. Yu can identify the 330 ohm resistor by the color bands along the body.

REQUIREMENTS:

1. Raspberry Pi, SD Card


2. LED
3. Bread Board
4. Jumper Wires
5. Power Supply
6. Resistor
7. Monitor, Keyboard, Mouse

A) LED Blinking

PIN DIAGRAM:

NAME PIN NUMBER

GPIO 40
GND 6

Step 1: Connect the led’s using the pin connection table

Step 2: Open the terminal

Step 3: Open the file

 Sudo nano led.py

Step 4: Write the python code.

Input:

import RPi.GPIO as GPIO


import time
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11,GPIO.OUT)

NAME: NIVEDAN VITTHAL LIYE ROLLNO:615


print("press q to exist");
try:
while True:
for num in range(0,2):
GPIO.output(11,GPIO.HIGH)
time.sleep(0.05)

except KeyboardInterrupt:
pass
GPIO.output(11,GPIO.LOW)
GPIO.cleanup()

Step 5: Run the code

sudo python led.py

Output:

NAME: NIVEDAN VITTHAL LIYE ROLLNO:615


B) LED Pattern Blinking

Pin Diagram:
C) Name Pin nu
NAME PIN DIAGRAM
GPIO 40
GPIO 37
GPIO 35
GPIO 33
GND 6
D) M
Step 1: Connect the led’s using the pin connection table

Step 2: Open the terminal

Step 3: Open the file as

Sudo nano led.py

Step 4: Write the python code

Input:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
led1=29
led2=31
led3=33
led4=35
led5=36
led6=37
GPIO.setup(led1,GPIO.OUT)
GPIO.setup(led2,GPIO.OUT)
GPIO.setup(led3,GPIO.OUT)
GPIO.setup(led4,GPIO.OUT)
GPIO.setup(led5,GPIO.OUT)
GPIO.setup(led6,GPIO.OUT)
def ledpattern(ledVal1,ledVal2,ledVal3,ledVal4,ledVal5,ledVal6):
GPIO.output(led1, ledVal1)
GPIO.output(led2, ledVal2)
GPIO.output(led3, ledVal3)
GPIO.output(led4, ledVal4)
GPIO.output(led5, ledVal5)
GPIO.output(led6, ledVal6)
def patterOne():
for i in range(0,3):
ledpattern(1,0,1,0,1,0)
time.sleep(1)
ledpattern(0,1,0,1,0,1)
time.sleep(1)

NAME: NIVEDAN VITTHAL LIYE ROLLNO:615


def patternTwo():
for i in range(0,5):
ledpattern(1,0,0,0,0,0)
time.sleep(0.1)
ledpattern(0,1,0,0,0,0)
time.sleep(0.1)
ledpattern(0,0,1,0,0,0)
time.sleep(0.1)
ledpattern(0,0,0,1,0,0)
time.sleep(0.1)
ledpattern(0,0,0,0,1,0)
time.sleep(0.1)
ledpattern(0,0,0,0,0,1)
time.sleep(0.1)
def patternThree():
for i in range(0,5):
ledpattern(0,0,0,0,0,1)
time.sleep(0.1)
ledpattern(0,0,0,0,1,0)
time.sleep(0.1)
ledpattern(0,0,0,1,0,0)
time.sleep(0.1)
ledpattern(0,0,1,0,0,0)
time.sleep(0.1)
ledpattern(0,1,0,0,0,0)
time.sleep(0.1)
ledpattern(1,0,0,0,0,0)
time.sleep(0.1)
def patternFour():
for i in range(0,5):
ledpattern(0,1,1,1,1,1)
time.sleep(0.1)
ledpattern(1,0,1,1,1,1)
time.sleep(0.1)
ledpattern(1,1,0,1,1,1)
time.sleep(0.1)
ledpattern(1,1,1,0,1,1)
time.sleep(0.1)
ledpattern(1,1,1,1,0,1)
time.sleep(0.1)
ledpattern(1,1,1,1,1,0)
time.sleep(0.1)
def patternFive():
for i in range(0,5):
ledpattern(1,1,1,1,1,0)
time.sleep(0.1)
ledpattern(1,1,1,1,0,1)
time.sleep(0.1)
ledpattern(1,1,1,0,1,1)

NAME: NIVEDAN VITTHAL LIYE ROLLNO:615


time.sleep(0.1)
ledpattern(1,1,0,1,1,1)
time.sleep(0.1)
ledpattern(1,0,1,1,1,1)
time.sleep(0.1)
ledpattern(0,1,1,1,1,1)
time.sleep(0.1)
try:
while True:
patterOne()
patternTwo()
patternThree()
patternFour()
patternFive()
finally:
#reset the GPIO pins
GPIO.cleanup()

Step 5: Run the code

sudo python led.py

Output:

NAME: NIVEDAN VITTHAL LIYE ROLLNO:615

You might also like