Project tutorial
KY-016 Straight Onto UNO

KY-016 Straight Onto UNO © CC0

Got a KY-016? Stick it straight onto your UNO and start attracting unicorns! No soldering. No schematics. No freaking Fritzing.

  • 1 comment
  • 8 respects

Components and supplies

Apps and online services

Ide web
Arduino IDE
Remember to install the SoftPWM library. In the Arduino IDE, click to the "Sketch" menu and then Include Library > Manage Libraries. Search for SoftPWM.

About this project

This is a step in my bigger project about creating a spectacular light show with a bunch of bright RGB SMD LEDs. For that project I needed a software PWM library, because I need more PWM pins than there are hardware PWM pins on an Arduino UNO. In this project I test the SoftPWM library by Brett Hagman. Instead of using my bright RGB SMD LEDs, I just hooked the KY-016 into my UNO, because I noticed the pins of the KY-016 go directly as they are into three digital pins and one GND pin of the UNO.


The KY-016 is an RGB LED on a small PCB including the required resistors for powering the LED with 5 V from the digital pins of the UNO. The KY-016 is included in the 37-in-1 sensor kit, which I believe is available from various manufacturers.

The pinout of the KY-016 is

  • R
  • G
  • B
  • GND or -

Pins I use on the UNO are

  • ~11
  • 12
  • 13
  • GND

The great thing is that these three pins are consecutive pins on the UNO. Just locate them! And stick your KY-016 into them!

~11 is a hardware PWM pin on the UNO (that's what the tilde (~) means), while pins 12 and 13 only perform digital out. So by writing analogWrite(11, 128); I could without further fuss get the led attached to pin 11 shine half dimmed. But pins 12 and 13 work properly only with digitalWrite(), either full bright or off.

Here's where the software PWM comes in handy. In short, it takes care of creating a PWM signal on any digital pin you want.

Create your own colour shows

My sample program "slides the R, G and B slides" through all combinations of full saturated colours in an RGB colour space. Create your own shows by altering the pattern of how the slides are moved. F.i. omit the blue colours, make the colours as warm as possible, restricting the colours to the spectral sector from red through yellow to green.

Figure out how to black out the two red LEDs on the UNO. In the following video you can see the bright red from the on board LEDs.


The code will have a RGB LED connected to pins 11, 12 and 13 sweep through all colours in the spectrum. One cycle lasts 6144 milliseconds.
 *    by Johan Halmen
 *    credits to Brett Hagman
 *    Make sure you have installed 
 *    the SoftPWM library by Brett Hagman
#include "SoftPWM.h"

int bPin = 13;
int gPin = 12;
int rPin = 11;

void setup() {
  SoftPWMSet(rPin, 0);
  SoftPWMSet(gPin, 0);
  SoftPWMSet(bPin, 0);
  SoftPWMSetFadeTime(rPin, 0, 0);
  SoftPWMSetFadeTime(gPin, 0, 0);
  SoftPWMSetFadeTime(bPin, 0, 0);

void loop() {
  int total, phase, delta;
  long int now, then = 0;
  now = millis();
  total = now % 6144;           // The cycle lasts 6144 milliseconds (6 * 1024)
  phase = total / 1024;         // Divide the cycle into 6 phases, think of each
                                // phase as sliding one slide of three slides on 
                                // a light board representing the red, green and blue
                                // channels of your light.
  delta = (total % 1024) >> 2;  // Have the "slide" value vary from 0 to 255,
                                // the delta value increments every four milliseconds
  if (delta != then)            // Update the slides only if the millisecond clock 
                                // has ticked four times                               
    switch (phase)
      // Every second phase one slide goes up, 
      // every other second one slide goes down
      case 0 :
        SoftPWMSet(gPin, delta); // green goes up
      case 1 :
        SoftPWMSet(rPin, 255 - delta); // red goes down
      case 2 :
        SoftPWMSet(bPin, delta); // etc, you get the idea
      case 3 :
        SoftPWMSet(gPin, 255 - delta);
      case 4 :
        SoftPWMSet(rPin, delta);
      case 5 :
        SoftPWMSet(bPin, 255 - delta);
    then = delta;               // Save the delta time for this last
                                // update of the slides


The components
I didn't draw any schematics, since it's all about just plugging one component with 4 male pins into another component with 4 female pins. Locate the GND or "-" pin of the KY-016. This goes into the GND pin of the UNO, next to digital pin 13. Don't bother if the red, green and blue pins of your KY-016 are in another order, as long as they go to pins 11 to 13 and the GND or "-" pin goes to the GND of the UNO.
Img 20190513 204358 biioih48bx


Similar projects you might like

Simple Arduino Uno - ESP 8266 Integration

Project tutorial by team

  • 108 respects

Control Arduino Uno Using ESP8266 WiFi Module and Blynk App

Project tutorial by Adithya TG

  • 68 respects

RS-485 and Arduino Uno

Project tutorial by Alf81010

  • 11 respects

Arduino Uno + Electrical Device (Bulb) + Android Phone

Project tutorial by Stephen Simon

  • 42 respects

Car Control with Arduino Uno and Bluetooth

Project tutorial by Mehmet

  • 49 respects

Embedis : Arduino Uno Keystore

Project tutorial by Team thingSoC

  • 3 respects
Add projectSign up / Login