Raspberry PI LED Blink Tutorial

Author : Dinesh Kumar Wickramasinghe

Introduction

Hello Friends, Today I am going to create a Raspberry Pi LED Blinking Project. I am using Raspberry Pi 3 Model B for this tutorial.

In this tutorial, I will step by step show you how to write a simple Python code to blink an LED which connect to your Raspberry Pi via GPIO pins.

Raspberry Pi LED Blinking Video
Up your Pi and Lets get started

What you need to complete this project?

  • Raspberry Pi 3 / 2 / B+
  • LED (Any color)
  • 220 Ohm Resistor
  • Hook up Wires
GPIO Pins Connectivity

Use the below diagram to understand the GPIO Pin numbers

Raspberry Pi GPIO Pins

Connect your LED to the Raspberry Pi Pin 11 via the 220 Ohms resistor. Use the below diagram.

Connect LED GPIO Pins
Writing the Code

Now it is time to write the Python code. If you are not familiar with Python programming, no problem. This is just a Hello World program.

I assume now you've turned on your Raspberry Pi and you are on Raspbian desktop. Now follow these steps.

(Click on images to enlarge them)

Right click on your desktop and select Create New > Folder. Name your folder as "Programs"

Double click the "Programs" folder and open it.

Right click inside the folder and Select Create New > Empty File

Name your file as "blink.py" The .py extension means it is a Python file.

Double click the "blink.py" file. It will open up the text editor.

Now type the below Python code.

Please note that you type the code same as on above screenshot. You need to keep the indentation as it is. Otherwise your code will not work as expected.

Now save your code. (Press Ctrl + S or File > Save )

Close the test editor and open the Console. To open the console, click the console icon on task bar. Please see the below screenshot.

Type below command on console window to change the directory to Programs folder that you created on Desktop. Our python code is inside this folder.

/home/pi/Desktop/Programs

Once you change the directory, type the below command to run your Python script.

sudo Python blink.py

Now your program will start and if everything good you will see the led is blinking. If you find any error, carefully check your connections and also the python code for any errors.

Comments Area
Add your questions and comments here. Comments will be published after the admin approval

 

Similar Projects

Go Top