LED Blinking using Raspberry Pi 3
Hello friends, I hope you all are doing great. In today's tutorial, we are gonna have a look at
LED Blinking using Raspberry Pi 3. It's our first embedded project on Pi 3 and its quite simple. In our previous tutorials on Raspberry Pi 3, we have seen How to install Rasbian on SD Card for Pi 3 and then we have also setup HDMI LCD with Pi 3. So, now our raspberry Pi 3 is ready to program.
In today's tutorial, we will interface a single LED with digital Pin of Raspberry Pi and then we will design a simple code in Python which will turn this LE ON and OFF. It will be quite simple and I will guide you step by step, but if you got into any trouble then ask in comments and I will help you out. So, let's get starteed with LEd Blinking using Raspberry Pi 3:
LED Blinking using Raspberry Pi 3
- On our previous tutorials, we have already set up our computer with raspberry Pi 3. If you haven't read those articles then you must go through them first.
- So, here's our final setup as shown in below figure:
- You must have noticed in above figure that we have an extra Bread Board, which was not present in our Previous Setup.
- I have placed an LED on this Bread board and here's its circuit diagram:
- I would recommend you to use Bread Board but if you can manage to connect legs of resistor and LED then that's fine as well. :P
- Here's a close look of this LED placed in Bread Board.
- Now we have successfully designed our simple electronic circuit.
- It's time to start moving towards coding part.
- We are gonna use Python language that's why I am gonna open pre installed tool in raspbian named as Python 3 (IDLE).
- We are gonna use this environment to design our python code.
- So click on your Menu > Programming > Python 3 (IDLE), as shown in below figure:
- Python 3 will open up, so click on File and then New File to create a seperate File for this project, as shown in below figure:
- You can give a name to this New File, as I have give it Blink.py , .py is the extension for python files.
- In this Blink.py, we are gonna write our code, which will blink the LED, here's our code:
- Copy the below code and paste it in your Blink.py file as shown in above figure.
import RPi.GPIO as GPIO
import time
LED = 11 # pin11
print(" ******** LED Blinking using Raspberry Pi 3 ********* ")
print(" **** Designed by www.TheEngineeringProjects.com **** ")
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD) # We are accessing GPIOs according to their physical location
GPIO.setup(LED, GPIO.OUT) # We have set our LED pin mode to output
GPIO.output(LED, GPIO.LOW) # When it will start then LED will be OFF
while True: #Compiler will keep on executing this loop (infinite loop
GPIO.output(LED, GPIO.HIGH) # led on
time.sleep(2) #delay
GPIO.output(LED, GPIO.LOW) # led off
time.sleep(2)
- You can also download this Blink.py file by clicking below button:
[dt_default_button link="https://www.theengineeringprojects.com/RaspberryPi3/LED Blinking using Raspberry Pi 3.rar" button_alignment="default" animation="fadeIn" size="medium" default_btn_bg_color="" bg_hover_color="" text_color="" text_hover_color="" icon="fa fa-chevron-circle-right" icon_align="left"]Download Blink.py File[/dt_default_button]
- When you run this Blink.py File by pressing F5, then your LED will start blinking. Here's the screenshot of LED in ON state:
- So, that's how you can interact with hardware pins of Pi 3.
I hope after following today's tutorial you can quite easily design this LED Blinking using Raspberry Pi 3. If you got into any troubles then ask in comments and I will sort them out. In the next tutorial, we are gonna have a look at How to Create a GUI in Python. Till then Take care and have fun !!! :)