Ardumotive Arduino Greek Playground
  • Home
    • Blog
    • About us
    • Contact
    • License
  • Events
    • Unboxing & Review
  • Tutorials
  • Workshop
  • RPi Tutorials
  • News
The 1st Arduino Playgroung in Greece - Open Source Hardware

Blink a LED

10/7/2018
Available languages:
Picture
Picture

Introduction 

Picture
LEDs (Light-emitting diode) can be found on many collors and sizes. This example shows the simplest thing you can do with Raspberry Pi to see physical output: it blinks an LED!

If you're new to Raspberry this tutorial will help you get started and make your first Raspberry Pi project!

​Let's get started! 

Video in Greek language

What you will need - Hardware

For this tutorial you will need:​
  • GPIO Breakout
  • Breadboard
  • LED
  • 220 Ohm resistor
Picture

The Circuit

Picture
The connections are pretty easy, see the image above with breadboard circuit schematic.
Picture
Common leds have two pins. The positive end of a led (larger pin) is called anode, and the negative end is called cathode.

The code

In the program below, the first thing you do is to import the library for GPIO and sleep. The next step is to initialize pin 18 as an output pin with GPIO.setup( ) function .
The While True loop runs over and over again, forever. In the main loop, you turn on or off LED with GPIO.output( ) function and "pause" the program for one seconds with sleep( ) function.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#Import library for GPIO and sleep
import RPi.GPIO as GPIO
from time import sleep
#Stop the warnings
GPIO.setwarnings(False)
#Set the LED on pin 18 as an output 
GPIO.setmode(GPIO.BCM)
GPIO.setup(18,GPIO.OUT)
#Loop
while True:
    GPIO.output(18,GPIO.HIGH)
    print ("LED ON")
    sleep(1)
    GPIO.output(18,GPIO.LOW)
    print ("LED OFF")
    sleep(1)
Download the code from here and open it with Thonny Python IDE or run it from terminal.
raspberrypi_blink_led_tutorial.py.zip
File Size: 0 kb
File Type: zip
Download File

Now start making your own modifications to the code. For example you can add a second led or change the sleep time.
​

Well Done!

You have successfully completed our first Raspberry Pi "How to" tutorial and you learned how to use:
  • led
  • comments in code
  • GPIO.setmode(), GPIO.setup(), GPIO.output(), print() and sleep() functions

Video in Greek language

I hope you liked this, let me know in the comments.
Picture

Search Engine

Licence 

Picture

Help us to grow up!

Picture


Donate us
About us
License
Cookies policy

Visit the biggest Arduino Shop in Greece!

Picture
find us on dwrean.net
find us on Codebender
find us on Instructables
Developed and designed by Vasilakis Michalis Copyright © 2013 Ardumotive All Rights Reserved
All trademarks referenced herein are properties of their
Powered by Create your own unique website with customizable templates.
Design by DivTag Templates