0
0
Raspberry Piprogramming~30 mins

RGB LED color mixing in Raspberry Pi - Mini Project: Build & Apply

Choose your learning style9 modes available
RGB LED color mixing
📖 Scenario: You have a small RGB LED connected to your Raspberry Pi. Each color (Red, Green, Blue) can be turned on or off by setting the GPIO pins high or low. You want to create different colors by mixing these three basic colors.
🎯 Goal: Write a program that controls the RGB LED by turning on or off the red, green, and blue pins to create a specific color.
📋 What You'll Learn
Create variables for the GPIO pins connected to the red, green, and blue parts of the LED.
Set up the GPIO pins as outputs.
Write code to turn on the red and green pins and turn off the blue pin to create yellow color.
Print the current color being displayed.
💡 Why This Matters
🌍 Real World
RGB LEDs are used in many devices for colorful lighting effects, status indicators, and decorations.
💼 Career
Understanding how to control hardware like LEDs with code is important for jobs in embedded systems, IoT, and hardware prototyping.
Progress0 / 4 steps
1
Set up GPIO pins for RGB LED
Create three variables called red_pin, green_pin, and blue_pin and set them to 17, 27, and 22 respectively.
Raspberry Pi
Need a hint?

Use simple assignment to set each pin number to the correct variable.

2
Configure GPIO pins as outputs
Import the RPi.GPIO module as GPIO. Set the GPIO mode to GPIO.BCM. Then set up red_pin, green_pin, and blue_pin as output pins using GPIO.setup().
Raspberry Pi
Need a hint?

Remember to import the GPIO library and set the mode before setting up pins.

3
Turn on red and green pins, turn off blue pin
Use GPIO.output() to turn on the red_pin and green_pin by setting them to GPIO.HIGH. Turn off the blue_pin by setting it to GPIO.LOW.
Raspberry Pi
Need a hint?

Use GPIO.output with the correct pin and state to control the LED colors.

4
Print the current color
Write a print statement that outputs the text "The LED color is Yellow".
Raspberry Pi
Need a hint?

Use print() to show the color name on the screen.