Project Overview:

This project demonstrates how to control an RGB LED with an Arduino to create various colors by mixing the red, green, and blue channels. You’ll learn how to use PWM (Pulse Width Modulation) to adjust the intensity of each color and create different color effects.

How It Works:

An RGB LED has three color channels: red, green, and blue. By varying the brightness of each channel using PWM, you can mix colors to produce a wide range of hues. This project uses the Arduino’s analogWrite function to control the brightness of each channel and cycles through different colors.

Components List:

  1. Arduino Board (e.g., Uno, Nano, etc.)
  2. RGB LED (Common Cathode or Common Anode)
  3. 220-ohm Resistors (for each LED channel)
  4. Jumper Wires
  5. Breadboard (optional)
  6. Power Supply (for Arduino)

Software List:

  • Arduino IDE (Integrated Development Environment)

Circuit Diagram and Connection:

Component

Arduino Pin

RGB LED (Red)

Digital Pin 11

RGB LED (Green)

Digital Pin 10

RGB LED (Blue)

Digital Pin 9

Resistors (220-ohm)

Between each LED channel and GND

  1. Connect the red LED channel of the RGB LED to Digital Pin 11 on the Arduino through a 220-ohm resistor.

  2. Connect the green LED channel of the RGB LED to Digital Pin 10 on the Arduino through a 220-ohm resistor.

  3. Connect the blue LED channel of the RGB LED to Digital Pin 9 on the Arduino through a 220-ohm resistor.

  4. Connect the common cathode or anode of the RGB LED to GND or +5V (depending on whether it is a common cathode or common anode LED).

Project Code:


// RGB Mixing

void setup()

{

  pinMode(11, OUTPUT); // Set pin 11 as output for red channel

  pinMode(10, OUTPUT); // Set pin 10 as output for green channel

  pinMode(9, OUTPUT);  // Set pin 9 as output for blue channel

}


void loop()

{

  // Set color to red

  analogWrite(11, 255); // Full intensity red

  analogWrite(10, 0);   // No green

  analogWrite(9, 0);    // No blue

  delay(1000); // Wait for 1000 milliseconds

  

  // Set color to green

  analogWrite(11, 0);   // No red

  analogWrite(10, 255); // Full intensity green

  analogWrite(9, 0);    // No blue

  delay(1000); // Wait for 1000 milliseconds

  

  // Set color to blue

  analogWrite(11, 0);   // No red

  analogWrite(10, 0);   // No green

  analogWrite(9, 255);  // Full intensity blue

  delay(1000); // Wait for 1000 milliseconds

  

  // Set color to white (mix of red, green, and blue)

  analogWrite(11, 170); // Partial intensity red

  analogWrite(10, 170); // Partial intensity green

  analogWrite(9, 170);  // Partial intensity blue

  delay(1000); // Wait for 1000 milliseconds

}


Explanation of the Code:

  • Setup Function:

    • pinMode(11, OUTPUT); sets pin 11 as an output for the red channel.

    • pinMode(10, OUTPUT); sets pin 10 as an output for the green channel.

    • pinMode(9, OUTPUT); sets pin 9 as an output for the blue channel.

  • Loop Function:

    • Red: analogWrite(11, 255); sets the red channel to full intensity, while green and blue are off.

    • Green: analogWrite(10, 255); sets the green channel to full intensity, while red and blue are off.

    • Blue: analogWrite(9, 255); sets the blue channel to full intensity, while red and green are off.

    • White: analogWrite(11, 170); and similar for green and blue channels create a white color by mixing all three channels at partial intensity.

Test and Troubleshooting:

  1. Testing: Upload the code to your Arduino and observe the RGB LED. The LED should cycle through red, green, blue, and white colors every second.

  2. Troubleshooting:

    • Ensure the RGB LED and resistors are connected properly.

    • Verify the RGB LED is correctly oriented (common cathode vs. common anode).

    • Check the Arduino’s PWM pins are functioning correctly.

Summary:

This project introduces the basics of RGB LED color mixing with Arduino. By controlling the intensity of red, green, and blue channels, you can create various colors and learn the fundamentals of PWM and color mixing.


No comments

Theme images by Dizzo. Powered by Blogger.