Blink LED using Raspberry Pi – Beginners tutorial

If you are getting started with Raspberry Pi, then the first thing you would love to learn is, using the GPIO Pins on Pi.In this tutorial, we will use the GPIO Pins of PI to Blink a LED with a time interval.Lets Start!!

Components you Need

  • Raspberry Pi
  • 5mm LED
  • 330Ω Resistor
  • Breadboard
  • Male to Female Jumper Wires
  • power supply

 Connections and Raspberry Pi Pinout

pi3_gpio
Raspberry Pi 3B

In this tutorial I’m using the Raspberry Pi 3B running Raspbian OS, you can follow this tutorial even for other Pi variants by referring their Pinout diagrams.

Follow this article to install Raspbian OS if you haven’t already Installing Raspbian OS.

LED Connections
LED Connections

Connect the negative terminal of LED to PIN 13  of Raspberry Pi on a Breadboard.

Connect the positive terminal of LED to PIN 6 of  Raspberry Pi with a 330Ω Resistor in series with LED.The Resistor helps us to limit the current through the LED.

Now we are ready to Write the Code.

 

Code

import RPi.GPIO as Blink_led
import time
Blink_led.setmode(Blink_led.BOARD)
Blink_led.setup(3, Blink_led.OUT)
for counter in range(0,10000):
    Blink_led.output(3,True)
    time.sleep(1)
    Blink_led.output(3,False)
    time.sleep(1)
Blink_led.output(False)

Note-We can change the delay between the Blinks by changing the number in ‘time.sleep(1)’, where the number represents the time in seconds.we can change the GPIO pin by changing the number in ‘Blink_led.setup(3, Blink_led.OUT)’  to any other Pin Number.

Download the Python Code HereBlink.py

Make sure that you have already installed Raspbian OS on your Raspberry Pi.If you haven’t installed Raspbian OS, follow this Installing Raspbian OS.

Plug in your SD card.

Connect a Keyboard, Mouse, Monitor your Raspberry Pi.

Connect Power Supply and Boot.

After the Pi has booted, Open Menu>>Programming>>Python 3 IDLE, Create a new file and write the above code.

Save and Run the Code, Now you will have your LED Blinking!!

Leave a Reply

Your email address will not be published. Required fields are marked *

Show Buttons
Hide Buttons