Saturday, June 13, 2015

IoT Hello World - Control LED using Raspberry Pi

I used my Raspberry Pi B+ model to control a Led just to quickly see how easy or difficult it was. It turned out to be pretty straightforward once you have the hardware thins required.

  1. A two pin Led
  2. Two wires 
After i installed Raspebian on the Pi using the standard guide that i have got. I installed WiringPi from https://projects.drogon.net/raspberry-pi/wiringpi/download-and-install/

For reference to GPIO pin layout, i referred http://pi4j.com/pins/model-b-plus.html. Connect long leg (+ve) of the LED to pin 11 (GPIO 0) and connect short leg (-ve) to any Ground (I connected to pin 6).

Note that you should also use a resistor on the ground wire to limit the amount of current being passed to the LED otherwise it might damage your LED or even the board. I learnt that usually that happens if you are going to use it for prolonged time but for my 2 sec demo it did not cause any issue without resistor. So do at your own risk.



GPIO pins can be programmatically controlled to be in either input or output mode. I saw that most of them are IN by default. I ran following to see pins status.

gpio readall

See that pin Gpio 0 is in IN mode. Change its mode to OUT as follows-

gpio mode 0 out

Now you are ready to turn on/off the light. Use the following two commands.

For turning on the light - 

gpio write 0 1



For turning off the light

gpio write 0 0




No comments: