Starting to program a Raspberry is extremely simple, one of the first applications, very simple is precisely to flash an LED. For writing this “Raspberry Pi LED Blink code”, we are going to use python language.
First, we will import GPIO libraries and what concerns the time management by the program. Then we will set which GPIO pin to use. and finally, we will send HIGH voltage and Low voltage signal on the selected pin with time delay inside a forever loop.
1. CONCEPTS – Raspberry pi LED Blink
a. What is GPIO in Raspberry Pi?
GPIO stands for General Purpose Input Output. A 40 pin GPIO header is found on Raspberry Pi boards. These pins are used for a wide range of purpose including input and output operations. When we are controlling GPIO with python or another language and we have to enter in which way we will use the GPIO in GPIO.BOARD or GPIO.BCM.
The GPIO.BOARD option specifies that it is referring to the pins by their number, that is, the numbers printed on our Raspberry Pi, whereas GPIO.BCM specifies the actual Broadcom chip numbering.
Although You can use any of the numbering schemes, it is preferred to use GPIO.BOARD scheme because GPIO.BCM numbering keeps changing in different versions of Raspberry Pi.
b. Pin diagram (pinout) for Raspberry Pi
- Raspberry Pi – 1 | purchase
- LED – 1 | purchase
- Resistor (470Ω) – 1| purchase
- Breadboard – 1 | purchase
- Connecting Wires as required | purchase
Program : Raspberry Pi LED Blink
#UNCIA ROBOTICS #Program : LED BLINK # #CONNECTIONS: # #Raspberry Pi LED #BOARD11 (+)Positive #GND (-)Negative import time #import time for delay import RPi.GPIO as GPIO #import GPIO libraries GPIO.setmode(GPIO.BOARD) #use BOARD pin numbering led=11 #using pin 11 GPIO.setup(led,GPIO.OUT) #set pin mode to output while(1): #forever loop GPIO.output(led,1) #send HIGH voltage on pin time.sleep(0.5) #wait for some time GPIO.output(led,0) #send LOW voltage on pin time.sleep(0.5) #wait for some time GPIO.cleanup() #clean GPIO
6. FAQs – Raspberry Pi LED Blink
Is it safe to connect LED without resistor?
connecting LED with Raspberry Pi without using resistor will not harm your board. but its always better to use a resistor.
Which one is better to use? GPIO.BCM or GPIO.BOARD.
Its always better to use GPIO.BOARD because GPIO.BCM numbering keeps changing with different versions of the Raspberry Pi board and in future if you upgrade your board, previous programs may not work.
Still, having doubts?
Ask your questions on Raspberry Pi LED Blink, in the comments section below or Contact Us.