This project was a little harder than my previous RGB LED project, and took a bit longer due to some hardware issues. It also involves more programming, and does not work with Cayenne MyDevices.
If you have not viewed my previous project, RGB LED: A Button Click Away!, you should do so. Just click here.
ConstructionCopy the Schematics on to your breadboard and make sure everything is plugged in properly. The ground wire (depicted in black and white) should be on row 13.
Testing Your RGB LEDOpen up Putty and login to your Raspberry Pi. This will show you a remote terminal that will allow you to access all of your files and manipulate them.
Not working?
- Is your Pi connected to the internet?
- Give your Pi a minute or so to start up.
- Don't know your IP address? Go into the Pi manual and enter the following command: ifconfig
I wrote my script remotely, and copied it over using WinSCP. I saved it to /home/pi/Desktop/Python\ Games. Getting to your file:
cd Desktop/Python\ Games
sudo python RGB_Color.py
This will run your program. Write "red", "green", or "blue" to change the color of the LED and Ctrl+C to clean up the program.
VariationsYou can add more colors like yellow and light blue. All you have to do is edit the program script:
if UserInput = "red":
GPIO.output(red_pin, True)
GPIO.output(green_pin, False)
GPIO.output(blue_pin, False)
elif UserInput = "green":
GPIO.output(red_pin, False)
GPIO.output(green_pin, True)
GPIO.output(blue_pin, False)
elif UserInput = "blue":
GPIO.output(red_pin, False)
GPIO.output(green_pin, False)
GPIO.output(blue_pin, True)
All you have to do to add another color is add another elif and give the colors you want to turn on or off:
if/elif UserInput = "Example Color":
GPIO.output(red_pin, True/False)
GPIO.output(green_pin, True/False)
GPIO.output(blue_pin, True/False)
LimitationsYou cannot change the brightness of the LED. It is a two-state: either on or off. It is also a simple program, and cannot run automatically (e.g. turn light red at 8:00 PM, turn off all lights at 2:00 AM.) Cayenne MyDevices is useful for doing this, but that is another story...
Problems I FacedUnfortunately, I could not see this program ever to work fully. The green part of my LED broke, but everything else was functioning. I replaced it with a traditional sized LED and there was too much power going through it to work properly, and I don't know what type of resistor I need. Please help me!
Comments
Please log in or sign up to comment.