KY-016: RGB LED with Arduino
Hello! Arduino is a fun and engaging way to spend time, whether you are a computer nerd or not! This post will teach you:
- How to code a program for Arduino with a color-changing RGB LED, KY-016
- How to connect the wiring
- How to 'play' with the different parameters
- And so much more!
What is the KY-016?
This is a sensor used for color changing. Think of it as an LED that can change into any type of color you want. That is because every color that we can see is made up of three main colors, red, blue , and green. The KY-016 uses these three colors to make any type of color you want based on the value of red. blue, or green you want to have.
This sensor is also compatible with many other boards, such as the Raspberry Pi, and the ESP32.
What are the supplies you need before beginning the experiment?
To power this RGB LED, you definitely need more than just an Arduino. To begin, you need:
- An Arduino UNO board(or any other type of board is fine, though we will be showing you with an UNO)
- KY-016 sensor, also called as the RGB LED.
- A computer with the Arduino IDE installed on it. If you don't have it, install it on: https://www.arduino.cc/en/software
- A breadboard to make the circuit on.
- Male-to-Male connecting wires.
- An type-B USB cable to connect the computer to the Arduino
- And if you want extra power supply: batteries and power cable.
How to Setup:
To setup the Arduino, take 4 male-to-male pins and connect connect them to the GND(Ground) pin, the pin number 9, 10, and 11. To see a complete diagram, see the bottom most picture. That will give you a sense of how to wire it.
Coding
Coding our Arduino is obviously very important. To see the code which we used, check below:
int redpin = 11; // select the pin for the red LED
int bluepin =10; // select the pin for the blue LED
int greenpin =9; // select the pin for the green LED
int val;
void setup() {
pinMode(redpin, OUTPUT);
pinMode(bluepin, OUTPUT);
pinMode(greenpin, OUTPUT);
Serial.begin(9600);
}
void loop() {
for(val = 255; val > 0; val--)
{
analogWrite(11, val);
analogWrite(10, 255 - val);
analogWrite(9, 128 - val);
Serial.println(val, DEC);
delay(5);
}
for(val = 0; val < 255; val++)
{
analogWrite(11, val);
analogWrite(10, 255 - val);
analogWrite(9, 128 - val);
Serial.println(val, DEC);
delay(5);
}
}
(Source: Arduinomodules.info)
This blog and experiment is inspired from Arduinomodules.info and written by Avviin Chandrasekaran, 8th Grade Student at Kennedy Middle School, Cupertino
California.
Avviin is interested in learning Science and computer concepts and programming.
He was doing Scratch programming from 7 year old and made multiple Youtube
Videos.