How to Glow an LED using Raspberry Pi and Python


Today, most of the IoT based applications and products are powered by Raspberry Pi. If you haven’t yet read the previous article, about why IoT is the buzzword of the decade, do check it out! Raspberry Pi is a pocket sized affordable computer which is both fun to play around and build projects as per your ideas. You can plug any computer monitor or TV into the Pi for the display. To get started, you can further connect a standard keyboard and mouse to use it like a mini computer. In true sense, It’s as good as a full sized desktop computer. You can browse the internet, create documents and spreadsheets, watch high definition (HD) videos and play games as well. In this article, we look at a simple DIY Project on how to build your first IoT application using Python to glow an LED.

Raspberry Pi is pretty simple to get started. It provides you a practical approach to learn programming. If you’re familiar with Python, and know how to connect LEDs and resistors to a breadboard, you are good to go! However, if you’re not familiar with Python then I recommend going through this website.

Make sure you have a Raspberry Pi with Raspbian Jessie installed. The circuit is connected as shown below.

LEDs Glow IoT Demo

Connect the LEDs and Raspberry Pi to the breadboard as shown in the diagram using Jumper Wires. Hook up the Raspberry Pi to a monitor via the HDMI port on the board.

Launch the terminal and open ‘nano’ text editor, or you could use any text editor that is already familiar to you. This demo is as simple as a Hello World program. Running the following code will make the LEDs blink.

Now that we have blinking LEDs, lets go ahead and build a silly game. Modify the current code that picks a random number from a given list, glows green LED when you guess the number correctly and glows the red LED if you’re wrong. Run the following code, happy playing!

The sheer form factor and hardware coupled with its ease of use, gives Raspberry Pi the capabilities to interact with everyday things/devices and makes it one of the favourite boards for IoT based products. People around the world are already making phenomenal tools using Raspberry Pi and also share them with the community.

I hope building your first ever IoT project was fun. Let us know what you think in the comments below. Keep checking this space for more projects in the coming days!