Tichomir Dunlop
Published © CC BY-NC-ND

RGB LED: A Button Click Away!

Press one of two buttons to control an RGB LED to make it turn red, blue (or purple with both of the buttons on). Using Raspberry Pi B+.

BeginnerFull instructions provided30 minutes1,528
RGB LED: A Button Click Away!

Things used in this project

Hardware components

Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1
RGB Diffused Common Cathode
RGB Diffused Common Cathode
×1
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×2
Raspberry Pi 1 Model B+
Raspberry Pi 1 Model B+
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×3
Male/Male Jumper Wires
×2
Resistor 475 ohm
Resistor 475 ohm
I use 470 ohm, but they were not on the component list. 475 ohm should do.
×2

Software apps and online services

Cayenne MyDevices

Story

Read more

Schematics

Fritzing Schematic (.fzz file)

Fritzing Schematic of Breadboard setup.

Fritzing Schematic (.jpg file)

Fritzing Schematic of Breadboard

Code

Python Script

Python
Turn on/off pins 18 and 23. Use this if you do not want to use Cayenne/Cayenne not working.
Note: Press Ctrl+C to clean up.
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
blue_pin = 18
red_pin = 23
GPIO.setup(red_pin, GPIO.OUT)
GPIO.setup(blue_pin, GPIO.OUT)
try: 
    while True:
        GPIO.output(red_pin, True)
        GPIO.output(blue_pin, True)
finally:  
    print("Cleaning Up.")
    GPIO.cleanup()

Credits

Tichomir Dunlop

Tichomir Dunlop

5 projects • 2 followers
Hello! I am an beginner on the Raspberry Pi and have a model 3 and B+. I know some Python Programming Language as well.

Comments