Introduction: Simple Python RGB Raspberry Pi Tutorial

Picture of Simple Python RGB Raspberry Pi Tutorial

A simple way to start the Raspberry Pi programming way is try to programming a Raspberry Pi. Now I have created this simple tutorial. You can follow the simple passages and make a simple RGB wireless lamp.
All the components are a RGB led, comune cathode, three resistences (120 Ohm + 120 Ohm + 100 Ohm), a pinplug for Raspberry Pi GPiO, and a piece of perfboard.


You can also buy this RGB led with resistors

Step 1: The Circuit

Picture of The Circuit

The circuit is very simple. You can also use a breadboard and some jumper cable.

Follow the scheme, and solder the components on the perfboard. Use a RGB common cathode and 3 resistor. Use the 120 Ohm resistor for blue and green pin and 100 Ohm for red pin.

Step 2: Plug the Circuit

Picture of Plug the Circuit

Now you are a RGB circuit for Raspberry Pi. Plug the circuit on GPiO in this position.

The Blue pin in the 25

The Green pin in the 24

The Red pin in the 23

Pay attention of the numbers of pin. In this project we use a GPIO pin number. for thi reason we follow the GPIO numeration. Like in the image, you can view the pin number and the GPIO number. The RGB led use the GPIO pins 23, 24 and 25. Also the RGB led use the GND pin between the pins 24 and 25.
Please double-check before start your system. You can burn Raspberry Pi.

Step 3: Start the Raspberry by Terminal

Picture of Start the Raspberry by Terminal

Now you can run the Raspberry Pi. Connect by Terminal if you use MAC OSX or Linux. If you use a Windows system, you can download putty ( Connect by a ssh protocol, and use the terminal for write the Python program and for command the RGB led light.

An important feature of Raspberry Pi is the presence of Python. Now Raspbian have inside a version of Python. You can test the presence of Python in your Raspbian system by this command:


When you write this command if the system have installed Python write on the screen the Python version.

Step 4: Write the Program

Type on the terminal:

sudo nano

After this put the code in the terminal window.

(see the py file)

import RPi.GPIO as GPIO


RED = 25

GREEN = 24

BLUE = 23








while (True):

request = raw_input(“RGB—>”)

if (len(request) == 3):




except KeyboardInterrupt:


Push CTRL + X button and save the file.

Step 5: Command the RGB Led by the Terminal

Picture of Command the RGB Led by the Terminal

Now you can start the program.


sudo python

You can read RGB-->

Now use 0 for OFF the color and 1 for ON color.

Use first number for Red, second number for Green and third for Blue.

For blue write 001 and after click enter

For green write 010 and after click enter

For red write 100 and after click enter

The fun comes when you start mixing colors.

Try 101 click enter and see the color.