How to use tricolor LED module with Arduino

  • avatar
  • 2.5K Views
  • 3 Likes
  • 4 mins read

The KY-016 is capable of producing wide range of different colors by mixing blue, green and red lights. The RGB LED module will not require any limiting resistors. Those resistors are already integrated in the circuit, and so 5V can be directly used as power input.

Components

arduino-nano

1x Arduino Nano (or another Arduino module)

$3.18

Buy now

mini-breadboard

1x Mini-breadboard

$7.43 $2.38

Buy now

ky-016

1x Tricolor LED module (KY-016)

$0.38

Buy now

dupont

Dupont wires

$1.61

Buy now

Wiring schema

Tricolor LED module have four pins: one for each RGB color and GND. Analog inputs are used to control the power of the light and must be connected to PWM pins on Arduino (we used D3, D5 and D6). Non PWM pins can also be used to toggle the lights but we will lose the fade effect.

When the RGB pin receives:

  • HIGH or 255 the light is fully ON

  • LOW or 0 the light is fully OFF

arduino_tricolor_led.png

Arduino code

We've defined two functions to increase and decrease the power of the LED light. The code will sequentially and gradually turn the lights ON and then OFF: first the blue, then the green and finally the red one.

#define BLUE_PIN 3
#define GREEN_PIN 5
#define RED_PIN 6

void setup()
{
pinMode(BLUE_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
pinMode(RED_PIN, OUTPUT);
}

void loop()
{
increaseLight(BLUE_PIN);
decreaseLight(BLUE_PIN);

increaseLight(GREEN_PIN);
decreaseLight(GREEN_PIN);

increaseLight(RED_PIN);
decreaseLight(RED_PIN);
}

void increaseLight(int ledPin)
{
for (int i = 0; i <= 255; i++) {
analogWrite(ledPin, i);

delay(10);
}
}

void decreaseLight(int ledPin)
{
for (int i = 255; i >= 0; i--) {
analogWrite(ledPin, i);

delay(10);
}
}

Note:analog values must be in [0-255] range.

Credits

Official GitHub: https://github.com/hibit-dev/tricolor-led

 Join Our Monthly Newsletter

Get the latest news and popular articles to your inbox every month

We never send SPAM nor unsolicited emails

0 Comments

Leave a Reply

Your email address will not be published.

Replying to the message: View original

Hey visitor! Unlock access to featured articles, remove ads and much more - it's free.