Home > Artikel, Artikel IT, Pemprograman, Robotik & Mikrokontroler > Hardware application in Raspberry PI

Hardware application in Raspberry PI

i was in Depok yesterday , and suddenly thought about “how to control a hardware component by using PI”, because i used to control hardware device such as LED’S (Light emitting Diode) , Switches, censors, servos, and many more with microcontroller. maybe, i could do same thing by PI, then i searched for article last night , and i got brief tutorial. in this section, i would like to discuss hardware application and how to turn on / off your LED by using python script in Raspberry PI. this is interesting enough. here lists of my raw materials (depend on you) :

  • PI , of course
  • LED
  • Resistor , 1 x 330 ohm
  • Electronic Board or you can use breadboard
  • Cable usually called jumper to connect electronic component to others.
  • Coffee ( to enjoy step by step)

step by step :

  • create electronic circuit like this and connect it to your PI. please be carefull to make this circuit, i suggest you to use breadboard.


  • create file ‘lamp.py’ :

import os; #import os to use 'system' function
import RPi.GPIO as GPIO #GPIO module to access your GPIO Port in PI
import time

GPIO.setup(3, GPIO.OUT); # 3 : port GPIO3 set as output
os.system("clear"); #clear screen
status = True; #boolean status as flag true or false, but set true first
while(status): #while status true then loop
 print "1. Nyalakan Lampu"
 print "2. Matikan Lampu"
 print "3. Kedap Kedip"
 print "0. Keluar"
 pil = raw_input( "Pilihan Anda : ") #store user input to pil variable
  print "Lampu Dinyalakan";
  print "Lampu Dimatikan";
  GPIO.output(3, True);
  for i in range(1,10):
   GPIO.output(3, False);
   GPIO.output(3, True);
  print "Terima kasih";
  status = False;
  print "GAGAL";
 raw_input("Press any button");

  • Test your PI, execute it , type sudo python lamp.py .

IMG_0781When you choose ‘2’

IMG_0778when you choose ‘1’

  • After learn about fundamental of hardware of PI, it leads you into combination of hardware and software. you can put servos, censor , switch and other technique. hopefully 🙂
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s