0% found this document useful (0 votes)
93 views

National Institute of Engineering, Mysuru Department of Electronics and Communication Engineering Internet of Things Lab-3

This document describes how to blink an LED using a Raspberry Pi. It explains how to calculate the resistor value needed to limit current to the LED and connect the LED to an output pin of the Pi. The code imports GPIO and time libraries, sets a pin as an output, and uses a while loop to repeatedly turn the pin on for 1 second then off for 1 second to blink the LED. It then expands the code to blink multiple LEDs in sequence by adding additional output pins and controlling them in order within the loop.

Uploaded by

puneeth s
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
93 views

National Institute of Engineering, Mysuru Department of Electronics and Communication Engineering Internet of Things Lab-3

This document describes how to blink an LED using a Raspberry Pi. It explains how to calculate the resistor value needed to limit current to the LED and connect the LED to an output pin of the Pi. The code imports GPIO and time libraries, sets a pin as an output, and uses a while loop to repeatedly turn the pin on for 1 second then off for 1 second to blink the LED. It then expands the code to blink multiple LEDs in sequence by adding additional output pins and controlling them in order within the loop.

Uploaded by

puneeth s
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

National Institute of Engineering, Mysuru

Department of Electronics and Communication Engineering

INTERNET OF THINGS LAB-3


Blink a LED using Raspberry pi

Aim: To understand the basic concept of input/output pins, delays and library functions in
Raspberry pi.

Components required: Raspberry pi kit, LED, Breadboard, Resistor and connecting wires.

Explanation: From the data sheet of LED, forward voltage of 1.7 V and forward current of
20mA. Output voltage from Raspberry pi is 3.3 V, if directly connected could damage the
LED hence a Resistor to be used to limit the voltage across the LED.
𝑉 𝑉𝑜 −𝑉𝐹 3.3−1.7
𝑅= = = = 80Ω
𝐼 𝐼𝐹 20∗ 10 −3
Connections:
1. Pin configuration of Raspberry pi is shown in Figure 3.1 which indicates the power
supply pins, ground pins and General Purpose Input and Output pins.

Figure 3.1 PIN configuration of Raspberry pi

2. Pin 8 is configured as an output file and connected as shown in Figure 3.2.


3. Pin 6 is connected to another end of the LED (Ground pin).

Department of Electronics and Communication Page 1


Figure 3.2 LED connection to pi

Program:

import RPi.GPIO as GPIO # Import Raspberry pi GPIO library


import time #Import time module
GPIO.setmode(GPIO.BOARD) # Use physical pin numbering
GPIO.setup(8, GPIO.OUT) # Setup GPIO Pin 8 as output pin
while True: #Run Infinitely
GPIO.output(8,True) # Turn on LED (True= High)
time.sleep(1) #Wait for one second (ON time)
GPIO.output(8,False) #Turn off LED
time.sleep(1) # Wait for one second (OFF time)
Program to blink series of LED
4. Configure Pins 11 and 12 as Output and assign the delay and order of the
pins according to blink the LED in series.

Department of Electronics and Communication Page 2


Program:

import RPi.GPIO as GPIO # Import Raspberry pi GPIO library


import time #Import time module
GPIO.setmode(GPIO.BOARD) # Use physical pin numbering
GPIO.setup(8, GPIO.OUT) # Setup GPIO Pin 8 as output pin
GPIO.setup(11, GPIO.OUT) # Setup GPIO Pin 11 as output pin
GPIO.setup(12, GPIO.OUT) # Setup GPIO Pin 12 as output pin
while True: #Run Infinitely
GPIO.output(8,True) # Turn on LED (True= High)
time.sleep(1) #Wait for one second (ON time)
GPIO.output(8,False) #Turn off LED
time.sleep(1) # Wait for one second (OFF time)
GPIO.output(11,True) # Turn on LED (True= High)
time.sleep(1) #Wait for one second (ON time)
GPIO.output(11,False) #Turn off LED
time.sleep(1) # Wait for one second (OFF time)
GPIO.output(12,True) # Turn on LED (True= High)
time.sleep(1) #Wait for one second (ON time)
GPIO.output(12,False) #Turn off LED
time.sleep(1) # Wait for one second (OFF time)

Department of Electronics and Communication Page 3

You might also like